#define FaceLIBDLL
#include "stdafx.h"
#include "facedll.h"
#include <opencv2/opencv.hpp>
//////////頭檔案中函數的實作
FaceRecognizer::FaceRecognizer()
{
}
FaceRecognizer::~FaceRecognizer()
生成(Build)工程,在debug檔案夾中會生成相應的DLL及LIB檔案:facedll.dll facedll.lib
封裝好一個類之後,在後面的類可以調用這個類生成的dll,再封裝新類的dll。
需要在工程中添加需要引用的頭檔案,如facedll.h。在debug中拷貝facedll.lib檔案。在 Properties->Linker->Input-> Additional Dependecies中添加facedll.lib(或寫全路徑:"..\debug\facedll.lib")
然後一樣的方法再封裝新的類就可以了~
#pragma once
#ifdef HEARTLIBDLL
#define HEARTAPI _declspec(dllexport)
#else
#define HEARTAPI _declspec(dllimport)
#endif
#include "datadll.h"
class HEARTAPI HRMeasure
{
};
調用需要各個dll的.h、.dll、.lib檔案。
将頭檔案添加到工程中,并#include到需要用的地方。将lib檔案拷貝到項目中,并在 Properties->Linker->Input-> Additional Dependecies 中寫入:facedll.lib;heartdll.lib。
或者在程式中寫入:
#pragma comment(lib,"facedll.lib")
#pragma comment(lib,"heartdll.lib")
之後程式中就可以直接使用封裝成DLL的類了:
HRMeasure *hrMea=new HRMeasure();