node.js调用Delphi写的Dll

本文介绍了如何使用Node.js调用由Delphi编写的DLL。首先展示了Delphi的DLL代码,强调了string类型的处理和编码转换。接着,详细说明了在Node.js中安装和配置ffi库的步骤,包括安装必要的编译工具和库。最后,针对可能出现的动态链接错误193及其解决方案进行了讨论,指出问题在于64位Node.js与32位DLL的不匹配,解决办法是确保两者位数一致。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、调用代码

Delphi版本Delphi 10 Seattle

Delphi代码

unit Unit1;

interface

function testint(i: Integer): Integer; stdcall;
function testpchar(value: PAnsiChar): PAnsiChar; stdcall;

implementation

function testint(i: Integer): Integer; stdcall;
begin
  result := i + 1000;
end;

function testpchar(value: PAnsiChar): PAnsiChar; stdcall;
var
  svalue: string;
begin
  svalue := Utf8ToAnsi(value);
  svalue := '你好:' + svalue;
  result := PAnsiChar(AnsiToUtf8(svalue));
end;

end.
library test;

{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even thos
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值