[python-win32] MIDL & MakePy
Tim Roberts
timr at probo.com
Thu Mar 4 19:06:20 CET 2010
Dave Cross wrote:
>
> Can anyone explain how MakePy interprets COM IDL?
Well, remember that MakePy does not interpret IDL. MakePy reads the
TLB, which is the compiled version of the IDL. By the time MakePy sees
it, it's already been through one level of interpretation.
> If I define:
> HRESULT Test([out] byte* outp);
> Makepy generates:
> """method Test"""
> return self._ApplyTypes_(3, 1, (24, 0), ((16401, 2),), u'Test',
> None,outp)
> and I can interpret (16401,2) as VT_UI1, BYREF and OUT.
>
> If, however, I define:
> HRESULT Test([in] long len, [in, size_is(len)] byte outp[]);
> MakePy generates:
> """method Test"""
> return self._ApplyTypes_(4, 1, (24, 0), ((16387, 3), (16401, 2)),
> u'Test', None,len, outp)
> and the marshalling of outp is still a pointer to a single byte, not
> an array of bytes.
There is no difference in C (or C++) between "byte* outp" and "byte
outp[]" in a parameter list. It's just two different ways to spell of
the same thing.
> Manually editing the MakePy class to use a value of 16412 (i.e.
> VT_CARRAY BYREF) gives me a
> 'VARIANT Type is unknown' exception as does 16414 (VT_LPSTR)
> Adding in 0x2000 to set VT_ARRAY leads to a 'Type mismatch' error.
Right. MakePy only understand the types that are COM
dispatch-compliant, and VT_CARRAY is not one of those. It cannot be
handled safely in all languages. VT_ARRAY designates that the parameter
is a pointer to a SAFEARRAY structure.
> Is there some doccumentation somewhere to tell me which VARIANT types
> I can use and how to do arrays?
You said you couldn't change the server, right? Unless the COM object
is expecting a pointer to VARIANT, you cannot just pass it one. As I
said, you're going to need some kind of adapter.
--
Tim Roberts, timr at probo.com
Providenza & Boekelheide, Inc.
More information about the python-win32
mailing list