Using Py2exe's ctypes_com_server setup keyword with Python 3

0

I'm making an extension for a Windows program that hooks to COM server objects. I want to use Python to do this, and from what I understand, I can use Py2exe to create a DLL from a comtypes server.

For a test, I wrote a simple class that calls a print method exposed via RPC. I created a COM interface for that class, registered it, instantiated the COM object from another Python program, and called the print method. It works.

(I've created a repository for reference here: https://github.com/jakogut/python-inproc_server)

However, when I use Py2exe to create a DLL from my COM server, and try to register that DLL using regsvr32, a popup states:

The module "RemotePrint.dll" was loaded but the call to DllRegisterServer failed with error code 0x80040201

So far, I've tried running from an administrator command prompt, clearing the comtypes gen cache and recreating the DLL, profiling the runtime library dependencies using Dependency Walker (it froze/crashed, and gave no helpful information), and running on another machine.

Based on the fact that my code works as it should when I register it using the comtypes register function, I'm assuming this doesn't work as a DLL because of improper setup on my part, or a quirk with Py2exe and Python 3.

python
windows
com
py2exe
comtypes
asked on Stack Overflow Nov 13, 2015 by jakogut

1 Answer

1

It seems that the problem was the Python Interpreter crashing because it couldn't import RemotePrintLib from comtypes.gen. Adding 'comtypes.gen' to the includes option for distutils worked!

One thing that helped diagnose this was win32traceutil.

answered on Stack Overflow Nov 17, 2015 by jakogut

User contributions licensed under CC BY-SA 3.0