【发布时间】:2020-10-05 14:41:23
【问题描述】:
我已经从一个 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; }
}
根据this SO 线程使用extern "C" 不应该是一个问题,确实当
从 exe 文件调用这个函数我得到了想要的结果(即控制台的“1”)但是当我从 Python 调用它时使用:
import ctypes
from ctypes import cdll
dllPath = r"C:\MyDll.dll"
lib = cdll.LoadLibrary(dllPath)
lib.CheckVal(ctypes.c_int(1))
我正在打印一些垃圾值(通过 PTVS 调试确认 y 确实是垃圾值。)
我做错了什么或默认参数不能在 Python 中工作?
【问题讨论】: