Python ctypes访问冲突

时间:2012-04-20 12:53:46

标签: python ctypes

我正在尝试从this guide之后的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'd int

有什么想法吗?我假设不对返回的值做任何事情。

1 个答案:

答案 0 :(得分:0)

问题解决了。

c ++代码是一些文档提供的示例代码。不用说示例代码和文档是不正确的(零函数仍然希望它的参数作为指针)。