我有不同的dll导出这个函数(每个dll一个函数):
DLL1:
DECLDIR void getFrameworkVersion(int* pMajor, int* pMinor, int* pBugfix);
DLL2:
void __stdcall getFrameworkVersion(int* pMajor, int* pMinor, int* pBugfix);
我在python中导入两个dll没有错误,并且调用它们也没有错误。但是我的错误值
dll1 = cdll.LoadLibrary('dll1')
dll2 = oledll.LoadLibrary('dll2')
pMajor = pMinor = pbugFix = c_int()
dll1.getASTFrameworkVersion.argtypes = [ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)]
#test.eval.restype = ctypes.c_double
dll1.getASTFrameworkVersion(byref(pMajor), byref(pMinor), byref(pbugFix))
astVersion = "AST Framework version: " + str(pMinor.value) + "." + str(pbugFix.value) + "." + str(pMajor.value)
dll2.getFrameworkVersion.argtypes = [ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int), ctypes.POINTER(ctypes.c_int)]
dll2.getFrameworkVersion(byref(pMajor), byref(pMinor), byref(pbugFix))
asfVersion = "ASF Framework version: " + str(pMinor.value) + "." + str(pbugFix.value) + "." + str(pMajor.value)
我收到了这个输出:
AST Framework version: 0.0.0
ASF Framework version: 14.14.14
答案 0 :(得分:2)
pMajor = pMinor = bugFix = c_int()
错误:所有三个Python名称都是相同的c_int
实例,因此将包含相同的值!你正在做的是等同于C中的以下代码:
int x;
getFrameworkVersion(&x, &x, &x);
因此,获得0.0.0
的事实可能是因为实际结果将以.0
结束,这会覆盖前两个值。