I have a c function as:
extern "C" __declspec(dllexport) MyStruct foo()
{
MyStruct s = {0, 0}
return s;
}
where the MyStruct is define as:
struct MyStruct{
uInt32 a;
uInt32 b;
void * c;
};
And i am trying to call the function in python, but always get error like:
WindowsError: exception: access violation writing 0x00000000
if i remove void * c from the struct, then it works…
so how should i return the void pointer?
thanks!
This is almost certainly being caused by a disagreement between your C compiler and the ctypes library on the ABI for returning the object. Without seeing your Python code, it’s hard to say whether the problem is due to an incorrect Python declaration of the return type, a bug in the ctypes library, or a non-standard ABI chosen by the C compiler.
For the most portable behavior, I’d suggest changing the function to return the object via an out parameter, like so:
And interface with it like so: