Skip to content
Advertisement

Wrapping a C++ library using msl-loadlib in python

I am currently writing a wrapper for a C++ library. The library is a 32-bits dll file and I’m using 64-bits so I’m using msl-loadlib. I have a problem wrapping a function that has pointer parameters.

Here is the header of the function in C++

JavaScript

and here the wrapper I wrote

JavaScript
JavaScript

When I call Client.getMeasurement(parameters), I get the following error

JavaScript

Edit :

I tried to use ctypes argtypes.

JavaScript

I have a C++ sample code that is using the GetMeasurement function :

JavaScript

Advertisement

Answer

I’m ignoring msl-loadlib as extraneous to the problem of calling ctypes correctly.

Here’s an example of calling the function shown. The YData needs to be an array of 3 double* and then each of those pointers needs to be initialized with the next dimension of the array. Note this parallels the C++ example of calling the function.

test.cpp – sample implementation to fill out the arrays.

JavaScript

test.py – ctypes example to call the function

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement