- 论坛徽章:
- 0
|
#! /usr/env/python
from ctypes import *
test = CDLL("testdll"
A = test.A
A.restype = c_int
B = test.B
B.restype = c_int
B.argtypes = [c_int, c_void_p, c_void_p]
va1 = c_int()
va2 = c_int()
s2 = B(A(), byref(va1), byref(va2) )
print s2, va1, va2
// 测试dll的头文件
#ifndef TEST_DLL_H
#define TEST_DLL_H
#define DLLPORT __declspec(dllexport)
extern "C" DLLPORT int A();
extern "C" DLLPORT int B(int handle, int *s1, int* s2);
#endif
// 测试dll的实现文件
#include "testdll.h"
int A()
{
return 1;
}
int B(int handle, int *s1, int* s2)
{
*s1 = 76;
*s2 = 88;
return handle;
}
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
# 输出结果:
1 c_long(76) c_long(8
因此,你应该仔细查看你的dll返回值是否正确,而不是去判断python的代码是否有问题! |
|