才開始學(xué)習(xí)DLL編程,感覺一切好陌生,靜下心來(lái)學(xué)習(xí)好了.

http://blog.csdn.net/zy122/archive/2006/11/17/1389884.aspx 
這個(gè)地址的博客里面簡(jiǎn)單而又明了的說(shuō)明了DLL的工作原理和使用,制作.

不過在自己做的時(shí)候遇到一點(diǎn)小問題,記錄下來(lái),免得以后再犯.

DEF 文件定義,一不小心犯了個(gè)小錯(cuò)誤:

編譯連接時(shí)候出現(xiàn):
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)

雖然出現(xiàn)警告,但是不會(huì)影響程序的結(jié)果.
在MSDN 中有說(shuō)明.

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 這個(gè)關(guān)鍵字不能被現(xiàn)在的連接器認(rèn)識(shí),仔細(xì)看看果然是寫錯(cuò)了.

所以類似的問題應(yīng)該可以同樣理解,不要把系統(tǒng)不認(rèn)識(shí)的定義關(guān)鍵字放到DEF文件中去,可能會(huì)導(dǎo)致問題.

使用DLL時(shí)導(dǎo)入DLL 和LIB文件到當(dāng)前編譯目錄下:

頭文件申明時(shí)要 使用 類型 _declspec(dllimport) 函數(shù)()
記得載入庫(kù)文件 #pragma comment (lib,"yourlib.lib") 或在工程中添加.