[python-win32] Need data type identifiers

Graham Bloice graham.bloice at trihedral.com
Mon Jul 23 09:47:24 CEST 2012


This issue sometimes occurs when the typelib specifies a VARIANT type
argument, implying that any VARIANT type will do, but the COM server is
coded to expect an actual type and does not (incorrectly IMHO) attempt to
convert the incoming VARIANT to the appropriate type.  Makepy has no idea
of what type is really expected so I think converts the parameter based on
the Python type of the value passed in the call.  This may or may not line
up with what the COM Server is expecting.



When this occurs, and you don’t have access to the COM Server code to fix
it, you must force the COM Client to pass the appropriate types.
“Adjusting” the makepy generated file is one way of doing this.



*From:* python-win32-bounces+graham.bloice=trihedral.com at python.org [mailto:
python-win32-bounces+graham.bloice=trihedral.com at python.org] *On
Behalf Of *Fox,
Michael K
*Sent:* 21 July 2012 04:55
*To:* python-win32 at python.org
*Subject:* [python-win32] Need data type identifiers



We are having occasional difficulties when we need to pass an argument
in-and-out of a COM method that we are calling in Python.  There is some
magic in makepy that normally handles this for us but occasionally it fails
because it somehow reads the typelib incorrectly and misunderstands the
data type it must create.  Specifically, I have a C++ method exposed to COM
and it expects an empty SafeArray of two elements (double floats) to be
passed as an argument.  That method revises the array, filling it with two
values.  We have found that makepy assigns some sort of identifier to each
data type.  For instance an array of strings is assigned (24584, 3) and an
array of variants is assigned (24588, 3) as shown in the line of code
below, taken from one of the wrappers created by Makepy.



def *GetDirection*(*self*, oDirection=(0,0)):

              return *self*._ApplyTypes_(1611137025, 1, (24, 0), ((24588,3),),
u*'GetDirection'*, None, oDirection)



Occasionally pywin32 assigns the wrong identifier then the argument is cast
as the wrong data type and an error is thrown.  We stumbled upon the
correct identifier and when we corrected the identifier assigned by Makepy
then we were able to call the method without throwing an error.  Where can
we find a list of these identifiers?



*Mike Fox*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20120723/b5749807/attachment.html>


More information about the python-win32 mailing list