How to use a C dll in python
Question: I am trying to use a C++ dll in python. I am running python 2.7 on Windows
server 2012; both are 64bit.

To create a dll, I followed the directions on "Walkthrough: Creating and Using
a Dynamic Link Library (C++)" on <http://msdn.microsoft.com/en-
us/library/vstudio/ms235636.aspx>. I used their example code. I am new to dlls
and python so I thought I would start with examples.

My python code:

    
    
    from ctypes import *  
    hw = CDLL("Y:\dll_check\MathFuncsDll.dll")  
    print "HelloWorld"  
    

I get the following error:

    
    
     Y:\dll_check> python .\MathFuncsMain/py  
        Traceback (most recent call last):  
            File ".\MathFunsMain.py"  
                libimgr = CDLL("Y:\dll_check\MathFuncsDll.dll")  
            File "C:Python27\lib\ctypes\__init__.py", line 365, in __init__  
                self._handle = _dlopen(self._name, mode)  
        WindowsError: [Error 193] %1 is not a valid Win32 application  
    

What is causing my error?


Answer: use 32 bit python version and compile to resolve the issue. Reason(probably) :
even though your machine is 64-bit; the dll you have created is a 32 bit one.
bcz through visual studio you can select and create only "Win32 application".

