我已經從 DLL 導出了這個簡單的函數(我在 MSVC2015、Windows 10、x64 中工作):// Main.h#define DLL_SEMANTICS __declspec (dllexport)extern "C"{ DLL_SEMANTICS int CheckVal(const int x, const int y = 1);}代碼:// Main.cpp int CheckVal(const int x, const int y) { cout << y << endl; return 0; }}根據這個SO線程,使用extern "C"應該不是問題,事實上,當從exe文件調用這個函數時,我得到了想要的結果(即,控制臺的“1”),但是當我使用Python從Python調用這個函數時:import ctypesfrom ctypes import cdlldllPath = r"C:\MyDll.dll"lib = cdll.LoadLibrary(dllPath)lib.CheckVal(ctypes.c_int(1))我正在打印一些垃圾值(通過 PTVS 調試確認這y確實是垃圾值。)我是否做錯了什么或者默認參數無法在 Python 中工作?
添加回答
舉報
0/150
提交
取消