2016-07-29 37 views
0

我想在Visual Studio 2015中使用包含C++和C#代码的dll创建一个本地节点扩展。我不能使它在以前的my own instructions之后工作,这是基于最新的node-gyp如何在node.js中使用混合C++&.Net dll? (Error:abort()has been called)

当不使用/clr选项时,我可以运行类似下面的程序。

console.log("1"); 
const addon = require('./build/Release/addon'); 
console.log("2"); 

当启用/clr时,只有第一次调用日志被执行。当编译在调试模式下的dll,我得到以下信息:

enter image description here

如何修复/调试呢?

(我知道有优势,但我试图去节点GYP方式)

回答

0

失败摆弄在VS2015所有(?)编译器和连接选项之后,我发现了如何设置我binding.gyp相反,为了获取.NET工作:

{ 
    "targets": [ 
    { 
     "target_name": "addon", 
     "sources": [ "hello.cc" ], 
     "msbuild_settings": { 
     "ClCompile": { 
      "CompileAsManaged": "true", 
      "ExceptionHandling": "Async", 
     }, 
     }, 
    } 
    ] 
} 

我的成功执行的托管和非托管代码如下混合证实构建:

#include <node.h> 
#include <v8.h> 

namespace demo { 

    #pragma managed 

    void callManaged() 
    { 
    System::String^ result = gcnew System::String("hola"); 
    System::Console::WriteLine("It works: " + result); 
    } 

    #pragma unmanaged 

    using v8::FunctionCallbackInfo; 
    using v8::Isolate; 
    using v8::Local; 
    using v8::Object; 
    using v8::String; 
    using v8::Value; 

    void Method(const FunctionCallbackInfo<Value>& args) { 
    Isolate* isolate = args.GetIsolate(); 
    callManaged(); 
    args.GetReturnValue().Set(String::NewFromUtf8(isolate, "woooooorld")); 
    } 

    void init(Local<Object> exports) { 
    NODE_SET_METHOD(exports, "hello", Method); 
    } 

    NODE_MODULE(addon, init) 

}