[python-win32] QueryInterface fails with object passed from VB
jose simas
josesimas at gmail.com
Fri Apr 25 13:02:08 CEST 2008
Hi,
I am porting parts of a large VB application to python (using 2.5)
where the UI must stay in VB for the moment. I am using the Model View
Presenter where my models and presenters are in python and my view is
in VB.
I am having trouble passing the VB views into my python presenters.
The views are UserControls and implement an interface (IViewDataView
in the example below) which is defined externally in a type library
(ResultsInterfaces in this example). This interface defines the
methods that the presenter can call on the view. So the VB code is:
Dim presenterInPython As Object
Set presenterInPython = CreateObject("VBToPython.MyTest")
presenterInPython.Init vbUserControl.Object
And the python code is:
class MyTest:
_public_methods_ = ['Init']
_reg_progid_ = "VBToPython.MyTest"
_reg_clsid_ = '{AAAAA649-0AF9-40cf-A51B-4BB10DD33074}'
def Init(self, view):
import comtypes
res_id = comtypes.GUID("{417081F1-179E-4856-B996-03043260AB81}")
import comtypes.client as cc
cc.GetModule((res_id, 1, 0))
import comtypes.gen.ResultsInterfaces as ResInt
internalView = view.QueryInterface(ResInt.IViewDataView)
at this point it throws the error (full error at the end):
<type 'exceptions.TypeError'>: Only strings and iids can be converted
to a CLSID.
Could anyone shed some light on what I missing here? I would also
appreciate if someone could point me in the direction of a similar
example or demo.
Cheers
Jose
The error from PythonWin Trace Collector:
Object with win32trace dispatcher created (object=None)
in <COMTEST.MyTest instance at 0x01DE0800>._QueryInterface_ with
unsupported IID IPersistStreamInit
({7FD52380-4E07-101B-AE2D-08002B2EC713})
in <COMTEST.MyTest instance at 0x01DE0800>._QueryInterface_ with
unsupported IID IPersistPropertyBag
({37D84F60-42CB-11CE-8135-00AA004BB851})
in _GetIDsOfNames_ with '('Init',)' and '1033'
in _Invoke_ with 1000 1033 1 (<PyIDispatch at 0x1f178b4 with obj at 0x15aa40>,)
Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\win32com\server\dispatcher.py",
line 47, in _Invoke_
return self.policy._Invoke_(dispid, lcid, wFlags, args)
File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line
285, in _Invoke_
return self._invoke_(dispid, lcid, wFlags, args)
File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line
290, in _invoke_
return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line
593, in _invokeex_
return func(*args)
File "C:\_svn\GXP\branches\v5\Core\src\COMTEST.py", line 37, in Init
y = view.QueryInterface(ResInt.IViewDataView)
TypeError: Only strings and iids can be converted to a CLSID.
pythoncom error: Python error invoking COM method.
Traceback (most recent call last):
File "C:\Python25\Lib\site-packages\win32com\server\dispatcher.py",
line 163, in _Invoke_
return DispatcherBase._Invoke_(self, dispid, lcid, wFlags, args)
File "C:\Python25\Lib\site-packages\win32com\server\dispatcher.py",
line 49, in _Invoke_
return self._HandleException_()
File "C:\Python25\Lib\site-packages\win32com\server\dispatcher.py",
line 129, in _HandleException_
reraise()
File "C:\Python25\Lib\site-packages\win32com\server\dispatcher.py",
line 47, in _Invoke_
return self.policy._Invoke_(dispid, lcid, wFlags, args)
File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line
285, in _Invoke_
return self._invoke_(dispid, lcid, wFlags, args)
File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line
290, in _invoke_
return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line
593, in _invokeex_
return func(*args)
File "C:\_svn\GXP\branches\v5\Core\src\COMTEST.py", line 37, in Init
y = view.QueryInterface(ResInt.IViewDataView)
<type 'exceptions.TypeError'>: Only strings and iids can be converted
to a CLSID.
More information about the python-win32
mailing list