I am currently working on a project that requires to access functions in DLLs, and I found ctypes to handle the function call for me. However, I encounter some difficulties when some functions ask to pass parameters by reference. I've tried the ctypes.by_ref() but it doesn't work because the object is a user-defined class.
And then I gave ctypes.pointer() a try and it spits out the error message: "type must have storage info". I guess that means it only takes ctypes data types?
My code:
from ctypes import *
class myclass():
a= None # requiring c_int32
b= None # requiring c_int32
myci= myclass()
myci.a= c_int32(255)
myci.b= c_int32(0)
mycip= pointer(myci) # let's say it's Line 8 here
loadso= cdll.LoadLibrary(mydll)
Result= loadso.thefunction (mycip) # int thefunction(ref myclass)
And the terminal output:
Line 8: TypeError: _type_ must have storage info
I would like to know 1) what does that error message mean? and 2) the way to work around and pass a user-defined class by reference to an external DLL.
Thank you in advance for your time.