<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style id="css_styles" type="text/css"><!--blockquote.cite { margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc }
blockquote.cite2 {margin-left: 5px; margin-right: 0px; padding-left: 10px; padding-right:0px; border-left: 1px solid #cccccc; margin-top: 3px; padding-top: 0px; }
a img { border: 0px; }
li[style='text-align: center;'], li[style='text-align: center; '], li[style='text-align: right;'], li[style='text-align: right; '] {  list-style-position: inside;}
body { font-family: 'Segoe UI'; font-size: 12pt; }
.quote { margin-left: 1em; margin-right: 1em; border-left: 5px #ebebeb solid; padding-left: 0.3em; }
--></style>
</head>
<body>
<div style="font-family: "JetBrains Mono", "Courier New", monospace; white-space: pre;">
<div style=""><font size="1" style="font-size: 13.3px;">For the following code, the method "GetPerson" has no explicit argument (except self).</font></div>
<div style=""></div>
<div style=""><br>
</div>
<div style="font-size: 10pt;"><span style="background-color: white;"><span style="color:#9C9;">class</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#C9C;font-weight:bold;">MyCOMObject</span><span style="color:#CCC;">:</span></span></div>
<div style="font-size: 10pt;"><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">    </span><span style="color:#CCC;">_public_methods_</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">=</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">[</span><span style="color:#F99157;">"GetPerson"</span><span style="color:#CCC;">]</span></span></div>
<div style="font-size: 10pt;"><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">    </span><span style="color:#999;">#_reg_clsid_ = '{44ee76c7-1290-4ea6-8189-00d5d7cd712a}'</span></span></div>
<div style="font-size: 10pt;"><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">    </span><span style="color:#999;">#_reg_desc_ = "My COM server"</span></span></div>
<div style="font-size: 10pt;"><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">    </span><span style="color:#999;">#_reg_progid_ = "MyCOMObject"<br>
</span></span></div>
<div style="font-size: 10pt;"><br>
</div>
<div style="font-size: 10pt;"><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">    </span><span style="color:#9C9;">def</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#69C;font-weight:bold;">get_person</span><span style="color:#CCC;">(</span><span style="color:#9C9;">self</span><span style="color:#CCC;">):</span></span></div>
<div style="font-size: 10pt;"><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">        </span><span style="color:#CCC;">person</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">=</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">Person(</span><span style="color:#F99157;">"haha"</span><span style="color:#CCC;">,</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#F99157;">45</span><span style="color:#CCC;">)</span></span></div>
<div style="font-size: 10pt;"><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">        </span><span style="color:#CCC;">wrapped</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">=</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">win32com.server.util.wrap(person,</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">useDispatcher</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">=</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">my_dispatcher)</span></span></div>
<div style="font-size: 10pt;"><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">        </span><span style="color:#9C9;">return</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">wrapped<br>
</span></span></div>
<div style="font-size: 10pt;"><br>
</div>
<div style="font-size: 10pt;"><br>
</div>
<div style="font-size: 10pt;">When calling from VBA, like below , it works fine.</div>
<div style="font-size: 10pt;">    Set o = CreateObject("MyCOMObject") </div>
<div style="font-size: 10pt;">    Set p = o.get_person()</div>
<div style="font-size: 10pt;"><br>
</div>
<div style="font-size: 10pt;">However, when calling from C++, or Delphi, the following error will be thrown:
</div>
<div style="font-size: 10pt;"><i>"TypeError: MyCOMObject.get_person() takes 1 positional argument but 2 were given"</i></div>
<div style="font-size: 10pt;"><i><br>
</i></div>
<div style="font-size: 10pt;">Delphi code:</div>
<div style="font-size: 10pt;"><br>
</div>
<div style="font-size: 10pt;"><i>procedure TForm1.Button1Click(Sender: TObject); </i>
</div>
<div style="font-size: 10pt;"><i>var </i></div>
<div style="font-size: 10pt;"><i>  o: OleVariant; </i></div>
<div style="font-size: 10pt;"><i>  p: OleVariant; </i></div>
<div style="font-size: 10pt;"><i style="font-size: 10pt;">begin </i></div>
<div style="font-size: 10pt;"><i>  o := CreateOleObject('MyCOMObject'); </i></div>
<div style="font-size: 10pt;"><i style="font-size: 10pt;"> <b> p := o.get_person()</b>; // error will be thrown
</i></div>
<div style="font-size: 10pt;"><i>  s := p.name; </i></div>
<div style="font-size: 10pt;"><i>  age := p.age; </i></div>
<div style="font-size: 10pt;"><i>  ShowMessage(s); </i></div>
<div style="font-size: 10pt;"><i>end;</i></div>
<div style="font-size: 10pt;"><i><br>
</i></div>
<div style=""><font size="1" style="font-size: 13.3px;">The fix is to change Line 639 of policy.py to the following:</font></div>
<div style=""><font size="1" style="font-size: 13.3px;"><br>
</font></div>
<div style=""><font size="1" style="font-size: 13.3px; background-color: white;">    
</font></div>
<div style="">
<div style="font-size: 10pt;">
<div><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">                
</span><span style="color:#9C9;">if</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#9C9;">len</span><span style="color:#CCC;">(args)</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">==</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#F99157;">1</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#9C9;">and</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">(args[</span><span style="color:#F99157;">0</span><span style="color:#CCC;">]</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">==</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">-</span><span style="color:#F99157;">2147352572</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#9C9;">or</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">args[</span><span style="color:#F99157;">0</span><span style="color:#CCC;">]</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">==</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#9C9;">None</span><span style="color:#CCC;">):</span></span></div>
<div><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">                
</span><span style="color:#9C9;">return</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">func()</span></span></div>
<div><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">                
</span><span style="color:#9C9;">else</span><span style="color:#CCC;">:</span></span></div>
<div><span style="background-color: white;"><span style="color: rgb(192, 192, 192);">                
</span><span style="color:#9C9;">return</span><span style="color: rgb(192, 192, 192);"> </span><span style="color:#CCC;">func(*args)</span></span><br>
</div>
</div>
</div>
</div>
</body>
</html>