Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Ptyhong calls DLL, how to use structure array pointer as parameter?
Ptyhong calls DLL, how to use structure array pointer as parameter?
Ptyhong calls DLL, how to use structure array pointer as parameter?

C++ function prototype

Typedef structure

{

Unsigned long device type;

Int handle;

int NumberOfClients

Int serial number;

int MaxAllowedClients

} NeoDevice

Int _ stdcall icsnoefinndneodevices (unsigned long device type, NeoDevice *pNeoDevices, int * pnumberofdevices);

Use python as follows:

NeoDevice class (structure):

_fields_ = [("DeviceType ",c_ulong),

(“Handle”,c_int),

(“NumberOfClients”,c_int),

("serial number", c_int),

(" MaxAllowedClients ",c_int)]

CNeoVICan class (CCanBase):

def __init__(self):

neoVi = windll.icsneo40

self . icsnoefindneodevices = neo VI . icsnoefindneodevices

if __name__ == "__main__ ":

canBus = cNeoVICan()

Print canBus.icsneoGetDLLVersion ()

iNumberOfDevices =[neo device()for x in range( 10)]

num = c_int

Iresult = canbus. icsnoefinndneodevices (c _ ulong (65535), pointer (iNumberOfDevices), byref(num))

However, the following error will be reported:

Backtracking (last call):

The file "c: \ work \ project \ GUI \ wxpycan303 \ DRV \ source \ src \ DRV \ neovi \ cneovican.py", line 224, is in the< module & gt

Iresult = canbus. icsnoefinndneodevices (c _ ulong (65535), pointer (iNumberOfDevices), byref(num))

Type error: _type_ must have storage information.

What is the reason for the mistake?

Thank you.

-Solutions.

Because python's list is not of type ctypes.

The correct way is

NeoDevice class (structure):

_fields_ = [("DeviceType ",c_ulong),

(“Handle”,c_int),

(“NumberOfClients”,c_int),

("serial number", c_int),

(" MaxAllowedClients ",c_int)]

CNeoVICan class (CCanBase):

def __init__(self):

neoVi = windll.icsneo40

self . icsnoefindneodevices = neo VI . icsnoefindneodevices

if __name__ == "__main__ ":

canBus = cNeoVICan()

Print canBus.icsneoGetDLLVersion ()

iNumberOfDevices =(neo device * 10)()

num = c_int()

I result = CANbus . icsnoefindneodevices(c _ ulong(65535),cast(iNumberOfDevices,POINT(NeoDevice)),byref(num))