0

I'm trying to access a dll from python, following this guide. The first function I try and call from the dll seems to work fine, so I must be most of the way there, but the second one gives me an access violation.

Python code:

#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 )

The access violation occurs when I call the zero( handle ).

The C++ code that does this is here:

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);
}

Where SENSOR_HANDLE is just a typedef'd int

Any ideas? I assume it's ok not to do anything with the returned value.

Community
  • 1
  • 1
TheLastBert
  • 466
  • 4
  • 16
  • You shouldn't write "SOLVED" anywhere; that's what accepted answers are for. If you've fixed it, then write up the solution yourself. – Alexander R Apr 20 '12 at 13:28
  • 1
    Find a different example. That's got to be the most confusing way I've seen to use ctypes. Try http://stackoverflow.com/a/4353259/235698. – Mark Tolonen Apr 20 '12 at 13:39
  • @AlexanderR I couldn't mark my own solution as correct for 2 days, and I didn't want to waste someone's time by having them read the whole question only to realise it wasn't necessary. I have removed it now. – TheLastBert Apr 23 '12 at 09:30

1 Answers1

0

Problem solved.

The c++ code was sample code provided with some documentation. Needless to say the sample code and the documentation were incorrect (the zero function still wanted its argument as a pointer).

TheLastBert
  • 466
  • 4
  • 16