.dll issue! VBA to C#?!
-
Hi! I´m trying to translate Vba call method from .dll. But if i translate it it won´t be the same in C#. The code in VBA:
Public Sub SnodAnrop()
i = Module1.snod25x(host, port, user, pass, cert, cacert, service, arg, extra, result, buf)
End SubDeclare Function snod25x Lib "sn25.dll" Alias "****" (ByVal Host As String, ByVal Port As String, ByVal User As String, ByVal Passwd As String, ByVal Cert As String, ByVal CAert As String, ByVal Nodtjanst As String, ByVal Arg As String, ByVal Extra As String, ByVal Result As String, ByVal Resultbuf As Long) As Long
The translation to C# have i done like this:
[DllImport("sn25.dll", EntryPoint = "****")]
static extern int snod(string host, string port, string user, string passwd, string cert, string CAert, string Nodtjänst, string arg, string extra, string result, int buf); private void button1_Click(object sender, EventArgs e){ int i = snod("", "", user, pass, "", "", service, arg, "",result, 1024); } The problem is now is the string "result" in VBA returns info, but in C# it doesn´t collect any info at all. Int i returns a status value wich is 0 that meens OK. The problem is that i dont get any info back with the string "result" in C# How Would u translate it? Have i missed something? Im pretty new in C# so explain easely. Would Appriciate some help!!! Thanks!!!!
-
Hi! I´m trying to translate Vba call method from .dll. But if i translate it it won´t be the same in C#. The code in VBA:
Public Sub SnodAnrop()
i = Module1.snod25x(host, port, user, pass, cert, cacert, service, arg, extra, result, buf)
End SubDeclare Function snod25x Lib "sn25.dll" Alias "****" (ByVal Host As String, ByVal Port As String, ByVal User As String, ByVal Passwd As String, ByVal Cert As String, ByVal CAert As String, ByVal Nodtjanst As String, ByVal Arg As String, ByVal Extra As String, ByVal Result As String, ByVal Resultbuf As Long) As Long
The translation to C# have i done like this:
[DllImport("sn25.dll", EntryPoint = "****")]
static extern int snod(string host, string port, string user, string passwd, string cert, string CAert, string Nodtjänst, string arg, string extra, string result, int buf); private void button1_Click(object sender, EventArgs e){ int i = snod("", "", user, pass, "", "", service, arg, "",result, 1024); } The problem is now is the string "result" in VBA returns info, but in C# it doesn´t collect any info at all. Int i returns a status value wich is 0 that meens OK. The problem is that i dont get any info back with the string "result" in C# How Would u translate it? Have i missed something? Im pretty new in C# so explain easely. Would Appriciate some help!!! Thanks!!!!
-
Hi! I´m trying to translate Vba call method from .dll. But if i translate it it won´t be the same in C#. The code in VBA:
Public Sub SnodAnrop()
i = Module1.snod25x(host, port, user, pass, cert, cacert, service, arg, extra, result, buf)
End SubDeclare Function snod25x Lib "sn25.dll" Alias "****" (ByVal Host As String, ByVal Port As String, ByVal User As String, ByVal Passwd As String, ByVal Cert As String, ByVal CAert As String, ByVal Nodtjanst As String, ByVal Arg As String, ByVal Extra As String, ByVal Result As String, ByVal Resultbuf As Long) As Long
The translation to C# have i done like this:
[DllImport("sn25.dll", EntryPoint = "****")]
static extern int snod(string host, string port, string user, string passwd, string cert, string CAert, string Nodtjänst, string arg, string extra, string result, int buf); private void button1_Click(object sender, EventArgs e){ int i = snod("", "", user, pass, "", "", service, arg, "",result, 1024); } The problem is now is the string "result" in VBA returns info, but in C# it doesn´t collect any info at all. Int i returns a status value wich is 0 that meens OK. The problem is that i dont get any info back with the string "result" in C# How Would u translate it? Have i missed something? Im pretty new in C# so explain easely. Would Appriciate some help!!! Thanks!!!!
Bold text is used to emphasise something. Please don't do this to everything that you write. For a method to be able to update a string parameter, you have to use the
ref
keyword to send the parameter by reference. I'm not certain if you have posted the correct VBA code. It's sending the parameter by value, which would not make it possible for the function to update the string.Despite everything, the person most likely to be fooling you next is yourself.
-
Hi! I´m trying to translate Vba call method from .dll. But if i translate it it won´t be the same in C#. The code in VBA:
Public Sub SnodAnrop()
i = Module1.snod25x(host, port, user, pass, cert, cacert, service, arg, extra, result, buf)
End SubDeclare Function snod25x Lib "sn25.dll" Alias "****" (ByVal Host As String, ByVal Port As String, ByVal User As String, ByVal Passwd As String, ByVal Cert As String, ByVal CAert As String, ByVal Nodtjanst As String, ByVal Arg As String, ByVal Extra As String, ByVal Result As String, ByVal Resultbuf As Long) As Long
The translation to C# have i done like this:
[DllImport("sn25.dll", EntryPoint = "****")]
static extern int snod(string host, string port, string user, string passwd, string cert, string CAert, string Nodtjänst, string arg, string extra, string result, int buf); private void button1_Click(object sender, EventArgs e){ int i = snod("", "", user, pass, "", "", service, arg, "",result, 1024); } The problem is now is the string "result" in VBA returns info, but in C# it doesn´t collect any info at all. Int i returns a status value wich is 0 that meens OK. The problem is that i dont get any info back with the string "result" in C# How Would u translate it? Have i missed something? Im pretty new in C# so explain easely. Would Appriciate some help!!! Thanks!!!!
Your problem may be resolved by using a StringBuilder for the result buffer and I'll point you to a reference showing the win32 api function GetWindowText which returns a string. http://msdn.microsoft.com/en-us/magazine/cc301501.aspx[^]
[DllImport("sn25.dll", EntryPoint = "****")]
static extern int snod(string host, string port,
string user, string passwd,
string cert, string CAert,
string Nodtjänst, string arg,
string extra,
StringBuilder result, int buf);You'd then call your function like this
// create a 1K buffer
StringBuilder sb = new StringBuilder(1024);
int res = snod(............, sb, sb.Capacity);
string resultStr = sb.ToString();Also make sure that you know what type of encoding the result string uses, i.e. Ansi or Unicode and set CharSet appropriately in your DllImport attribute. I'm not an expert at this so can't guarantee that these suggestions will work, but hopefully... Alan.