[python-win32] Working with a PyIDispatch object

Mark Hammond mhammond at skippinet.com.au
Fri Feb 4 03:08:20 CET 2005


You can convert it to a "friendly" object simply by doing:
 
locator = win32com.client.Dispatch(locator)
 
If you want to ensure early binding, try:
 
locator = win32com.client.gencache.EnsureDispatch(locator)
 
That should generate a makepy file for the interface on the fly (but doesn't
work for all objects - suck it and see :)
 
Mark

-----Original Message-----
From: python-win32-bounces at python.org
[mailto:python-win32-bounces at python.org]On Behalf Of Greg Lee
Sent: Thursday, 3 February 2005 9:55 AM
To: python-win32 at python.org
Subject: [python-win32] Working with a PyIDispatch object



I'm using MSXML2.SAXXMLReader.4.0 to validate XML.  
Following a hint posted July 2 by the estimable Mark Hammond, I implemented
the error handler thus: 

class MyErrorHandler: 
    _com_interfaces_ = ['IVBSAXErrorHandler'] 
    _public_methods_ = ['error', 'fatalError', 'ignorableWarning'] 

    def error(self, locator, strError, nErrorCode): 
  .... 

When the error method is called, the locator turns out to be a PyIDispatch
object for a win32com.gen_py.Microsoft XML, v4.0.IVBSAXLocator instance.
The only way I've found to decode this locator is via the Invoke method,
e.g.:

    def error(self, locator, strError, nErrorCode): 
        id =  locator.GetIDsOfNames('columnNumber') 
        colno = locator.Invoke(id, 0x0, pythoncom.DISPATCH_PROPERTYGET, 1) 
        ... 

1.  Is there a better way to do this?  
2.  What are the parameters for the Invoke method?  I worked this out
experimentally from win32com/dynamic.py, but I'd be happier knowing what the
"1" means.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 4796 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-win32/attachments/20050204/05d05588/winmail.bin


More information about the Python-win32 mailing list