edge
edge copied to clipboard
User C# in Node.JS and DLLimport
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 ?
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.
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...)
An idea please ?
+1
hey @Icemaaan how did you solve this???
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