Somewhat embarrasingly, that sample doesn't work with Python (clearly I tried
harder to make it work with VB then python :) The problem is that Python
itself attempts to fetch 'split' as a property, and depending on the error code
it gets, it may retry as a method (the problem is that in the expression
"a.b()", at the time 'a' is asked for property 'b' , its not yet known that the
result will be called)
As a result, in the sample code, the lines:
elif wFlags & pythoncom.DISPATCH_PROPERTYGET:
return item
are being hit, so a function object is being returned from the COM method call,
at which point pythoncom barfs with the error you see.
There are 2 possible solutions: one would be to check that if the objects
appears callable and DISPATCH_METHOD is not set, raise an exception with
hresult DISP_E_MEMBERNOTFOUND. Python will then retry as a method call. The
other alternative would be make a simple Dispatch wrapper for a function, with
that wrapper having a '_value_' function, which should be called when python
sees a call to a COM object (ie, "ob()" should cause the COM object 'ob' to be
called with DISPID_VALUE)
Hope this helps,
Mark
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nicholas
Sent: Sunday, 20 January 2008 4:22 AM
To: [email protected]
Subject: [python-win32] newbie question on calling DynamicPolicy.py from python
com client
Hi,
I have executed tried to call the ch12 example dynamic server
"DynamicPolicy.py" from python client via:
m = win32com.client.Dispatch('PythonDemos.StringModule')
m.split('hello there')
which gives the following error:
pythoncom error: Python error invoking COM method.
<type 'exceptions.TypeError'>: Objects of type 'function' can not be converted
to a COM VARIANT
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python25\lib\site-packages\win32com\client\dynamic.py", line 491, in
__getattr__
raise pythoncom.com_error, details
com_error: (-2147352567, 'Exception occurred.', (0, 'Python COM Server Internal
Error', "Unexpected Python Error: <type ' exceptions.TypeError'>: Objects of
type 'function' can not be converted to a COM VARIANT", None, 0, -2147467259),
None)
Could anyone enlighted me on what I have done wrong?
Thanks
Nicholas
_______________________________________________
python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32