edge icon indicating copy to clipboard operation
edge copied to clipboard

User C# in Node.JS and DLLimport

Open tdupuy17 opened this issue 9 years ago • 6 comments

Hello,

I try to import DLL and execute C# code in node.js but my C# code works very well in Visual Studio, but not in node.js... This the code : (The error is on commented line "ERROR")

var edge = require('edge');

var helloWorld = edge.func(function () {/*

  using System;
  using System.Collections.Generic;
  using System.Runtime.InteropServices;
  using System.Threading.Tasks;
  using System.Net;

  class Startup
      {
      [DllImport("BLUEBOXLib.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
      static extern int BLUEBOX_Init(out int Handle);

      [DllImport("BLUEBOXLib.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
      static extern int BLUEBOX_SetAddress(ref int Handle, byte Address);

      [DllImport("BLUEBOXLib.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
      static extern int BLUEBOX_Close(ref int Handle);

      [DllImport("BLUEBOXLib.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
      static extern int BLUEBOX_End(ref int Handle);

      [DllImport("BLUEBOXLib.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
      static extern int BLUEBOX_SetChannel(ref int Handle, String Channel, String Settings);

      public async Task<object> Invoke(dynamic input)
      {
        return await Task<object>.Run(() => {
            byte Address = Convert.ToByte(255);
            IPAddress Ip = IPAddress.Parse("192.168.4.200");
            UInt16 Port = Convert.ToUInt16(3000);
            int Handle;
            int Err = 0;

            Err = Startup.BLUEBOX_Init(out Handle);
            Console.WriteLine("Init : "+ Err);

            // check library initialization
            if (Err != 0)
            {
                Console.WriteLine("BLUEBOXLib.dll: Library load error!");

                Startup.BLUEBOX_Close(ref Handle);
                Startup.BLUEBOX_End(ref Handle);

                return "false";
            } else {
                Err = Startup.BLUEBOX_SetAddress(ref Handle, Address);
                Console.WriteLine(Err);
                if (Err == 0)
                {
                    // create the settings string to pass to library
                    System.String strSettings = "192.168.4.200:3000,60000";

                    Err = Startup.BLUEBOX_SetChannel(ref Handle, "TCP", strSettings);
                    //ERROR The function return -2 in Err, that signifies "Handle Error"
                    //She must return 0, like while I run the code in Visual Studio
                }

                if (Err != 0)
                {

                    Startup.BLUEBOX_Close(ref Handle);
                    Startup.BLUEBOX_End(ref Handle);

                    return "false2";

                } else {

                // SOME CODE
                }
            }
return "true";
        });
      }
  }



*/});

helloWorld({test:1},function(error,result){
  console.log("ERROR : "+error);
console.log("RESULT : "+result);

});

Do you have an idea that why it's not works ?

tdupuy17 avatar Aug 27 '15 15:08 tdupuy17

I assume the architecture (x86/x64) of the native DLLs you are pulling in within your code matches the architecture of node.exe you are using?

I would start by running Process Monitor on your app to see if you spot any anomalies in DLL loading or in native calls being made.

tjanczuk avatar Aug 27 '15 15:08 tjanczuk

Hello, I have two DLLs, one for x64, one for x86. I am not sure about that you request... we'll see this with the Process Monitor : (I don't know if is this that you want...)

capture d ecran 2015-08-28 a 08 51 01

tdupuy17 avatar Aug 28 '15 06:08 tdupuy17

An idea please ?

tdupuy17 avatar Aug 31 '15 08:08 tdupuy17

+1

creativefull avatar Aug 29 '16 09:08 creativefull

hey @Icemaaan how did you solve this???

cjcruz avatar May 12 '17 00:05 cjcruz

hir sir please i need you samples for c# bluebox are change a lot of here library that i need to use library in my project that i don't found an samples in his official site can you help me with you c# sample thanks sir

vbiste avatar Jun 07 '20 14:06 vbiste