Calling the stdcall Delphi function using pAnisChar from node js

I have an outdated Delphi dll that requires a json string (pAnsiChar) and returns an int as success or failure. I managed to connect to the dll from nodejs using node -ffi. However, I get a return int value that points to an invalid json string.

Can someone point me to how to call Delphi dll with pAnsiChar as function arguments from node

thanks

+4
source share
3 answers

PAnsiCharin Delphi is char*in C / C ++. In the FFI statement for the DLL function, simply declare the parameter PAnsiCharas "string", which is a char * with zero completion in FFI.

, Delphi:

function ProcessJson(Json: PAnsiChar): Integer; stdcall;

node.js :

var ffi = require('ffi');

var mydll = ffi.Library('mydll', {
  'ProcessJson': [ 'int', [ 'string' ] ]
});

var ret = mydll.ProcessJson("json content here");
+4

, Node FFI . cdecl. , Delphi :

function MyFunction(str: PAnsiChar): Integer; cdecl;

node -ffi , :

var ffi = require('ffi');
var mylib = ffi.Library('libname', {
  'MyFunction': [ 'int', [ 'string' ] ]
});
var retval = mylib.MyFunction("some string");

DLL, , DLL, , cdecl, DLL stdcall.

+5

, node -ffi :

thiscall, fastcall MSVC cdecl Windows

readme.

This is not a good source of information, but there is no mention of stdcall in readme. fastcall is supported, although it is also a calling call cleanup convention, so it is best to switch your functions to fastcall instead of cdecl if you want to call the Delphi DLL using node -ffi.

I will try to name some simple StdCall functions with node -ffi to make sure that it can handle them correctly and check here when I have some results.

0
source

Source: https://habr.com/ru/post/1523742/


All Articles