I'd like to use a function that is defined in a DLL from Python. The value returned from the C++ function (get_version) is a struct
typedef struct myStruct {
size_t size;
char * buff;
} myStruct ;
The Python code is:
lib = CDLL(myDLL.dll)
lib.get_version
The question is how do I handle the returned value?
I've read Voo's answer and reading other posts, but I'm still struggling with this
I declared the struct class (Foo, from Voo's answer) and set the restype
The code now looks
class Foo(Structure):
_fields_ = [('size', c_size_t), ('buff', c_char_p)]
lib = CDLL(myDLL.dll)
lib.get_version
lib.get_version.restype = Foo._fields_
I get the following error TypeError: restype must be a type, a callable, or None
I read about this and if I set the restype not as a list, e.g.: c_char_p, the error doesn't appear
When I set the restype
lib.restype = Foo.fields
The error doesn't appear but the restype for get_version is not set correctly
When looking at the variables in debug:
lib.restype = list: [('size', ), ('buff', )]
lib.get_version.restype = PyCSimpleType:
Any help would be appreciated
ctypesworks with C functions, so if using C++ make sure toextern "C"the function.C linkage function cannot return C++ class 'myStruct '