<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"><meta name="Generator" content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"Palatino Linotype";
        panose-1:2 4 5 2 5 5 5 3 3 4;}
@font-face
        {font-family:"Imperial BT";}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Palatino Linotype","serif";
        color:navy;
        font-weight:normal;
        font-style:normal;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang="EN-GB" link="blue" vlink="purple"><div class="WordSection1"><p class="MsoNormal"><span style="color:#1f497d">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.</span></p>
<p class="MsoNormal"><span style="color:#1f497d"> </span></p><p class="MsoNormal"><span style="color:#1f497d">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.</span></p>
<p class="MsoNormal"><span style="color:#1f497d"> </span></p><div style="border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt"><div><div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span lang="EN-US" style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> python-win32-bounces+graham.bloice=<a href="mailto:trihedral.com@python.org">trihedral.com@python.org</a> [mailto:<a href="mailto:python-win32-bounces%2Bgraham.bloice">python-win32-bounces+graham.bloice</a>=<a href="mailto:trihedral.com@python.org">trihedral.com@python.org</a>] <b>On Behalf Of </b>Fox, Michael K<br>
<b>Sent:</b> 21 July 2012 04:55<br><b>To:</b> <a href="mailto:python-win32@python.org">python-win32@python.org</a><br><b>Subject:</b> [python-win32] Need data type identifiers</span></p></div></div><p class="MsoNormal"> </p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:12.0pt;font-family:"Palatino Linotype","serif";color:navy">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 </span><span lang="EN-US">(24584, 3)</span><span lang="EN-US" style="font-size:12.0pt;font-family:"Palatino Linotype","serif";color:navy"> and an array of variants is assigned </span><span lang="EN-US">(24588, 3) </span><span lang="EN-US" style="font-size:12.0pt;font-family:"Palatino Linotype","serif";color:navy">as shown in the line of code below, taken from one of the wrappers created by Makepy.</span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:12.0pt;font-family:"Palatino Linotype","serif";color:navy"> </span></p><p class="MsoNormal" style="text-autospace:none"><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:blue">def</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black"> <b>GetDirection</b>(<i>self</i>, oDirection=(</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:maroon">0</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black">,</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:maroon">0</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black">)):</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas"></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black"> </span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:blue">return</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black"> <i>self</i>._ApplyTypes_(</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:maroon">1611137025</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black">, </span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:maroon">1</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black">, (</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:maroon">24</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black">, </span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:maroon">0</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black">), ((</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:maroon">24588</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black">,</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:maroon">3</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black">),), u</span><i><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:#00aa00">'GetDirection'</span></i><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black">, </span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:blue">None</span><span lang="EN-US" style="font-size:10.0pt;font-family:Consolas;color:black">, oDirection)</span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:12.0pt;font-family:"Palatino Linotype","serif";color:navy"> </span></p><p class="MsoNormal"><span lang="EN-US" style="font-size:12.0pt;font-family:"Palatino Linotype","serif";color:navy">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. <span style="background:yellow">Where can we find a list of these identifiers?</span></span></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:12.0pt;font-family:"Palatino Linotype","serif";color:navy"> </span></p><p class="MsoNormal" align="center" style="text-align:center"><b><span lang="EN-US" style="font-size:12.0pt;font-family:"Imperial BT";color:black">Mike Fox</span></b></p>
<p class="MsoNormal"><span lang="EN-US"> </span></p></div></div></body></html>