Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

273
Visualizações
Is there an easy way in NodeJS to call functions from a 3rd-party API that uses custom data types?

Currently I am by importing the C++ .dll using ffi-napi calling the functions in NodeJS directly, but it requires me to define all the custom data types in NodeJS if I want to pass them as function arguments.

I am looking for an alternate method to call functions from a C++ .dll that uses custom data types or a different approach with ffi-napi.

Below is my current implementation using ffi-napi:

C++ Header:

Enum1 some_function (
     Enum2 var1,
     Struct1* var2,
     Struct1* var3,
     Enum3* var4);
);

NodeJS:

var ref = require('ref-napi');
var ffi = require('ffi-napi');
var Struct = require('ref-struct-napi');
var Enum = require('enum')
var Union = require('ref-union-napi')

var somelib = new ffi.Library("somedll.dll", {
"some_function": [
    Enum1, [Enum2, Struct1*, Struct1*, Enum3*] // ignore correctness for simplicity
]});

I can define the custom data types (Enum1, Struct1, Enum3, etc.) in NodeJS using the modules shown above since NodeJS does not support these natively. Even using ref.refType(Type) to get pointers.

The difficulty is that these Struct types can be nested. For example, Struct1 in the C++ Header is defined:

typedef struct Struct1 {
Struct2 var1;
Struct3 var2;
Struct4 var3;
};

Struct1 has 3 other Structs within. I will just show how Struct4 is defined in C++ Header:

typedef struct Struct4 {
Enum4 var1;
Struct5 var2;
Struct6 var3;
union {
    Struct7* var4;
    Struct8* var5;
    Struct9* var6;
    Struct10* var7;
};

These structs may also contain a few other data types.

When I need to call some_function, I will need to pass variables of the respective argument data types

somelib.some_function(Enum2Var, &Struct1Var1, &Struct1Var2, &Enum3Var); // ignore correctness for simplicity

I am wondering if there is a better implementation than having to manually define all of these data types in NodeJS to correctly use these functions.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda