-
-
#ifdef _DEBUG #else # endif #ifdef _DEBUG
#pragma comment(lib,"..\\debug\\LedCtrlBoard.lib")
#else
#pragma comment(lib,"..\\release\\LedCtrlBoard.lib")
#endif 轉自:http://www.cppblog.com/amazon/archive/2009/09/04/95318.html (1)隐式連結
第一種方法是:通過project->link->Object/Library Module中加入.lib檔案(或者在源代碼中加入指令#pragma comment(lib, “Lib.lib”)),并将.dll檔案置入工程所在目錄,然後添加對應的.h頭檔案。
#include "stdafx.h" #include "DLLSample.h" #pragma comment(lib, "DLLSample.lib") //你也可以在項目屬性中設定庫的連結 int main() { TestDLL(123); //dll中的函數,在DllSample.h中聲明 return(1);}
(2)顯式連結
需要函數指針和WIN32 API函數LoadLibrary、GetProcAddress裝載,使用這種載入方法,不需要.lib檔案和.h頭檔案,隻需要.dll檔案即可(将.dll檔案置入工程目錄中)。
#include <iostream> #include <windows.h> //使用函數和某些特殊變量 typedef void (*DLLFunc)(int); int main() { DLLFunc dllFunc; HINSTANCE hInstLibrary = LoadLibrary("DLLSample.dll"); if (hInstLibrary == NULL) { FreeLibrary(hInstLibrary); } dllFunc = (DLLFunc)GetProcAddress(hInstLibrary, "TestDLL"); if (dllFunc == NULL) { FreeLibrary(hInstLibrary); } dllFunc(123); std::cin.get(); FreeLibrary(hInstLibrary); return(1); }
-
轉載于:https://www.cnblogs.com/ShiShouTHS/p/11481167.html