[python-win32] PythonWin COM Client Problem Accessing Methods in C++ MFC COM Server

Mark Hammond mhammond at skippinet.com.au
Fri Oct 29 00:17:04 CEST 2010

On 29/10/2010 7:28 AM, Steve Johnston wrote:
> Hello Mark,
> Thank you for responding to my query!  I hope you don't mind that I am
> replying directly to your email.  I'm not sure what the proper protocol is.

It is best if replies stay on list for the benefit of others.

> Your response makes sense, but I'm not sure why my application is not
> returning the "...IDispatch implementation for the dual interface...".
> Unfortunately, I'm not a COM expert.  I looked in the source code, and there
> is a function,
> BOOL CFREDApp::GetDispatchIID( IID* pIID )
> {
>     *pIID = IID_IDualFREDApp;
>     return TRUE;
> }
> which returns the IID of the dual interface.  But I don't know if invoking a
> method from the Python client ultimately calls this function to get the IID,
> and ultimately, the dual interface.

The name looks misleading, but it will be returning the IID of the 
vtable interface - IID_IDispatch is a fixed value.

> Here is another short experiment from the Python Interactive window:
> PythonWin 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit
> (Intel)] on win32.
> Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for
> further copyright information.
>>>> import win32com.client
>>>> app = win32com.client.Dispatch("FRED.Application")
>>>> app
> <win32com.gen_py.FRED Type Library.IDualFREDApp instance at 0x16765696>
>>>> appdual =
> app._oleobj_.QueryInterface("{7267D11E-5C4A-4C83-8766-19EBF0F87E85}")
> Traceback (most recent call last):
>    File "<interactive input>", line 1, in<module>
> TypeError: There is no interface object registered that supports this IID

That is expected - IID_IDualFREDApp is a custom IID which win32com knows 
nothing about.  win32com will so a QI for IID_IDispatch.

> The IID in the QueryInterface call is the IID of the dual interface.  I also
> looked in my registry and there are several entries with that IID that look
> reasonable.  I can only assume that the interface is properly registered
> since Visual Basic can successfully invoke methods from it.

VB is capable of dynamically using vtable interfaces which have a 
typelibrary (which yours does).  You need to track the code for when 
IID_IDispatch is queried for.

Note I'm taking off on 2 weeks holiday tomorrow and may not be able to 
reply while away...



More information about the python-win32 mailing list