首页 > 解决方案 > 从 delphi 或 lazarus 调用 Visual Studio dll

问题描述

我需要从 delphi 7 或 lazarus 调用一个 dll。关于 dll 的信息很少,但我有一个在 Visual Studio 中使用的示例:声明:

    [DllImport("landwell.dll", EntryPoint = "PTcomm", CharSet = CharSet.Auto)]
    public static extern int PTcomm(int com, int boud, ref int Rcount);
    [DllImport("landwell.dll", EntryPoint = "PTcomm_YPWJ", CharSet = CharSet.Auto)]
    public static extern int PTcomm_YPWJ(int com, int boud, ref int Rcount);

    [DllImport("landwell.dll", EntryPoint = "PTrecord", CharSet = CharSet.Auto)]
    public static extern int PTrecord(int num,byte[] record);

如何在 Delphi 7 或 Lazarus 中声明和调用这些函数?

我唯一的文档是: 1、Common Transmit: PTcomm(int com,int boud,int *Rcount) Com是串口号,boud rate是9600,*Rcount是记录总数
“1”表示返回成功, “0”表示无记录,“-1”表示打开端口不成功,“-2”表示发送不成功

2、常用采集数据 PTrecord(int num,byte record[8]) record{8} 表示8byte(包括读卡器号),num 表示序列号 “1”表示返回成功,“0”表示返回不成功我只有Visual Studio 中的一个示例,我什至无法尝试,因为它是用旧版本的 VS 编写的,并且自动转换不起作用。这时候我没有学习VS的打算。文章前面提到的声明来自那个例子。有人指责我什至没有尝试过,他们不认识我,也不知道我做了什么。我尝试过但失败了,这就是我要问的原因。

谢谢,让-克劳德

标签: delphidlllazarus

解决方案


在 Delphi 和 Lazarus 中尝试这些声明:

function PTcomm(com, boud: Integer; var Rcount: Integer): Integer; stdcall; external 'landwell.dll';

function PTcomm_YPWJ(com, boud: Integer; var Rcount: Integer): Integer; stdcall; external 'landwell.dll';

function PTrecord(num: Integer; rec: PByte): Integer; stdcall; external 'landwell.dll';

推荐阅读