Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. .dll issue! VBA to C#?!

.dll issue! VBA to C#?!

Scheduled Pinned Locked Moved C#
helpcsharpquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andredani
    wrote on last edited by
    #1

    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 Sub

    Declare 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!!!!

    S G A 3 Replies Last reply
    0
    • A andredani

      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 Sub

      Declare 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!!!!

      S Offline
      S Offline
      selcuks
      wrote on last edited by
      #2

      U may use this site: http://www.carlosag.net/Tools/CodeTranslator/Default.aspx[^]

      Always keep the Murphy Rules in mind!

      1 Reply Last reply
      0
      • A andredani

        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 Sub

        Declare 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!!!!

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • A andredani

          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 Sub

          Declare 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!!!!

          A Offline
          A Offline
          Alan N
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups