Hi,
I've been using wx.activex to wrap an ActiveX control (WMP10), and
needed to get hold of its various COM-interfaces in order to make it
useful. However, I couldn't find any way to do this with the current
API, so I got an idea: By adding a call to RegisterActiveObject() in
wxie/wxactivex.cpp (in wxPython/contrib/activex), calls to
win32com.client.Dispatch() reaching out for the same CLSID will get
the existing instance instead of creating a new one (or by calling
pythoncom.GetActiveObject() to force it to get an existing object --
raising an exception if there isn't one). The way I use it right now
in my code is:
wmp = wmpctl.WMPControl(*args, **kwargs)
obj = win32com.client.Dispatch("WMPlayer.OCX.7")
self.player = win32com.client.CastTo(obj, "IWMPPlayer")
self.controller = win32com.client.CastTo(obj, "IWMPControls")
self.settings = win32com.client.CastTo(obj, "IWMPSettings")
My first approach was to modify wx.activex to be able to take a
Python COM-object (and/or adding a method returning one), but I
figured that it was too invasive and would add a direct dependency on
pywin32.
What do you think?
Regards,
Ole André
Patch (also attached):
--- wxPython-src-2.6.1.0\wxPython\contrib\activex\wxie\wxactivex.cpp-orig Sat
Feb 26 12:18:16 2005
+++ wxPython-src-2.6.1.0\wxPython\contrib\activex\wxie\wxactivex.cpp Mon
Jun 13 14:14:30 2005
@@ -317,9 +317,14 @@
wxCHECK_RET(adviseSink.Ok(), _T("adviseSink not Ok"));
- // // Create Object, get IUnknown interface
+ // Create Object, get IUnknown interface
m_ActiveX.CreateInstance(clsid, IID_IUnknown);
wxCHECK_RET(m_ActiveX.Ok(), _T("m_ActiveX.CreateInstance failed"));
wxPython-2.6.1.0-wxactivex-registeractiveobject.patch (830 Bytes)
···
+
+ // Register object as active
+ unsigned long pdwRegister;
+ hret = RegisterActiveObject(m_ActiveX, clsid, ACTIVEOBJECT_WEAK,
&pdwRegister);
+ WXOLE_WARN(hret, "Unable to register object as active");
// Get Dispatch interface
hret = m_Dispatch.QueryInterface(IID_IDispatch, m_ActiveX);