How do I access COM object's nondefault interface?

Josef Sachs sachs at panix.com
Fri Aug 16 13:02:46 EDT 2002


>>>>> On 15 Aug 2002 17:05:51 -0400, Josef Sachs said:

> Can anyone tell me how to access a COM object's nondefault interface?

> I saw the postings from mhurwitch at roadnet.com and
> Toby Dickenson <htrd90 at zepler.org> on the subject in 1999,
> and I tried the methodology suggested (below) but it just
> crashes pythonwin.

> I'd greatly appreciate any assistance.

> By the way, is there a better place to ask Python-win32 questions?
> I have hardly received any responses to my recent postings.

> def qi(object,iid):
>  # Query for given iid, but use the IDispatch wrapper. The given iid
>  # must correspond to a dual interface or dispinterface
>  dispatch=object._oleobj_.QueryInterface(iid,pythoncom.IID_IDispatch)
>  # Create the best dispatch object we can, using makepy version if possible
>  return win32com.client.Dispatch(dispatch,resultCLSID=iid)

I have now also tried Mark Hammond's suggested methodology from an article
posted 2000/07/27 (Subject: Re: Two COM Questions: QueryInterface, and
Callback Inheritance), but it also crashes pythonwin.  Any suggestions?

>>> import win32com.client
>>> x=win32com.client.DispatchWithEvents("XMsg2.RoxBase.1", eventHandlerClass)
>>> a=x.GetMessage()
>>> a
<win32com.gen_py.xMsg2 CLIENT - Rox System Interface.IOrderAck>
>>> import win32com.client.gencache
>>> m=win32com.client.gencache.GetModuleForCLSID('{E21C8E4F-9D58-4618-B4E5-D8F1B0EAF649}')
>>> m
<module 'win32com.gen_py.497668DA-5952-4028-AB0A-20E2E55C9490x0x1x0' from 'G:\Python22\Lib\site-packages\win32com\gen_py\497668DA-5952-4028-AB0A-20E2E55C9490x0x1x0.pyc'>
>>> b=m.IxMessage
>>> b
<class win32com.gen_py.497668DA-5952-4028-AB0A-20E2E55C9490x0x1x0.IxMessage at 0x0141DE80>
>>> c=b(a)
>>> c
<win32com.gen_py.xMsg2 CLIENT - Rox System Interface.IxMessage>
>>> c.SenderSeqNumber
[crash]



More information about the Python-list mailing list