Thanks for the reply,<div>Here are the relevant lines from pybonjour.py:</div><div><br></div><div>line 84: </div><div>_CFunc = ctypes.WINFUNCTYPE<br><div><br></div><div>line 579 - 824 (some omitted):</div><div>(Start code)</div>
<div><div>def _create_function_bindings():</div><div><br></div><div>    ERRCHECK    = True</div><div>    NO_ERRCHECK = False</div><div><br></div><div>    OUTPARAM    = (lambda index: index)</div><div>    NO_OUTPARAM = None</div>
<div><br></div><div>    specs = {</div><div><br></div><div>        #&#39;funcname&#39;:</div><div>        #(</div><div>        #    return_type,</div><div>        #    errcheck,</div><div>        #    outparam,</div><div>
        #    (</div><div>        #<span class="Apple-tab-span" style="white-space:pre">        </span>param_1_type,</div><div>        #<span class="Apple-tab-span" style="white-space:pre">        </span>param_2_type,</div><div>        #<span class="Apple-tab-span" style="white-space:pre">        </span>...</div>
<div>        #<span class="Apple-tab-span" style="white-space:pre">        </span>param_n_type,</div><div>        #<span class="Apple-tab-span" style="white-space:pre">        </span>)),</div><div><br></div><div>        &#39;DNSServiceRefSockFD&#39;:</div>
<div>        (</div><div>            ctypes.c_int,</div><div>            NO_ERRCHECK,</div><div>            NO_OUTPARAM,</div><div>            (</div><div>                DNSServiceRef,<span class="Apple-tab-span" style="white-space:pre">                        </span># sdRef</div>
<div>                )),</div><div><br></div><div>        ### ... 15 definitions in between here ... ###</div><div><br></div><div>        &#39;DNSServiceConstructFullName&#39;:</div><div>        (</div><div>            ctypes.c_int,</div>
<div>            ERRCHECK,</div><div>            OUTPARAM(0),</div><div>            (</div><div>                ctypes.c_char * kDNSServiceMaxDomainName,<span class="Apple-tab-span" style="white-space:pre">        </span># fullName</div>
<div>                _utf8_char_p,<span class="Apple-tab-span" style="white-space:pre">                                        </span># service</div><div>                _utf8_char_p_non_null,<span class="Apple-tab-span" style="white-space:pre">                                </span># regtype</div>
<div>                _utf8_char_p_non_null,<span class="Apple-tab-span" style="white-space:pre">                                </span># domain</div><div>                )),</div><div><br></div><div>        }</div><div><br></div><div><br></div><div>
    for name, (restype, errcheck, outparam, argtypes) in specs.iteritems():</div><div>        prototype = _CFunc(restype, *argtypes)</div><div><br></div><div>        paramflags = [1] * len(argtypes)</div><div>        if outparam is not None:</div>
<div>            paramflags[outparam] = 2</div><div>        paramflags = tuple((val,) for val in paramflags)</div><div><br></div><div>        func = prototype((name, _libdnssd), paramflags)</div><div><br></div><div>        if errcheck:</div>
<div>            func.errcheck = BonjourError._errcheck</div><div><br></div><div>        globals()[&#39;_&#39; + name] = func</div><div><br></div><div><br></div><div># Only need to do this once</div><div>_create_function_bindings()</div>
</div><div>(End code)</div><div><br></div><div>The line &#39; func = prototype((name, _libdnssd), paramflags) &#39; fails with the following exception:</div><div><div>  File &quot;test_pybonjour.py&quot;, line 34, in &lt;module&gt;</div>
<div>  File &quot;C:\Users\clemens\Downloads\pybonjour-1.1.1\pybonjour-1.1.1\pybonjour.py&quot;, line 824, in &lt;module&gt;</div><div>  File &quot;C:\Users\clemens\Downloads\pybonjour-1.1.1\pybonjour-1.1.1\pybonjour.py&quot;, line 815, in _create_function_bindings</div>
<div>TypeError: WinFunctionType() takes at most 2 arguments (3 given)</div></div><div><br></div><div>Cheers,</div><div>Clemens</div><div><div class="gmail_quote"><br></div><div class="gmail_quote">On Mon, Sep 13, 2010 at 11:55 PM, Dino Viehland <span dir="ltr">&lt;<a href="mailto:dinov@microsoft.com">dinov@microsoft.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">





<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">It’s not that
</span>WINFUNCTYPE is always changing in CPython – it’s that each time you run it’ll have a different ID.  In IronPython we allocate object IDs sequentially starting at 43.  So if the only thing you call id() on (which printing the repr does implicitly) then
 the 1<sup>st</sup> object will always have an id of 43.  If you did “id(100)” first and then looked at ctypes.WINFUNCTYPE then you’d see it’d be 0x2C.</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">Can you include the line of code where the call is happening and an setup to get into the call?  It does look like there’s a 3<sup>rd</sup> argument that’s optional because:</p>
<p class="MsoNormal"> </p>
<p class="MsoNormal">from ctypes import *</p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">WINFUNCTYPE(c_int, c_int, c_int)(100, &#39;foo&#39;, &#39;100&#39;)</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D">Starts reporting a different error message on CPython than IronPython.  My guess is we need to implement this but there don’t seem to be any tests for it so
 if we can see at least 1 call site that’d be helpful </span><span style="font-size:11.0pt;font-family:Wingdings;color:#1F497D">J</span><span style="font-size:11.0pt;color:#1F497D">  can you open a bug on CodePlex for this
 as well?</span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;color:#1F497D"> </span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt">From:</span></b><span style="font-size:10.0pt"> <a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a> [mailto:<a href="mailto:users-bounces@lists.ironpython.com" target="_blank">users-bounces@lists.ironpython.com</a>]
<b>On Behalf Of </b>Clemens Nylandsted Klokmose<br>
<b>Sent:</b> Sunday, September 12, 2010 7:48 AM<br>
<b>To:</b> <a href="mailto:users@lists.ironpython.com" target="_blank">users@lists.ironpython.com</a><br>
<b>Subject:</b> [IronPython] PyBonjour through Ctypes</span></p>
</div>
</div><div><div></div><div class="h5">
<p class="MsoNormal"> </p>
<p class="MsoNormal">Hi,</p>
<div>
<p class="MsoNormal">I am experimenting with getting a Python library running in IronPython that relies on PyBonjour (<a href="http://code.google.com/p/pybonjour/" target="_blank">http://code.google.com/p/pybonjour/</a>).</p>

</div>
<div>
<p class="MsoNormal">PyBonjour is a pure python library interfacing with the systems bonjour installation. I am completely unexperienced with CTypes, so what I am proposing now might seem naïve.</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">At the top of the pybonjour.py is code looking like this:</p>
</div>
<div>
<div>
<p class="MsoNormal">if sys.platform == &#39;win32&#39;:</p>
</div>
<div>
<p class="MsoNormal">    # Need to use the stdcall variants</p>
</div>
<div>
<p class="MsoNormal">    _libdnssd = ctypes.windll.dnssd</p>
</div>
<div>
<p class="MsoNormal">    _CFunc = ctypes.WINFUNCTYPE</p>
</div>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">IronPython&#39;s sys.platform evaluates to &#39;cli&#39;, so I have tried to change the check to if sys.platform == &#39;win32&#39; or sys.platform == &#39;cli&#39;:</p>
</div>
<div>
<p class="MsoNormal">This seems to work, but everytime a C function is called now, Python complains that theres an argument too much.</p>
</div>
<div>
<p class="MsoNormal">E.g. TypeError: CFunctionType() takes at most 2 arguments (3 given). My suggestion is that ctypes.WINFUNCTYPE in IronPython might be a wrong value? (In IronPython it seems to always be 0x000000000000002B, whereas in CPython the value varies)</p>

</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">Does anyone have an idea of how to go about this?</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">It should be noted that I have pybonjour running with the standard CPython on Windows.</p>
</div>
<div>
<p class="MsoNormal"> </p>
</div>
<div>
<p class="MsoNormal">Thanks,</p>
</div>
<div>
<p class="MsoNormal">Clemens</p>
</div>
</div></div></div>
</div>
</div>

<br>_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
<br></blockquote></div><br></div></div>