title: How to initialize a structure variable in a C++ header file using Python ctypes?
body: <p>I am trying  to intialize the structure <code>ExternalInputs_add_two</code> in .h header file using Python ctypes.  The header file is:  </p>
  
  <pre><code>typedef struct {  
      int32_T Input;                       /* '&lt;Root&gt;/Input' */  
      int32_T Input1;                      /* '&lt;Root&gt;/Input1' */  
  } ExternalInputs_add_two;  
  </code></pre>
  
  <p>I need to initialize this structure since this member declaration uses the structure   values for input:  </p>
  
  <pre><code>extern ExternalInputs_add_two add_two_U;  
  </code></pre>
  
  <p>What ctypes function intializes the structure?  My Python code so far is:  </p>
  
  <pre><code>class ModelOutput(Structure):  
      _fields_ = [("Output", c_int)]  
  
  class ModelInput(Structure):  
      _fields_ = [("Input", c_int),  
                  ("Input1", c_int)]  
  
  
  #define the functions      
  initiateModel = cdll.add_two_win32.add_two_initialize  
  stepModel = cdll.add_two_win32.add_two_step  
  terminateModel = cdll.add_two_win32.add_two_terminate  
  
  
  #define the pointers to the functions  
  initiateModel.restype = c_void_p  
  stepModel.restype = c_void_p  
  terminateModel.restype = c_void_p  
  
  #initialize the model with value of 1  
  print "\n\nInitialize"  
  errMsg = initiateModel(1)  
  print "initateModel reports:", errMsg  
  
  #Set the input  
  test_input = ModelInput(1,2)    
  input_ptr =  pointer(test_input)  
  
  #This probably doesn't work since ExternalInputs_add_two is a structure, not a function.  
  cdll.add_two_win32.ExternalInputs_add_two = input_ptr  
  
  #Get the output pointer from add_two_U  
  output = POINTER(ModelOutput)  
  results = output.in_dll(cdll.add_two_win32,"add_two_U")  
  
  print "got results", results.Output  
  </code></pre>
  
  <p>I asked the question yesterday how to get the output from the member <code>add_two_U</code>.  David was nice enough to answer this question yesterday (use the <code>in_dll</code> function).  </p>
  
  <p>I've searched the ctypes documentation and online for an example or function to set a   structure using ctype.  I haven't found any so far. </p>
  
  <p>Thank you for your help.  </p>
  
  <p>Thank you for your help and answer.  Unfortunately, setting the input structure this way   does not work.  I forgot to mention that a Matlab script was written to use the dll and it   works.  I'm trying to convert to Python.  To initialize the structure   ExternalInputs_add_two, Matlab uses the following statements:  </p>
  
  <pre><code>sm.Input = 1  
  sm.Input1 = 2  
  sp = libpointer('ExternalInputs_add_two', sm)   
  </code></pre>
  
  <p>Then function add_two_U is called:  </p>
  
  <pre><code>sp = calllib('add_two_win32', 'add_two_U')  
  sp.value  
  get(sp, 'Value')  
  sp.Value.Input = 3  
  sp.Value.Input1 = 2  
  </code></pre>
  
  <p>If I remove the Matlab statement that initializes the ExternalInputs_add_two structure, I get an error.</p>
  
  <p>What is the Python ctypes equivalent to initialize the structure?  I'm sorry if I seem to   be a pest.</p>