comtypes question

Jorgen Bodde jorgen.maillist at gmail.com
Mon Mar 17 07:06:43 EDT 2008


Hi All,

I am trying to automate a 3rd party application, and all I have to
work on is the type library and some documentation. I hope a Python /
COM guru can answer this or put me on the right path because I don't
know why it does not work.

First I imported the typelib with comtypes like;

>> from comtypes.client import GetModule
>> GetModule("C:\\Program Files\\Seagull\\BarTender\\8.0\\bartend.exe")

Which blurbs out a lot of text:

# Generating comtypes.gen._D58562C1_E51B_11CF_8941_00A024A9083F_0_8_1
# Generating comtypes.gen.BarTender
<module 'comtypes.gen.BarTender' from
'C:\Python24\lib\site-packages\comtypes\gen\_D58562C1_E51B_11CF_8941_00A024A9083F_0_8_1.pyc'>

Which seems to be ok. Now, I need to call a function on the
Application object on which I need a "Messages" instance. The
Application object gets created properly:

>> import comtypes.gen.Bartender as bt
>> app = comtypes.client.CreateObject(bt.Application)

Which gives me the application (the bt.Application points to a wrapper
class containing the CLSID of the COM class to be instantiated).

Now I browse the typelibrary and I see there is a CoClass called
Messages. I need one of those to pass as an argument, and since
Messages is listed as a CoClass similar to Application, I assume it
can also be instantiated. But when I try this I get an error:

>>> msgs = cc.CreateObject('{2B52174E-AAA4-443D-945F-568F60610F55}')
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "C:\Python24\Lib\site-packages\comtypes\client\__init__.py",
line 198, in CreateObject
    obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
  File "C:\Python24\Lib\site-packages\comtypes\__init__.py", line 931,
in CoCreateInstance
    _ole32.CoCreateInstance(byref(clsid), punkouter, clsctx,
byref(iid), byref(p))
  File "source/callproc.c", line 757, in GetResult
WindowsError: [Errno -2147221164] Class not registered

Both Application and Messages are listed as CoClass inside the
typelibrary. Does anybody know  why it gives me this error and what I
am doing wrong? I have a COM Delphi background, and it would be
similar to:

msgs := CoMessages.Create;
... if the TLB is imported properly.

Here is the details of the Application CoClass:

[
  uuid(B9425246-4131-11D2-BE48-004005A04EDF)
]
coclass Application {
    [default] interface IBtApplication;
    dispinterface DBtApplication;
};

And here is one from the Messages CoClass (as you can see the GUID matches):

[
  uuid(2B52174E-AAA4-443D-945F-568F60610F55)
]
coclass Messages {
    [default] interface IBtMessages;
    dispinterface DBtMessages;
};

Regards,
- Jorgen



More information about the Python-list mailing list