questions about a C++ COM object accessed in Python via win32com

T.T.H. mymail.5.tth at
Mon Sep 22 17:27:27 CEST 2003


I am coding a C++ COM object which I want to access in Python. For that
I do have some detail questions and need help since I am not that familiar
with the documentation itself of Python and win32com yet.

How do I know that...

import win32com.client

...was successful or not?

In my COM object I do have the following C++ function:

STDMETHODIMP CMyTestObjekt::Connect()
  if (m_boolReadyToConnect == false) {
    return E_FAIL;
  return S_OK;

How do I know in Python whether I got back a S_OK or an E_FAIL? Or is this
whole concept wrong and I should better make an additional return value like:

MyFunktion(......., [out, retval] BOOL *pVal);  (declaration in the IDL)

If I execute the following command...

MyObject = win32com.client.Dispatch("MyCOM.MySuperCOMObject")

...what is the return value from which I know whether it was successful?
Or what can be the ""content"" of "MyObject" afterwards?

If I have a function in Python in which I call the (global) COM Object,
what "if" do I have to use to know whether the COM object already had
been allocated? I tried the following but that didn't work:

def foo():
  if MyObject == None:
    print "COM not there yet"
    print MyObject.Message

I'd really appreciate any help. Or even a hint where to look in the "original"
documentation. FYI: I do use Win2000 and ActiveState ActivePython 2.2 which
already includes win32com.

Matthias "T.T.H." Grobe

More information about the Python-list mailing list