[python-win32] Py COM module consumes a thrid part C-base python library, can not run in C# under x86 build mode

Tim Roberts timr at probo.com
Wed Apr 3 20:23:48 CEST 2013


lizy10b wrote:
> ,
> I am new to Python win32.
> The problem I am facing is my environment is Win7-x64 ,VS2008 SP1,
> Pywin32-218.win32-py2.6, I worte a python module (py file) which
> consumes a third part C-based python library (dll wrapped by ctypes),
> and modify it using Python Win32 to make it COM visiable. After
> registering the COM,  I try to consume it in C#.Net.  In x86 mode an
> exception occured saying can not find the C-based python library's dll
> file, but when I changed the build mode to x64, it runs smoothly.....
>  
> The dll locates inside third part C-based python library's folder,
> so I copied it and place it in the root of the python installation
> path (C:\Python26\) , the C:\Windows\System32 ,and
> C:\Windows\SysWOW64, and the C# project's folder. But it still does
> not work in x86 mode.
>  
> The Python, the third part C-based python librarya and  the
> Python-Win32 are all x86 edition, I don't konw why it happen.

I got a little lost in your description, but let me give you some key
points to remember.

A 64-bit process can only load 64-bit DLLs.  That includes COM objects,
if they are "in-process" objects.

A 32-bit process can only load 32-bit DLLs.  Again, that includes
in-process COM objects.

On a 64-bit system, \Windows\System32 should only contain 64-bit DLLs. 
\Windows\SysWow64 should only contain 32-bit DLLs.  If you copied a
32-bit DLL to System32, that's a problem.  You need to remove it. 
Actually, your COM DLL shouldn't be in either of those two directories. 
They should be in your application's directory.  When you register it,
it will record the actual location of the DLL in the registry.  That's
how the system finds you -- not by doing a DLL path search.

A .NET application, by default, does a just-in-time compilation to match
the native bit size.  If you compile a C# application in "Any CPU", then
it will always be a 64-bit application on a 64-bit system and a 32-bit
application on a 32-bit system.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list