How to Passs NULL as a IDispatch Pointer to method?

Larry Bates larry.bates at websafe.com
Tue Apr 17 16:10:12 EDT 2007


ZhaoYingpu at 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




More information about the Python-list mailing list