title: Use a DLL with python (using ctypes), not working
body: <p>I'm trying to write a DLL that I can import in Python (2.7), and I'm having difficulties "making it work". When I load the library in Python using <code>WinDLL()</code> or <code>windll.LoadLibrary()</code>, and test the exported function the output i get is empty. If I add an argument to <code>TestFunction()</code> it raises a <code>ValueError</code> which states that there is probably to many arguments (it's really not).</p>
  
  <p><strong>python-file:</strong></p>
  
  <pre><code>from ctypes import *
  
  x = windll.LoadLibrary('./pymod.dll')
  print x.TestFunction(123) #Should return 123.
  </code></pre>
  
  <p><strong>main.h:</strong></p>
  
  <pre><code>#ifndef __MAIN_H__
  #define __MAIN_H__
  #include &lt;windows.h&gt;
  #define DLL_EXPORT __declspec(dllexport)    
  
  #ifdef __cplusplus
  extern "C"
  {
  #endif
  
  int DLL_EXPORT TestFunction(int data);
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif
  </code></pre>
  
  <p>and <strong>main.cpp:</strong></p>
  
  <pre><code>#include "main.h"
  
  int DLL_EXPORT TestFunction(int x = 0) {
      return x;
  }
  
  BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
      switch (fdwReason){
          case DLL_PROCESS_ATTACH:
              break;
          case DLL_PROCESS_DETACH:
              break;
          case DLL_THREAD_ATTACH:
              break;
          case DLL_THREAD_DETACH:
              break;
      }
      return TRUE;
  }
  </code></pre>
  
  <p><strong>Solved</strong>: Issue was wrong calling convention. </p>