才開始學習DLL編程,感覺一切好陌生,靜下心來學習好了.
http://blog.csdn.net/zy122/archive/2006/11/17/1389884.aspx
這個地址的博客里面簡單而又明了的說明了DLL的工作原理和使用,制作.
不過在自己做的時候遇到一點小問題,記錄下來,免得以后再犯.
DEF 文件定義,一不小心犯了個小錯誤:
編譯連接時候出現:
Linking...
.\DllTest.def : warning LNK4017: LIBRARRY statement not supported for the target platform; ignored
Creating library Release/DLLTest.lib and object Release/DLLTest.exp
DLLTest.dll - 0 error(s), 1 warning(s)
雖然出現警告,但是不會影響程序的結果.
在MSDN 中有說明.
The given module-definition statement is not supported by this version of the linker tools. The tool ignored the statement in the .def file.
http://forums.msdn.microsoft.com/zh-CN/vcgeneral/thread/80c00135-6de2-499e-bc51-f5ceab32eacf/
找到答案,原因在于LIBRARRY 這個關鍵字不能被現在的連接器認識,仔細看看果然是寫錯了.
所以類似的問題應該可以同樣理解,不要把系統不認識的定義關鍵字放到DEF文件中去,可能會導致問題.
使用DLL時導入DLL 和LIB文件到當前編譯目錄下:
頭文件申明時要 使用 類型 _declspec(dllimport) 函數()
記得載入庫文件 #pragma comment (lib,"yourlib.lib") 或在工程中添加.