title: "Procedure probably called with too many arguments" error when using CFUNCTYPE
body: <p>I am currently investigating interfaces between python and C-dll's.
  Using the ctypes library, I'm able to load the dll.</p>
  
  <p>I have a very simple software setup for a proof of concept:
  The function I call in the DLL, expects 1 argument; a function pointer to a function which takes a string to be printed by the python code.</p>
  
  <p>Python code:</p>
  
  <pre><code>lib = ctypes.WinDLL(LIB_PATH)
  # 1) Create callback function type
  CB_FUNC_TYPE = ctypes.CFUNCTYPE(None, ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p, ctypes.c_void_p)
  
  # 2) Create the function which will be called back
  def foo(text):
      print text
  
  # 3) create ctype callback function
  cb_func = CB_FUNC_TYPE(foo)
  
  # 4) Call the function
  print lib.Test2(cb_func)
  </code></pre>
  
  <p>Exported C function (Test2):</p>
  
  <pre><code>__declspec(dllexport) void Test2(T_LOG_CALLBACK pf_log)
  {  
     pf_log("Hello Python Log function!);    
     return;
  }
  </code></pre>
  
  <p>When executing the python code, I get the following error output message:</p>
  
  <pre><code>Hello Python Log function!
  Traceback (most recent call last):
    File "C:\version\vcs\py\workspace\workspace\tests\python-c integration\test.py", line 32, in &lt;module&gt;
      print lib.Test2(cb_func)
  ValueError: Procedure probably called with too many arguments (4 bytes in excess)
  </code></pre>
  
  <p>Which means that the callback is executed correctly, but an error on the stack has been triggered.</p>
  
  <p>I don't understand the error, because the c-function only has one parameter (the function pointer to the function foo in this case).</p>
  
  <p>If I update the line :</p>
  
  <pre><code>cb_func = CB_FUNC_TYPE(foo)
  </code></pre>
  
  <p>to</p>
  
  <pre><code>print lib.Test2(cb_func, "extra")
  </code></pre>
  
  <p>I get the same error, but 8 bytes in excess:</p>
  
  <pre><code>Hello Python Log function!
  Traceback (most recent call last):
    File "C:\version\vcs\py\workspace\workspace\tests\python-c integration\test.py", line 32, in &lt;module&gt;
      print lib.Test2(cb_func, "extra")
  ValueError: Procedure probably called with too many arguments (8 bytes in excess)
  </code></pre>
  
  <p>I cannot find the error, as I at least need to add the callback function's address.</p>
  
  <p>Anybody can see what I'm doing wrong?</p>