How do I emulate a dynamically sized C structure in Python using ctypes -


I'm writing some Pyro code to interact with a C DLL which uses structures on a large scale.

One of those structures contains nested structures I know that this is not a problem for the ctypes module. The problem is that there is an often used structure, which is defined by the macro in C because there is a "static" length array which can be different, it is confusing, so here is some code

  struct VarHDR {int size; } #defined VAR (size) \ straight Var {VarHDR hdr; Unsigned char array [[shape]]; }  

Then it is used in other structures

  struct MySruct {int foo; VAR (20) luggage items; }  

The question is how can I simulate it in Python that the resulting structure can be passed back and forth between my Python script and DLL.

BTW, I know that I can hardcoded the number there, but many examples of this "VAR" are of full size.

:

Another method is that

Variables with CTIP The use of data types of size, the dynamic nature of the python is to be used, and defines the defined (again) defining the data type before the required size depending on the condition of the case.

(untested) Example:

  def define_var_hdr (size): class war (structure): field = [("size", c_int), ( "Array", c_ubyte * size) return var var_class_10 = define_var_hdr (10) var_class_20 = define_var_hdr (20) var_instance_10 = var_class_10 () var_instance_20 = var_class_20 ()  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -