vectordouble using ctypes for dll in python

-1

I have a .dll inside it that has a BUBBLE function that returns a double.

The problem is that BUBBLE has a vector<double> in the argument.

extern "C" minhaDLL_API double BOLHA(vector<double> OI);

In fact it has a extern "C" which makes me believe that when compiling the .dll this turned into a pointer of double . I tried loading this function from .dll into python as follows

mydll = cdll.LoadLibrary("_DLL.dll")

func = mydll.BOLHA

func.argtypes = [POINTER(c_double)]
func.restype = c_double

returnarray = (c_double * 2)(0.047948, 0.005994)

func(returnarray)   

but it returns me the error

[Error -529697949] Windows Error 0xE06D7363
    
asked by anonymous 10.04.2018 / 02:57

1 answer

1

It seems that there is no direct way to solve this using Ctypes, I found that the best way to solve this problem is to change the .dll

It is necessary to put a double pointer in the argument and its size as an integer, and then at the beginning of the function you can transform that pointer + size into a vector and proceed normal with the function. This way, you can establish the connection easily with a type C without losing the utility of the vector in the code.

so it's in .dll

extern "C" minhaDLL_API double BOLHA(double* OI, int size);

and within the function you can make the following association:

vector<double> teste(OI, OI + size);

Now the test vector can be used normally.

In python, it stays:

mydll = cdll.LoadLibrary("_DLL.dll")

func = mydll.BOLHA

func.argtypes = [POINTER(c_double), c_int]
func.restype = c_double

returnarray = (c_double * 2)(0.047948, 0.005994)

func(returnarray, 2)   
    
11.04.2018 / 17:33