nodejs呼叫c dll感想

2021-07-16 03:03:25 字數 2416 閱讀 1507

這幾天折騰了幾天終於搞定了,nodejs呼叫c++dll的問題,回想起來有一下幾個難點:

1:函式引數,型別如下:

unsigned short arg0 = args[0]->uint32value();//其他整數型別類似

args[0]->tostring()

string::newfromutf8(isolate, 「data」)//建立乙個string型別

2:返回結構:

local

obj = object::new(isolate);

obj->

set(string

::newfromutf8(isolate, "re"), num);

obj->

set(string

::newfromutf8(isolate, "handle"), handle);

local

<

array

> arr =

array

::new(isolate, max_axis );

for (int i =

0; i < max_axis; ++i)

obj->set(string::newfromutf8(isolate, "data"), arr);

args.getreturnvalue().set(obj);

**中構造的string型別供外部呼叫使用。

總體**如下:

// cnc_resetconnect.cc

#include

#include

#include

#include

namespace demo odbaxis;

void getodbaxis(short value, odbaxis dta, isolate* isolate, local& obj)

obj->set(string::newfromutf8(isolate, "re"), num);

obj->set(string::newfromutf8(isolate, "dummy"), dummy);

obj->set(string::newfromutf8(isolate, "type"), type);

obj->set(string::newfromutf8(isolate, "data"), arr);

}/* read machine axis position */

//fwlibapi short winapi cnc_machine(unsigned short, short, short, odbaxis *);

void cnc_machine(const functioncallbackinfo& args)

hinstance hdll;

hdll = loadlibrary("fwlib32.dll");//載入動態鏈結庫fwlib32.dll檔案;

if (!hdll)

typedef

short(winapi *pmax)(unsigned

short, short, short, odbaxis *);//函式指標

pmax pcnc_resetconnect = null;

pcnc_resetconnect = (pmax)getprocaddress(hdll, "cnc_machine");

if (!pcnc_resetconnect)

unsigned

short arg0 = args[0]->uint32value();

unsigned

short arg1 = args[1]->uint32value();

unsigned

short arg2 = args[2]->uint32value();

odbaxis obj = {};

short value = pcnc_resetconnect(arg0, arg1, arg2, &obj);

localobjr = object::new(isolate);

getodbaxis(value, obj, isolate, objr);

args.getreturnvalue().set(objr/*string::newfromutf8(isolate, preturn)*/);

//localnum = uint32::new(isolate, value);

// set the return value (using the passed in

// functioncallbackinfo&)

}void init(localexports)

node_module(addon, init)

} // namespace demo

C 呼叫C Dll例程

form1.cs內容 using system using system.windows.forms using system.runtime.interopservices using system.text 申明dll中函式 dllimport kb dll.dll entrypoint inp...

aspx呼叫c dll異常

託管除錯助手 pinvokestackimbalance 在 c program files common files microsoft shared devserver 11.0 webdev.webserver40.exe 中檢測到故障。其他資訊 對 pinvoke 函式 fashionboo...

MFC呼叫C DLL細節

一 使用 clr 編譯 mfc 可執行檔案或規則 dll 1 開啟專案屬性對話方塊,方法是右鍵單擊解決方案資源管理器中的專案並選擇屬性。2 展開配置屬性旁邊的節點並選擇常規。在右側窗格中的專案預設值下,將公共語言執行庫支援設定為公共語言執行庫支援 clr 3 在相同的窗格中,確保將mfc 的使用設定...