Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Modifiable byVal strings should work if you replace them with <code>StringBuilder</code> in C#. Another possible solution is to use <code>[MarshalAs(UnmanagedType.VBByRefStr)] ref string i</code>.</p> <p>I used the "Upgrade Visual Basic 6 code..." tool in Visual Studio and this resulted in the following VB.NET code:</p> <pre><code>Private Declare Function Foo Lib "Foo_Functions.dll" (ByVal a As String, _ ByVal b As Integer, ByVal c As String, ByVal d As String, ByVal e As _ String, ByVal f As String, ByVal g As Integer, ByVal h As String, ByVal i _ As String, ByRef j As Integer, ByRef k As Integer) As Short </code></pre> <p>Note that VB6 <code>Long</code> was converted to <code>Integer</code> and VB6 <code>Integer</code> was converted to <code>Short</code>. I then used reflector to see how it should look like in C#:</p> <pre><code>[DllImport("Foo_Functions.dll", CharSet=CharSet.Ansi, SetLastError=true, ExactSpelling=true)] private static extern short Foo([MarshalAs(UnmanagedType.VBByRefStr)] ref string a, int b, [MarshalAs(UnmanagedType.VBByRefStr)] ref string c, [MarshalAs(UnmanagedType.VBByRefStr)] ref string d, [MarshalAs(UnmanagedType.VBByRefStr)] ref string e, [MarshalAs(UnmanagedType.VBByRefStr)] ref string f, int g, [MarshalAs(UnmanagedType.VBByRefStr)] ref string h, [MarshalAs(UnmanagedType.VBByRefStr)] ref string i, ref int j, ref int k); </code></pre> <p>This is the exact translation of the VB6 declaration and should have the same behaviour. If this still doesn't work then perhaps you could describe how exactly it doesn't work (does the unmanaged function ever get called, are the arguments garbage, are the returned values garbage, something else?).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload