[python-win32] problem with reference parameter to COM function(makepy)

Mark Hammond mhammond at skippinet.com.au
Tue Jun 6 03:51:37 CEST 2006

> I'm trying to use win32com to drive a COM object.  I ran makepy to
> create the interface and am (apparently) able to run some of the
> object's functions.  I'm having problem, though, with functions that
> have reference parameters (e.g., pointer to bool).  
> I saw in some documentation (on oreilly.com) that makepy was 
> supposed to
> arrange things so that these returned values are returned as a tuple
> from the function, but that seems not to have happened in 
> this case.

That is true in most cases - but its not obvious from the makepy generated
file - did you actually call the function?

> Is there something I can do to force this?  Or, am I doing something else
> wrong?
> Here's the documented signature:
>      long	IsError(BOOL FAR* pbIsError);

Its not clear what the true IDL signature is for the function.  If the long
is actually the HRESULT, then pywin32 will *not* return that value (but will
instead throw an exception if a failure code is returned).  Indeed, this is
what I believe is happening...

> and here's what makepy generated:
> 	def IsError(self, pbIsError=defaultNamedNotOptArg):
> 		"""method IsError"""
> 		return self._oleobj_.InvokeTypes(7, LCID, 1, (24, 0),
> ((16387, 0),),pbIsError
> 			)

makepy has decided the return value from the function is VT_VOID (the 24).
As a result, pywin32 considers this function to have only 1 return value -
so a tuple will *not* be returned - just 'pbIsError' (if the function fails,
an exception is thrown - hence the 'long' is not considered a return value
as such.)

I also note that the first param appears to be missing the [out] qualifer in
the IDL (reflected in the second tuple item being 0).  If the single value
you get returned is always None, that will be the reason.  I'm afraid I
can't recall exactly what pywin32 will do in such a case.

Hope this helps...

-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 2680 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-win32/attachments/20060606/28b0c53d/attachment.bin 

More information about the Python-win32 mailing list