Hey, gurus. I've worked a bit on this problem & come up with a more fundamental question:
Can COM objects created by win32com.client support QueryInterface for interfaces OTHER THAN IUnknown, IDispatch, & other builtins? In my experiments, the QI fails for IID's other than these builtins, whether I'm QIing a Python COM object or an msxml object. I need to instantiate an ISAXXMLReader from msxml, & set its 'contentHandler' to a COM object I've implemented in Python. Since reader.contentHandler = myCOMObj returns a type mismatch from COM, I assume the reader QI's myCOMObj from ISAXXMLContentHandler & fails. ________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jesse Davis Sent: Thursday, March 10, 2005 4:41 PM To: [email protected] Subject: [python-win32] Using msxml SAX via win32com -- how do I implementan ISAXContentHandler in Python? Greetings, gurus, & salutations, swamis. Summary: Trying to use msxml's SAXXMLReader. I've implemented an ISAXContentHandler in Python (see end of post), registered it using win32com.server.register.UseCommandLine(), & then I do: >>> import win32com.client as w32c >>> h = w32c.Dispatch('Python.SyncMLBenchmarkSAXContentHandler') >>> h <COMObject Python.SyncMLBenchmarkSAXContentHandler> >>> h.characters('foobar') characters So this shows I've registered my content-handler, I can instantiate it, & when I call its characters() method, it prints 'characters' like I expected. Next, I run makepy on Msxml2.SAXXMLReader, & I try to register the content-handler with the reader. Here's the problem: >>> r = w32c.Dispatch('Msxml2.SAXXMLReader') >>> r <win32com.gen_py.Microsoft XML, v5.0.IVBSAXXMLReader instance at 0x46177544> >>> r.contentHandler = h Traceback (most recent call last): File "<interactive input>", line 1, in ? File "C:\Python22\Lib\site-packages\win32com\client\__init__.py", line 463, in __setattr__ self._oleobj_.Invoke(*(args + (value,) + defArgs)) com_error: (-2147352571, 'Type mismatch.', None, 2) >>> r.putContentHandler(h) Traceback (most recent call last): File "<interactive input>", line 1, in ? File "C:\Python22\Lib\site-packages\win32com\client\__init__.py", line 454, in __getattr__ raise AttributeError, "'%s' object has no attribute '%s'" % (repr(self), attr) AttributeError: '<win32com.gen_py.Microsoft XML, v5.0.IVBSAXXMLReader instance at 0x46177544>' object has no attribute 'putContentHandler' Maybe I need to run makepy on my Python.SyncMLBenchmarkSAXContentHandle CoClass, but it doesn't show up in PythonWin's makepy GUI. Similarly, "python makepy.py Python.SyncMLBenchmarkSAXContentHandler" & "python makepy.py SyncMLBenchmarkSAXContentHandler" respond "Could not locate a type library matching..." However, there are reg keys HKEY_CLASSES_ROOT\CLSID\{85DBFCAE-7AEC-4c26-A165-7B91337ED934} & HKEY_CLASSES_ROOT\Python.SyncMLBenchmarkSAXContentHandler. Any ideas? Jesse Davis =======SyncMLBenchmarkSAXContentHandler===== class SyncMLBenchmarkSAXContentHandler: _public_methods_ = ['characters', 'endDocument', 'endElement', 'endPrefixMapping', 'ignorableWhitespace', 'processingInstruction', 'skippedEntity', 'startDocument', 'startElement', 'startPrefixMapping' ] _reg_progid_ = 'Python.SyncMLBenchmarkSAXContentHandler' _reg_clsid_ = '{85DBFCAE-7AEC-4c26-A165-7B91337ED934}' def characters(self, strChars=None): print 'characters' def endDocument(self): print 'endDocument' def endElement(self, strNamespaceURI=None, strLocalName=None, strQName=None): print 'endElement' def endPrefixMapping(self, strPrefix=None): print 'endPrefixMapping' def ignorableWhitespace(self, strChars=None): print 'ignorableWhitespace' def processingInstruction(self, strTarget=None, strData=None): print 'processingInstruction' def skippedEntity(self, strName=None): print 'skippedEntity' def startDocument(self): print 'startDocument' def startElement(self, strNamespaceURI=None, strLocalName=None, strQName=None, oAttributes=None): print 'startElement' def startPrefixMapping(self, strPrefix=None, strURI=None): print 'startPrefixMapping' _______________________________________________ Python-win32 mailing list [email protected] http://mail.python.org/mailman/listinfo/python-win32
