comtypes icon indicating copy to clipboard operation
comtypes copied to clipboard

Frozen ctypes com server can't load OLE typelib

Open jakogut opened this issue 9 years ago • 1 comments

When registering a frozen inproc com server, an exception is thrown when LoadTypeLibEx is passed a c_wchar_p string instead of a unicode string.

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "boot_ctypes_com_server.py", line 80, in DllRegisterServer
  File "C:\Python34\lib\site-packages\comtypes\server\register.py", line 328, in register
    Registrar().register(cls)
  File "C:\Python34\lib\site-packages\comtypes\server\register.py", line 135, in register
    self._register(cls, executable)
  File "C:\Python34\lib\site-packages\comtypes\server\register.py", line 152, in _register
    LoadTypeLibEx(dll, REGKIND_REGISTER)
  File "C:\Python34\lib\site-packages\comtypes\typeinfo.py", line 485, in LoadTypeLibEx
    _oleaut32.LoadTypeLibEx(c_wchar_p(szFile), regkind, byref(ptl))
TypeError: unicode string or integer address expected instead of bytes instance
DEBUG:comtypes.server.register:Unregister <class 'server.RemotePrint.RemotePrintImpl'>

jakogut avatar Dec 14 '15 18:12 jakogut

Through the discussion in python/cpython#127369, the more fundamental cause of this error has been identified.

When dealing with a frozen inproc server, comtypes.server.register._get_serverdll returns a bytes object, which causes an error with the current implementation of LoadTypeLibEx.

Instead of modifying LoadTypeLibEx as done in #91, I believe converting the path returned by _get_serverdll to str would result in a smaller-impact change.

junkmd avatar Dec 17 '24 00:12 junkmd