#109 Frozen environment and win32com.server.register.RegisterServer()

open
nobody
None
5
2014-05-12
2014-05-12
No

Hi,

I'm working on an Excel COM add-in with Python 3.3 / pywin32 v219. Everything works fine, except when I'm trying to cx_Freeze my app to distribute it.

The RegisterServer function doesn't create all requested keys in the windows registery.
You will find below a diff for my HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID{C5482ECA-F559-45A0-B078-B2036E6F011A} key.

Normal environment Frozen environment Status
\Debugging \Debugging OK
\Implemented Categories Not created missing key, but doesn't seem mandatory
\Implemented Categories\{B3EF80D0-68E2-11D0-A689-00C04FD658FF} Not created doesn't seem mandatory
\InprocServer32 Not created seems mandatory
\ProgID \ProgID OK
\PythonCOM \PythonCOM OK
\PythonCOMDispatcher \PythonCOMDispatcher OK (debug mode only)
\PythonCOMPath Not created seems mandatory
\PythonCOMPolicy \PythonCOMPolicy OK

When I create thoses registry keys by hand, my add-in registers in Excel.
Further researches in the register process shows me that the frozen case is implemented in win32com.server.register.RegisterServer(), but I don't know if cx_Freeze provides all requested env vars.

  • For the \InProcServer32 key, the involved RegisterServer() code says (register.py, line 209) :
if pythoncom.frozen:
 if hasattr(sys, "frozendllhandle"):
  dllName = win32api.GetModuleFileName(sys.frozendllhandle) 
 else:
  raise RuntimeError("We appear to have a frozen DLL, but I don't know the DLL to use")
  • For the \PythonCOMPath key, it's the RegisterClasses() function (register.py, line 426) which doesn't provide addnPath arg to RegisterServer() :
      # Frozen apps don't need their directory on sys.path
      if not pythoncom.frozen:
        scriptDir = os.path.split(sys.argv[0])[0]
        if not scriptDir: scriptDir = "."
        addnPath = win32api.GetFullPathName(scriptDir)

As I'm a new Python user, maybe I miss something with cx_freeze (need to provide more elements to make pywin32 works in frozen env ?), or maybe cx_freeze is not the best tool to freeze my pywin32 app ?

Hope to read you soon,

Best regards,

Jonathan

Discussion