<div>You&#39;d need to decorate the string array parameter with a lot more information -- it&#39;s an ANSI string rather than a Unicode string, for instance, and there&#39;s another parameter that describes the length of the array. But I just looked at the code for clrtype.accepts, and it doesn&#39;t appear to support decorating the parameter types with additional attributes. If you can get at the TypeBuilder -- and I know this used to be possible -- then the easiest way to implement this is probably just to call TypeBuilder.DefinePInvokeMethod directly.</div>

<div> </div>
<div> </div>
<div>Is there a typo in the C# code? It looks like SizeParamIndex should be 1 and not 10.<br><br></div>
<div class="gmail_quote">On Sat, Jun 5, 2010 at 10:57 PM, Ashley Abraham <span dir="ltr">&lt;<a href="mailto:abrahams84@gmail.com">abrahams84@gmail.com</a>&gt;</span> wrote:<br>
<blockquote style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" class="gmail_quote">Hi, <br>    I have the following C# code and I am trying to do the same functionality in IronPython, any help is appreciated. <br>
<br>I was trying to do the same functionality in IronPython using the clrtype.py from the IronPython-2.6-Samples and I am able to connect to the library and the function but I am having trouble passing array of strings. With the current code it only passes the first letter and then it crashes.<br>
<br>I am trying to call  <span style="FONT-FAMILY: courier new,monospace">cwavec(int, int, char *)</span> and it is a C function which is part of the vniwave.dll and I am trying access it in IronPython.<br><br>C# code:<br>
<br><span style="FONT-FAMILY: courier new,monospace">namespace PVWave<br>{        <br>    public class OPI<br>    {<br></span><span style="FONT-FAMILY: courier new,monospace">        </span><span style="FONT-FAMILY: courier new,monospace">[DllImport(&quot;C:\\datk_code\\VNI\\wave\\bin\\bin.i386nt\\vniwave.dll&quot;,</span><br style="FONT-FAMILY: courier new,monospace">
<span style="FONT-FAMILY: courier new,monospace">            EntryPoint = &quot;cwavec&quot;,</span><br style="FONT-FAMILY: courier new,monospace"><span style="FONT-FAMILY: courier new,monospace">            ExactSpelling = false,</span><br style="FONT-FAMILY: courier new,monospace">
<span style="FONT-FAMILY: courier new,monospace">            CharSet = CharSet.Ansi,</span><br style="FONT-FAMILY: courier new,monospace"><span style="FONT-FAMILY: courier new,monospace">            SetLastError = true)]</span><br style="FONT-FAMILY: courier new,monospace">
<span style="FONT-FAMILY: courier new,monospace">        public static extern unsafe int cwavec(Int32 action, Int32 nCmds,</span><br style="FONT-FAMILY: courier new,monospace"><span style="FONT-FAMILY: courier new,monospace">            [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr, SizeParamIndex = 10)] string[] cmds);</span><br>
<br><span style="FONT-FAMILY: courier new,monospace">    }<br>}<br><br><font face="arial,helvetica,sans-serif">Here is my attempt in IronPython:<br><br><font face="courier new,monospace">import clrtype<br>import System<br>
import sys<br><br>class OPI(object):<br>    &quot;Description of Class&quot;<br>    <br>    # Note that you could also the &quot;ctypes&quot; modules instead of pinvoke declarations<br>    __metaclass__ = clrtype.ClrClass<br>
    <br>    sys.path.append(&quot;C:\\datk_code\\VNI\\wave\\bin\\bin.i386nt&quot;)<br><br>    from System.Runtime.InteropServices import DllImportAttribute, PreserveSigAttribute<br>    DllImport = clrtype.attribute(DllImportAttribute)<br>
    PreserveSig = clrtype.attribute(PreserveSigAttribute)</font><br></font><br><br>    @staticmethod<br>    @DllImport(&quot;vniwave.dll&quot;)<br>    @PreserveSig()<br>    @clrtype.accepts(System.Int32, System.Int32, System.Array[System.String])<br>
    @clrtype.returns()<br>    def cwavec(action, nCommands, commands): raise RuntimeError(&quot;this should not get called&quot;)<br><br>def call_pinvoke_method_pvwave():<br>    print &quot;Calling pinvoke pvwave methods:&quot;<br>
    actionNum = 2<br>    nCommands = 1<br>    commands = System.Array[System.String]([&#39;PRINT, &quot;Connected to PV-Wave from IronPython&quot;&#39;])<br>    print &quot;cwavec(action, nCommands, commands):&quot;<br>    OPI.cwavec(actionNum, nCommands, commands)<br>
<br>call_pinvoke_method_pvwave()<br></span><br>Thanks<br>Ash<br><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>