我已经从 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
提交
取消