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.
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.
User contributions licensed under CC BY-SA 3.0