title: Ctypes throws "WindowsError: [Error 193] %1 is not a valid Win32 application", but it's not a 32/64-bit issue
body: <p>I have a problem loading a Windows DLL in Ctypes, which throws the error:</p>
  
  <pre><code>WindowsError: [Error 193] %1 is not a valid Win32 application
  </code></pre>
  
  <p>In my case, it's a 32-bit DLL built with VS2012 on Windows 7 64-bit, and on my development machine I can load it fine. I checked that it's 32-bit, using <code>dumpbin /headers</code>:</p>
  
  <pre><code>FILE HEADER VALUES
           14C machine (x86)
  </code></pre>
  
  <p>The problem occurs when I try to load the same DLL via Ctypes on a production VM, which is also Windows 7 64-bit. What I'm doing is:</p>
  
  <pre><code>from ctypes import *
  self.dll = CDLL(dllabspath)
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>File "C:\Users\user\Desktop\WinPython-32bit-2.7.10.1\.....\__init__.py", line 365, in __init__
  self._handle = _dlopen(self._name, mode)
  WindowsError: [Error 193] %1 is not a valid Win32 application
  </code></pre>
  
  <p>From the other questions I've already tried several things.</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/15374710/windowserror-error-193-1-is-not-a-valid-win32-application-in-python">This</a>, <a href="https://stackoverflow.com/questions/19849077/error-loading-dll-in-python-not-a-valid-win32-application">this</a>, <a href="https://stackoverflow.com/questions/5538671/python-call-to-external-program-results-in-error-193-1-is-not-a-valid-win32-a">this</a> and <a href="https://stackoverflow.com/questions/14621932/python-ctypes-load-library">this</a> question suggests that my environment has to be the same, i.e. 32-bit Python, 32-bit DLL. This is the case on my development system and the VM I'm testing on. On both, I'm using WinPython 32-bit, latest version. It works on the dev machine, it fails on the VM.</p></li>
  <li><p><a href="https://stackoverflow.com/questions/27196098/python-embedding-with-ipython-windowserror-error-193-1-is-not-a-valid-win32">Here</a>, it's related to g++ and a dependency on old Visual Studio runtimes. I compiled everything with VS2012 so I don't think this is applicable here. There is a delayed-loaded dependency on a third party library that needs <code>MSVCR80.dll</code>, but it's delayed-loaded and never called.</p></li>
  <li><p>I've also installed the Visual C++ 32-bit Runtime on the target machine.</p></li>
  <li><p><a href="https://stackoverflow.com/questions/10163832/python-simple-ctypes-dll-load-yields-error">This</a> suggests that the DLL needs to export a C interface, which it does.</p></li>
  <li><p>I know that the file path / file name to the DLL is correct, as before, there were issues with missing DLL dependencies, where I got a Windows popup. These are gone now.</p></li>
  </ul>
  
  <p>The error is very generic, rather cryptic. Since it works on the dev machine in the same Python env, I'm assuming it has to do with some dependencies that only a Visual Studio installation can give me?</p>
  
  <p>How can I troubleshoot this properly?</p>