Matt Wilbur schrieb:
> After much digging into pointers and arrays in ctypes, one question remains
> for me (and I have just checked out the ctypes trunk to try to figure this
> out myself) is what the mechanics of classes defined as POINTER(
> <COM_interface_class> ) work.  That is, there's no contents attribute
> (something I looked at briefly, again in desperation, to get access to the
> wrapped COM interface), they can't be indexed, so on and so forth.  I figure
> this must be an interaction of the _Pointer class, from which types
> constructed with POINTER inherit, and the metaclass of COM interface
> classes.  Any commentary is welcome.

Well, there is some strange metaclass and other hackery at work in the
POINTER(ISomeInterface) class.  If you look at the method resolution order
of an instance of 'CreateObject("InternetExplorer.Application")', for example,
you see this (this is also the class hierarchy in mro order):

 |  Method resolution order:
 |      POINTER(IWebBrowser2)
 |      comtypes.gen._EAB22AC0_30C1_11CF_A7EB_0000C05BAE0B_0_1_1.IWebBrowser2
 |      POINTER(IWebBrowserApp)
 |      comtypes.gen._EAB22AC0_30C1_11CF_A7EB_0000C05BAE0B_0_1_1.IWebBrowserApp
 |      POINTER(IWebBrowser)
 |      comtypes.gen._EAB22AC0_30C1_11CF_A7EB_0000C05BAE0B_0_1_1.IWebBrowser
 |      POINTER(IDispatch)
 |      comtypes.automation.IDispatch
 |      POINTER(IUnknown)
 |      IUnknown
 |      _compointer_base
 |      ctypes.c_void_p
 |      _ctypes._SimpleCData
 |      _ctypes._CData
 |      __builtin__.object

In other words:

POINTER(IWebBrowser2) is a subclass of IWebBrowser2, POINTER(IDispatch)
is a subclass of POINTER(IUnknown) and other funny relationships.

I do not remember exactly how I managed to remove the contents attribute from
POINTER(ISomeInterface), or how I prevented indexing.  It makes no sense to
dereference a COM pointer, the only interesting things that you can do with
a COM pointer is to call methods on it.

However, __getitem__ is mapped to the COM interfaces 'Item' method, if it has 
one.

Anyway, the interesting stuff is in comtypes\__init__.py, in the code for
the _cominterface_meta metaclass and the _compointer_base class.


> Man, I love this module.

:-)


Thomas


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft 
Defy all challenges. Microsoft(R) Visual Studio 2008. 
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
comtypes-users mailing list
comtypes-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/comtypes-users

Reply via email to