【建立dll檔】
- 將想要製作成dll檔的function整理好(ex: Function_A.c 與 Function_A.h)
- (vs 2010)新增專案→Win32專案,輸入專案名稱(ex:FuncDll)→[確定]
- 點選[下一步]→應用程式類型:DLL→[完成]
- 將相關檔案匯入(Function_A.c 與 Function_A.h)
此時專案內共有檔案如下:
原始程式檔: Function_A.c、dllmain.cpp、stdafx.cpp、Funcdll.cpp
標頭檔: Function_A.h、stdafx.h、targetver.h - 將Function_A.h內,要輸出的function最前頭加上"__declspec (dllexport)"
(ex: void funcA_export1(int abc) → __declspec (dllexport) void funcA_export1(int abc)) - Function_A.c 要改成 Function_A.cpp
- Function_A.cpp中,若無"stdafx.h",請include進去
- 在dllmain.cpp內,加入" #include "Function_A.h" "
- 建置→重建方案→成功 (此時在專案資料夾內應該會出現FuncDll.dll與FuncDll.lib)
- 開啟應用專案,準備使用剛剛建好的dll檔
- 將FuncDll.dll、FuncDll.lib、Function_A.h (個人將.h的檔名也手動改成FuncDll比較好認)三個檔案放入應用專案的資料夾內。
- 匯入FuncDll.h至專案,並將內文的__declspec (dllexport)改成__declspec (dllimport),且於專案適當處加上"#include "FuncDll.h" "。
- 專案屬性→連結器→輸入→其他相依性→[編輯]
填入 FuncDll.lib - 執行→成功
※ 以上為個人使用成功的範例
