title: How to call functions using ctypes with no input parameters?
body: <p>I am trying to call the C++ function add_two_U from Python using ctypes.  The function add_two_U is defined in the C++ header file as:</p>
  
  <pre><code>extern ExternalInputs_add_two add_two_U;
  </code></pre>
  
  <p>The structure ExternalInputs_add_two is defined in the header file as:</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>The function add_two_initialize that I call in my Python code below is defined in the header file as:</p>
  
  <pre><code>extern void add_two_initialize(boolean_T firstTime);
  </code></pre>
  
  <p>My Python code:</p>
  
  <pre><code>import sys
  from ctypes import *
  
  class ModelInput(Structure):
      _fields_ = [("Input", c_int),
                  ("Input1", c_int)]
  
  #define the functions    
  initiateModel = cdll.add_two_win32.add_two_initialize
  U_Model = cdll.add_two_win32.add_two_U
  
  
  # define the pointers to the functions
  initiateModel.restype = c_void_p
  U_Model.restype = c_void_p
  
  #initialize the model with value of 1
  print "\n\nInitialize"
  errMsg = initiateModel(1)
  print "initateModel reports:", errMsg
  
  #Initialize the structure and get the pointer.
  test_input = ModelInput(1,2)
  input_ptr =  pointer(test_input)
  </code></pre>
  
  <p>I am trying to call function add_two_U in the python code thru the variable U_Model.  Notice in the header file that this function doesn't have any input parameters and uses the structure in the header file to get the input data.</p>
  
  <p>I have the following 2 questions:</p>
  
  <ol>
  <li><p>How do I set the structure ExternalInputs_add_two structure in my Python code to pass the data to the <code>add_two_U</code> function?</p></li>
  <li><p>How do I call the dll function with no parameters <code>add_two_U</code> that I reference thru <code>U_Model</code> in the Python code?  If I use the Python statement to call the function:</p>
  
  <pre><code>result = U_Model()
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>WindowsError: exception: access violation reading 0xFFFFFFFF
  </code></pre></li>
  </ol>
  
  <p>I've searched on-line for an answer and couldn't find an example of initializing a structure in a header file and calling a function with no parameters.</p>
  
  <p>Notice in my Python code that I am able to call function add_two_initialize thru initiateModel with no errors since this function has input parameters.</p>