[python-win32] COM question - objects available from VB not available to Python COM

Iain Reid iain.reid at gp-w91005.wales.nhs.uk
Fri May 20 23:42:26 CEST 2005


Probably an old chestnut this but, after several days of unsuccesful
google'ing, I thought I'd join the list and seek wise counsel.

I have a piece of medical software that exposes its API via COM. In VB
(or C#) I can access a wider range of objects than in Python and I'm not
clear why. Reading to date suggests that Python will only (easily)
expose objects with an IDispatch 
Interface whereas VB can expose objects with 'other' interfaces.

In VB, I can say:

Dim pt as ClinicLib.Patient 
dim pt as ClinicLib.S6Patient

And both will return valid objects.

In Python, I get:

>>> import win32com.client;
>>> pt = win32com.client.Dispatch('Clinic.Patient');
>>> pt
<COMObject Clinic.Patient>

which works, and

>>> pt = win32com.client.Dispatch('Clinic.S6Patient');
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
  File "C:\Python24\Lib\site-packages\win32com\client\__init__.py", line
95, in Dispatch
    dispatch, userName =
dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
91, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py", line
79, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
pythoncom.IID_IDispatch)
com_error: (-2147467262, 'No such interface supported', None, None)
>>> 

which fails. Trying:

o=pythoncom.CoCreateInstance ("Clinic.S6Patient", None,
wc.pythoncom.CLSCTX_ALL, wc.pythoncom.IID_IUnknown);

Gives 

<PyIUnknown at 0x13e16cc with obj at 0x166474>

In essence, I'm looking for the same functionality as VB.... Perhaps

pt = win32com.client.Object('Clinic.S6Patient');

My reading to date suggests that VB probably uses CreateStdInterface and
QueryInterface to do what it needs to do. Does this seem plausible (I'm
new to the guts of COM) and, if so, does anyone have a code fragment
which demonstrates it?

Iain




More information about the Python-win32 mailing list