[python-win32] How to pass "out" parameter to win32com

Tim Roberts timr at probo.com
Tue Jul 1 18:49:57 CEST 2014


jh_wang2004 wrote:
> ------------------------------------------------------------------------------------------------------
>
> Hi Tim:
>     Thanks a lot for you reply. According to the COM document , the
> function declaration in
> C++ is
>    lRet = object.ReadDeviceBlock(szDevice、lSize、*lplData)
>        Long lRet  (return value, 0 is read success, otherwise is read
> failed)   Output
>        CString szDevice (Device register name)  Input
>       Long lSize (Read data counter) Input
>       Long *lplData (restore read value from device) Output

That's not a function declaration.  That's an example call of how to
call it.  This doesn't show how the parameters are actually declared. 
For example, you cannot have a CString as a COM parameter.  It's not
allowed.  A program might pass a CString, but it will be converted to a
COM string type, based on the declaration.

Too many people do not understand that there are strict rules for
declaring COM parameters, to make sure they work in all of the various
languages that can refer to COM.  Even without seeing the actual
declaration, I can tell you that this API violates those rules.  You
can't pass a raw pointer, because some languages can't deal with raw
pointers.  Plus, there's no way for the called function to know how
large that buffer is.

-- 
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.



More information about the python-win32 mailing list