我正在尝试按照本指南从 python 访问 dll 。我尝试从 dll 调用的第一个函数似乎工作正常,所以我必须大部分都在那里,但第二个函数给了我访问冲突。
Python代码:
#create open function
openProto = ctypes.WINFUNCTYPE( ctypes.c_int, ctypes.c_void_p )
openParams = ( 1, "handle", 0 ) ,
open = openProto ( ( "SensorOpen", pm ), openParams )
#create zero function
zeroProto = ctypes.WINFUNCTYPE( ctypes.c_int, ctypes.c_int )
zeroParams = ( 1, "handle", 0 ),
zero = zeroProto ( ( "SensorZero", pm ), zeroParams )
handle = ctypes.c_int ( 0 )
status = ctypes.c_int ( 0 )
open( ctypes.byref(handle) )
print handle
zero( handle )
当我调用零(句柄)时发生访问冲突。
执行此操作的 C++ 代码在这里:
SENSOR_HANDLE seHandle; // Sensor handle
double power;
char buff[80];
// Get handle for sensor
SensorOpen (&seHandle);
printf ("Sensor connected\nZeroing, please wait...\n");
while (SensorZero (seHandle) == SENSOR_ZERO_FAILED)
{
printf ("Zero failed.\nCheck no power is being applied.\nPress return key to retry ");
gets (buff);
}
SENSOR_HANDLE 只是一个typedef
'dint
有任何想法吗?我认为不对返回的值做任何事情是可以的。