[python-win32] IE DOM ptr as input to DLL function - Doing this right?

Jef Allbright jef at jefallbright.net
Fri Jun 29 21:34:58 CEST 2007


I'm a newbie to Win32 COM and am unsure whether my current problem
lies in what I'm doing or possibly in some quirk of the DLL I'm trying
to use from Python.

I have a snippet of C++ that I want to implement in Python:

	IDispatch* pVoid;
	m_pBrowserApp->get_Document(&pVoid);
	m_pAnalyzer->Analyze(pVoid, _variant_t(5L));
	pVoid->Release();

At first, I tried using win32com.Client.Dispatch to create a COM
object for both my DLL and for the IE browser, and that worked well up
to the point where I tried to use the ie.Document object as input to
Analyze where it expects the pVoid.  Got "argument is not a COM
object"

I learned from Thomas Heller via this post:
<http://mail.python.org/pipermail/python-win32/2006-December/005356.html>
that win32com doesn't known about comtype objects, so I tried the type
conversion function given there but got an error complaining about
unable to find the query interface.

I switched tracks at this point and implemented both COM objects using comtypes:

>>> from comtypes.client import *
>>> o = CreateObject("MyDLL.MyAnalyzer")
>>> ie = CreateObject("InternetExplorer.Application")
>>> ie.Navigate(url)
>>> doc = ie.Document

>>> doc
<POINTER(DispHTMLDocument) object 163a260>
# This seems as expected, right?

>>> o.Initialize(0)
>>> o.Analyze(doc, 10)

Here, it seems to accept my input and goes away for a while, and then
barfs with WindowsError: exception code 0xe06d7363 (the DLL threw an
unspecified exception.)

>From the makepy file, here is the DLL function template:
    def Analyze(self, pHtmlDoc=defaultNamedNotOptArg,
                      granularity=defaultNamedNotOptArg):
        """method Analyze"""
        return self._oleobj_.InvokeTypes(3, LCID, 1, (24, 0), ((9, 0),
(12, 0)),pHtmlDoc,
                                                       nGranularity)

My question is whether or not it appears I'm passing the DOM ptr
properly.  I don't have the source for the DLL but it works well with
an executable demo.

Thanks in advance for any advice.

- Jef


More information about the Python-win32 mailing list