From: Drumheller, M. <mic...@bo...> - 2005-09-21 22:39:13
|
I was doing pretty well at building com servers for a while there, but then I lost my mojo. Bottom line: If I use the com_server option in my setup.py, I seem to build a dll just fine, but when I register by running regsvr32 on the dll, a simple test script gives me a bizarre error. But if I register the classes with win32com.server.register.UseCommandLine, my simple test script runs just fine. The full details are included below. Any help would be greatly appreciated. (Am I forgetting some crucial step?) Thank you. MD P.S. In the interest of providing people with the necessary information to actually reproduce (or, I hope, not reproduce) this problem, I have attached a LOT of text below. In order to avoid cluttering people's inboxes please kindly snip as much of it out as possible if/when you reply! --tnx --------------------contents of directory SimpleP2E------------ SimpleP2EServer.py __init__.py testsimplep2e.py setup.py --------------------__init__.py-------------------------- __all__ =3D ["SimpleP2EServer"] --------------------SimpleP2EServer.py------------------ import sys, pythoncom, win32com class CSimpleP2EServer(object): _public_methods_ =3D ['Hello'] _reg_clsid_ =3D "<insert your guid here>" _reg_desc_ =3D "Simple Py2Exe Server" _reg_progid_ =3D "SimpleP2E.SimpleP2EServer" def __init__(self): print "initializing SimpleP2EServer" def Hello(self): return "hello from SimpleP2EServer" if __name__=3D=3D'__main__': import win32com.server.register # Always unregister everything first: try: win32com.server.register.UnregisterClasses(CSimpleP2EServer) print "unregistered the classes" except: print "Could not unregister." if sys.argv[1] =3D=3D "reg": print "registering" win32com.server.register.UseCommandLine(CSimpleP2EServer) else: print "not registering" -------------------testsimplep2e.py------------------- import win32com.client sim =3D win32com.client.Dispatch("SimpleP2E.SimpleP2EServer") print sim.Hello() -------------------setup.py---------------------------- from distutils.core import setup import py2exe setup(name=3D"SimpleP2E", version=3D"0.1", description=3D"Example COM Server using py2exe", author=3D"Michael Drumheller", author_email=3D"mic...@bo...", packages=3D["SimpleP2E"], com_server=3D["SimpleP2E.SimpleP2EServer"]) -------------------session transcript------------------- >>> make sure everything is unregistered: 05-09-21:15:25:56:simplePy2exeExample/SimpleP2E=3D> p SimpleP2EServer.py unreg Unregistered: SimpleP2E.SimpleP2EServer unregistered the classes not registering >>> this fails, as expected: 05-09-21:15:26:06:simplePy2exeExample/SimpleP2E=3D> p testsimplep2e.py=20 Traceback (most recent call last): File "testsimplep2e.py", line 2, in ? sim =3D win32com.client.Dispatch("SimpleP2E.SimpleP2EServer") File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch dispatch, userName =3D dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx) File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatchAndUserName return (_GetGoodDispatch(IDispatch, clsctx), userName) File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line 79, in _GetGoodDispatch IDispatch =3D pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch) pywintypes.com_error: (-2147221005, 'Invalid class string', None, None) >>> register everything from commando line: 05-09-21:15:26:08:simplePy2exeExample/SimpleP2E=3D> p SimpleP2EServer.py reg Unregistered: SimpleP2E.SimpleP2EServer unregistered the classes registering Registered: SimpleP2E.SimpleP2EServer=20 >>> this works, as expected: 05-09-21:15:26:13:simplePy2exeExample/SimpleP2E=3D> p testsimplep2e.py=20 initializing SimpleP2EServer hello from SimpleP2EServer >>> Unregister again (not shown for brevity) and build the py2exe distro: 05-09-21:15:26:14:simplePy2exeExample/SimpleP2E=3D> cd .. 05-09-21:15:26:16:PythonCo2/simplePy2exeExample=3D> p SimpleP2E/setup.py py2exe running py2exe running build_py *** searching for required modules *** <snip> VERSION.dll - C:\WINDOWS\system32\VERSION.dll KERNEL32.dll - C:\WINDOWS\system32\KERNEL32.dll MFC71.DLL - C:\WINDOWS\system32\MFC71.DLL >>> register the dll that just got created: 05-09-21:15:26:23:PythonCo2/simplePy2exeExample=3D> regsvr32 dist/SimpleP2EServer.dll=20 Registered: SimpleP2E.SimpleP2EServer=20 >>> try test script again: 05-09-21:15:26:28:PythonCo2/simplePy2exeExample=3D> cd SimpleP2E 05-09-21:15:26:31:simplePy2exeExample/SimpleP2E=3D> p testsimplep2e.py=20 05-09-21:15:27:34:simplePy2exeExample/SimpleP2E=3D>=20 <at this point I get a fatal error, which offers to throw me into the Vis. Stud. Debugger, Which, when I get there, shows me deep in stack trace, apparently initiated by a heap alloc, and dying in this fcn: _ptiddata _getptd(void) - get per-thread data structure for the current thread (line 319 for those who care). python24.dll!1e0663c7() =09 python24.dll!1e07b236() =09 python24.dll!00e42b14() =09 > msvcr71.dll!_getptd() Line 319 C msvcr71.dll!isalpha(int c=3D124) Line 48 + 0x5 C python24.dll!00e4355d() =09 python24.dll!00e4365f() =09 python24.dll!00e79132() =09 python24.dll!00e06cdc() =09 python24.dll!00e09a88() =09 python24.dll!00e09a88() =09 ntdll.dll!7c9106eb() =09 kernel32.dll!7c809a0f() =09 kernel32.dll!7c809a20() =09 kernel32.dll!7c8399f3() =09 pywintypes24.dll!00a78f5e() =09 win32api.pyd!00fb7ce0() =09 python24.dll!00e49796() =09 python24.dll!00e4755f() =09 python24.dll!00e598e7() =09 python24.dll!00e075f5() =09 python24.dll!00e093b7() =09 python24.dll!00e0645b() =09 python24.dll!00e0766c() =09 python24.dll!00e08d91() =09 python24.dll!00e093b7() =09 python24.dll!00e09d49() =09 python24.dll!00e0a3bc() =09 python24.dll!00e0a412() =09 python24.dll!00e46572() =09 python24.dll!00ea188a() =09 python24.dll!00e598e7() =09 python24.dll!00df93cc() =09 python24.dll!00df95cf() =09 python24.dll!00e485cb() =09 python24.dll!00e48741() =09 msvcr71.dll!_getptd() Line 319 C msvcr71.dll!isalpha(int c=3D58) Line 48 + 0x5 C python24.dll!00e4355d() =09 python24.dll!00e4365f() =09 python24.dll!00e577fe() =09 python24.dll!00e48d23() =09 python24.dll!00e490a1() =09 python24.dll!00e5e999() =09 python24.dll!00e5e999() =09 ntdll.dll!7c9106eb() =09 msvcr71.dll!_heap_alloc(unsigned int size=3D2083788507) Line 212 C msvcr71.dll!_heap_alloc(unsigned int size=3D) Line 212 + 0x5 C |