By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,278 Members | 2,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,278 IT Pros & Developers. It's quick & easy.

How to Passs NULL as a IDispatch Pointer to method?

P: n/a
Hello,all
I am using win32com to use com. and invoke a method as follows:
void AddShapeInfo(LPCTSTR name, LONG type, IDispatch* pDisp);
but i pass 0 or None to third parameter and get error info:
>>x.AddShapeInfo("who", 10, 0)
Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
x.AddShapeInfo("who", 10, 0)
File "<COMObject xxx.Document>", line 2, in AddShapeInfo
com_error: (-2147352571, 'Type mismatch.', None, 3)

or
>>x.AddShapeInfo("who",0,None)
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
x.AddShapeInfo("who",0,None)
File "<COMObject xxx.Document>", line 2, in AddShapeInfo
com_error: (-2147352571, 'Type mismatch.', None, 3)

Apr 17 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Zh********@gmail.com wrote:
Hello,all
I am using win32com to use com. and invoke a method as follows:
void AddShapeInfo(LPCTSTR name, LONG type, IDispatch* pDisp);
but i pass 0 or None to third parameter and get error info:
>>>x.AddShapeInfo("who", 10, 0)

Traceback (most recent call last):
File "<pyshell#9>", line 1, in <module>
x.AddShapeInfo("who", 10, 0)
File "<COMObject xxx.Document>", line 2, in AddShapeInfo
com_error: (-2147352571, 'Type mismatch.', None, 3)

or
>>>x.AddShapeInfo("who",0,None)

Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
x.AddShapeInfo("who",0,None)
File "<COMObject xxx.Document>", line 2, in AddShapeInfo
com_error: (-2147352571, 'Type mismatch.', None, 3)
Maybe Mark Hammond will chime in here, but I'll make at least an
attempt to help. If I'm reading this correctly the 3rd argument
should be and pointer to an IDispatch object. Passing null or
zero wouldn't make any sense. This looks like a pointer to a
callback function for this shape. To get one you would need to
define a Python COM class and wrap it with win32com.server.util.wrap()

possibly something like:

class who:
_public_methods_=['somemethod'}
#
# I don't know what method AddShapeInfo is going to call so
# change this to the appropriate method.
#
def somemethod(self):
#
# Put this method's code here
#
pass

#
# In your program
#
id=win32com.server.util.wrap(who())
x.AddShapeInfo("who",0,id)

I could be way off base here, but I hope that this helps.

-Larry

Apr 17 '07 #2

P: n/a
Thanks to Larry.
I want to pass the IDispatch pointer of other COM object to
AddShapeInfo or pass null to tell x do nothing.
for example.

Rect= Dispatch("Rect.Document")
ShapeSet = Dispatch("xxx.Document")
ShapeSet.AddShapeInfo("Rect", 0, Shape)

or

ShapeSet.AddShapeInfo("EmptyShape", 0, None)

Apr 18 '07 #3

P: n/a
Yingpu Zhao wrote:
Thanks to Larry.
I want to pass the IDispatch pointer of other COM object to
AddShapeInfo or pass null to tell x do nothing.
for example.

Rect= Dispatch("Rect.Document")
ShapeSet = Dispatch("xxx.Document")
ShapeSet.AddShapeInfo("Rect", 0, Shape)

or

ShapeSet.AddShapeInfo("EmptyShape", 0, None)
I think you will need to pass a basically empty class that
is wrapped in an IDispatch object. See my earlier example.

-Larry
Apr 18 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.