Skip to content
Advertisement

What should I do to have multiple ctypes data types assigned to a single ctypes instance in Python?

I’m converting a C code into a Python code that uses a .dll file. The syntax for accessing the commands from the DLL is given below:

JavaScript

C code Pointer to the odbm data structure is as follows:

JavaScript

C code used to access the dll command:

JavaScript

The python code that I converted according to the above C code is as follows:

JavaScript

I can get the output without any errors in the above code.

The actual data structure of the ODBM has declared 4 variables of datatypes short, short, long and short which are implemented in the C code. But I had declared the ODBM data structure in python as ctypes.c_short * 4 i.e, 4 variables of short data types.

But my necessity is to declare the ODBM structure the same as in the C code and pass it to the ctypes.byref().

The ultimate solution is to include multiple data types in a single variable as a ctypes instance. Kindly help me out.

Advertisement

Answer

A ctypes.Structure should be used here:

JavaScript
Advertisement