我有不同的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
pMajor = pMinor = bugFix = c_int()
是错误的:所有三个Python名称都是相同的c_int
实例,因此将包含相同的值!你所做的等同于C中的以下代码:
int x;
getFrameworkVersion(&x, &x, &x);
所以你得到0.0.0
的事实可能是因为真正的结果将在.0
结束,它覆盖了前面的两个值。