How to Passs NULL as a IDispatch Pointer to method?

Z

ZhaoYingpu

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:

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

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)
 
L

Larry Bates

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:


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


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
 
Y

Yingpu Zhao

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)
 
L

Larry Bates

Yingpu said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,297
Latest member
EngineerD

Latest Threads

Top