[python-win32] how to get the interface of an COM object?
Bruce Who
bruce.who.hk at gmail.com
Tue Nov 28 06:08:52 CET 2006
HI,all
Finally, I make it work with comtypes. All COM interfaces are
available and events can also be handled. Thanks for Thomas's help,
:-)
On 11/14/06, Bruce Who <bruce.who.hk at gmail.com> wrote:
> Hi, all
>
> I am trying to use win32com to interact with a proprietary COM object.
> progID of the coclass is "SomeObj2.SomeObj.1", I can create the
> coclass but am not able to access other interfaces via
> win32com.client.CastTo().
>
> For example ISomeInterface is one of this COM object's interfaces. But
> no classes are generated for this interface in the file made by
> makepy.py. I can only find things like this:
>
> ISomeInterface_vtables_dispatch_, ISomeInterface_vtables_
>
> this is my code:
>
> te = win32com.client.Dispatch("SomeObj2.SomeObj.1")
> # fail! Error message is:
> # ...
> # return mapCLSIDToClass[clsid]
> # KeyError: '{84AE9D10-95AD-13D5-88C1-0003025952C1}'
> ISomeInterface_ = win32com.client.CastTo(te, 'ISomeInterface')
>
>
> in the file generated by makepy.py, the class is very simple:
>
> class SomeObj(CoClassBaseClass): # A CoClass
> CLSID = IID('{7A4F5191-68A8-14D5-82C1-0001083952C1}')
> coclass_sources = [
> _SomeObjEvents2,
> _SomeObjEvents,
> _SomeObjEvents4,
> _SomeObjEvents5,
> _SomeObjEvents3,
> ]
> default_source = _SomeObjEvents5
> coclass_interfaces = [
> ]
>
> I googled the web and find some old posts in this maillist, it seems
> that only interfaces inherit from IDispatch can be used by pythonCOM,
> and interfaces here inherits from IUnknown. But I just need to use
> these interfaces, so could anybody tell me how to do it?
>
> And this control and its interfaces are all available to VBScript or
> Visual Bacis:
>
> Set ISomeInterface_ = SomeObj.interface("ISomeInterface")
> ...
> <OBJECT ID="SomeObj"
> CLASSID="CLSID:7A4F5191-68A8-14D5-82C1-0001083952C1" ></OBJECT>
>
> Since VBScript and python are both script languages, I guess python
> can also access these interfaces.
>
> Any help would be appreciated!
>
> Bruce
>
More information about the Python-win32
mailing list