Eddy
Eddy

Reputation: 379

Pass the address of a Python structure to a C function

I want to pass the address of a structure to a C program. In C I would use something like fun(&vendorRecord). I have tried various forms I have found on the internet but nothing works. Can someone give me a suggestion?

My structure looks like this:

class vendrRecord(Structure):
    _pack_ = 1                                            # pack the struct
    _fields_ = [
        ("vendorListNumber"      ,c_ubyte *(5)),
        ("vendorNumber"          ,c_ubyte *(5)),
        ]

My C structure looks like this:

struct  {
    unsigned char vendorListNumber[5];
    unsigned char vendorNumber[5];
} vendrRecord;

My C prototype looks like this:

void fun(void *record);

My C call looks like this:

fun(&vendrRecord);

Upvotes: 1

Views: 61

Answers (1)

Eddy
Eddy

Reputation: 379

VendrRecord = vendrRecord()
fun(byref(VendrRecord))

Upvotes: 1

Related Questions