Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting dllimport from vb6 to c# 3.5
    text
    copied!<p>I have some code in VB6 which imports a function from a dll, it uses the byVal and byRef keywords, I want to convert that code into C# 3.5.</p> <ol> <li><p>Is there going to be a problem with unicode encoding of the strings?</p></li> <li><p>Do I declare the varibles that are "byRef" in vb6 into "ref" varibles in the C# code?</p></li> <li><p>It seams that return value is entered into a string send by the VB6 code as a "byVal" parameter, how does that work, aren't you supposed to send stuff "byRef", if you want to allow the function to edit the string? Is this concept still going to work with my C# code?</p></li> </ol> <p>I tryed coping the function declaration from VB6, the parameter types are just int's, long's and string. Where there was a "byVal" keyword I just left it empty and replaced "byRef" keywords with the "ref" keyword in C# and the code dosn't work.</p> <p>The VB6 Code:</p> <pre> Private Declare Function Foo Lib "Foo_Functions.dll" (ByVal a as String, ByVal b<br /> as Long, ByVal c as String, ByVal d as String, ByVal e as String, ByVal f<br /> as String, ByVal g as Long, ByVal h as String, ByVal i as String, ByRef j<br /> as Long, ByRef k as Long) As <br />Integer </pre> <p>My C# 3.5 Translation:</p> <pre> [Dllimkport("foo_functions.dll")] public static extern int foo(String a, long b,<br /> string c, string d, string e, string f, long g, string h, stringbuilder i,<br /> ref long j, ref long k); </pre> <p>Please help, I'v already spent a whole day on this :p....</p> <p>In the end I converted the function call to a VB.NET lib, using the automatic project converter (from VB6 to VB.NET 2008), and called it using C# reference.</p> <p>Thanks.</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