2016-07-29 36 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) 

}