423,323 Members | 1,789 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,323 IT Pros & Developers. It's quick & easy.

How to pass a reference of instance of a structure of structures in python using ctyp

P: 1
a wrapper is been written for a .dll file to use in python. a function has argument as reference of instance of structure of structures. like this
this is C#
settings(Int32 hObject, ref FSettings pSettings)

public struct FSettings
{
public UInt16 perf_en;
public CSETTINGS C1;
public CFSETTINGS Cf1;
}

public struct CSETTINGS
{
public byte Mod;
public byte SetB;
}
public struct CFSETTINGS
{
public byte FDMod;
public byte SetFDB;
}

I have written in python like this

class CSETTINGS(C.Structure):
_pack_ = 1
_fields_ = [
("Mod",C.c_byte),
("SetB",C.c_byte)
]

class CANFD_SETTINGS(C.Structure):
_pack_ = 1
_fields_ = [
("FDMod",C.c_byte),
("SetFDB",C.c_byte)
}

class SFire2Settings(C.Structure):
_pack_ = 1
_fields_ = [
("perf_en",C.c_uint16),
("C1",C.POINTER(CSETTINGS)),
("Cf1",C.POINTER(CFSETTINGS))
]

f =C.WinDLL ("port.dll")
f.setFSettings.restype = C.c_int32
f.setFSettings.argtypes=[C.c_int32,C.POINTER(FSettings)]

settings =FSettings()
setFSettings(1,settings )

i am getting error like this :
: <type 'exceptions.TypeError'>: expected LP_FSettings instance instead of _ctypes.PyCStructType
May 16 '18 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.