DLL 製作方法
1.用VC開一個DL專案,這裡假設開了一個 Test prj
2.在Test.c中建立一個函數,
for example -
int TEST_API fn1Test(){
return 255;
}
3.在Test.h加入以下敘述
extern "C"{
TEST_API int fn1Test();
}
用extern"C"宣告的目的是讓所有外部程式都可存取fn1Test()
4.編譯,DLL製作結束
p.s 可以用VC建立一個新的程式去連結他,也可以使用python寫一小段code去驗證
以下是python code
-----------------
import ctypes # 加入ctypes module,讓python code可使用C function
ref = ctypes.CDLL("Test.dll") # 匯入Test.dll
print ref.fn1Test() # 執行Test.dll裡頭的fn1Test()
raw_input() # 等待user按下按鍵
文章標籤
全站熱搜

留言功能已依作者設定調整顯示方式