[python-win32] Fixing type ID for an interface file generated by makepy

Tim Roberts timr at probo.com
Tue Jan 25 19:37:41 CET 2011


Brad Buran wrote:
> When I generate the interface file for a COM object using makepy, it
> generates an incorrect signature for one of the methods:
>
> def ReadTag(self, Name=defaultNamedNotOptArg,
> pBuf=defaultNamedNotOptArg, nOS=defaultNamedNotOptArg,
> nWords=defaultNamedNotOptArg):
>     return self._oleobj_.InvokeTypes(9, LCID, 1, (3, 0), ((8, 0),
> (16388, 0), (3, 0), (3, 0)),Name
>         , pBuf, nOS, nWords)
>
> The  C++ signature for the method is (based on a working C++ example
> provided by the manufacturer):
>
> long ReadTag(LPCTSTR Name, float * pBuf, long nOS, long nWords)
> {
> 	long result;
> 	static BYTE parms[] = VTS_BSTR VTS_PR4 VTS_I4 VTS_I4 ;
> 	InvokeHelper(0x9, DISPATCH_METHOD, VT_I4, (void*)&result, parms,
> Name, pBuf, nOS, nWords);
> 	return result;
> }
>
> My understanding is that 16388 corresponds to VT_R4 (based on an old
> email thread on this list).

No.  16388 is 4+16384, which is VT_R4+VT_BYREF.  So, this is a
single-precision float passed by reference -- meaning by pointer.

So, the Python declaration says VT_I4 (return type), VT_BSTR,
VT_R4+VT_BYREF, VT_I4, and VT_I4.  That's mostly correct.

What problems are you seeing?  There is one potential issue here, in
that the C++ string is declared as LPCTSTR.  That's not a valid COM
type.  All COM strings have to be Unicode (as VT_BSTR will be), but if
the server is compiled ANSI, then LPCTSTR will be expecting an ANSI string.

> However, it should be a type code that corresponds to VTS_PR4.

That must be something the manufacturer invented, because VTS_PR4 does
not occur anywhere in the Windows SDK.

> I would really appreciate any guidance in 1) figuring out the best way
> to fix the signature or 2) finding a more comprehensive list of the
> actual constant the type codes corresponds to.

Do you have the SDK?  The master list is in the header file WTypes.h. 
The VT codes are a bit field -- the low 12-bits are the type code, and
the bits above that are flags, like VT_BYREF.

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



More information about the python-win32 mailing list