[python-win32] comtypes.server.register is case sensitive to filenames, see registry PythonClass.

Mark Hammond skippy.hammond at gmail.com
Fri Apr 20 08:06:14 CEST 2012

On 19/04/2012 11:32 PM, jeffwelch at earthlink.net wrote:
> I was having intermittent problems creating a Python COM object that I am using as a test/learning exercise. What I finally noticed was that when I was command line registering the object I was not consistent in typing the name of the python file.
> Executing the DOS command line:
>      python TestMsgBox.py -regserver
> Yields the following registry entry:
>      HKEY_CLASSES_ROOT\CLSID\{a4c0208f-8888-11e1-ac67-b8ac6f92cf9d}\InprocServer32
>          PythonClass = "TestMsgBox.TestMsgBox"
> Executing the DOS command line:
>      python TestMsgBox.py -regserver

Is the above correct, or did you mean to say "python testmsgbox.py" there?

If you did then I can guess how comtypes would come to that conclusion - 
python itself will think the filename is "testmsgbox.py".  pywin32 has 
code specifically to work around this - in win32com\server\register.py 
there is:

moduleName = os.path.splitext(win32api.FindFiles(sys.argv[0])[0][8])[0]

which will give back the actual filename rather than the one specified. 
  I'd see if you can find a comtypes specific mailing-list and ask the 


>      class TestMsgBox( comtypes.IUnknown ):
>          _case_insensitive_ = True

Again, I know almost zero about comtypes, but I wouldn't expect the 
above to have any bearing on the case of the module filename - I'd guess 
that this controls whether the method/property names should be 
considered case sensitive (ie, whether yourobject.Foo() and 
yourobject.foo()) both call the same method.



>          _reg_threading_ = "Both"
>          _reg_progid_ = "TestMsgBoxLib.TestMsgBox"
>          _reg_desc_ = "MessageBox sample for testing"
>          _reg_clsctx_ = comtypes.CLSCTX_INPROC_SERVER | comtypes.CLSCTX_LOCAL_SERVER
>          _reg_clsid_ = "{a4c0208f-8888-11e1-ac67-b8ac6f92cf9d}"
>      if __name__ == "__main__":
>          from comtypes.server.register import UseCommandLine
>          UseCommandLine(TestMsgBox)
> I don't know if this was intended behavior but I had not seen it documented.
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32

More information about the python-win32 mailing list