简体   繁体   中英

Calling cpp function from NodeJS which has argument const int16_t *bar but getting error unbound type

I am trying to call CPP function from NodeJS

typedef struct foo {

    uint8_t     *data;
    int         dataSize;

} foo ;

foo *ExtractBar(const int16_t *bar);

I have tried nbind library in NodeJS. but getting unbound type error.

uint16 = Int16Array.from('12345');
uint16.fill(0);
lib.ExtractBar(uint16);

I have also tried ffi-napi npm module. but from that I was getting segmentation fault error. can anyone help me please on how to pass correct argument from NodeJS code. I am not sure how to create similar structure in NodeJS-

const int16_t *bar

Usually you have to have a reference to a variable as JavaScript is a garbage collected language.

Specifically to nbind, have a look at this and this . You want to pass from NodeJS an buffer of uint16 so you could use nbind::Buffer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM