调用C++编写的dll的问题

weishigao 2016-08-01 10:38:50
有一个VC的DLL,函数说明如下:
BOOLEAN Tuc_EnumTouchScreen(
OUT PCHAR *paths,
OUT INT &count
);

paths
[out]设备路径数组。
Handle
[out]设备个数。

========================
C++调用范例:
INT deviceCount = 0;
PUCHAR devicePaths[64] = {0};
for (int i=0; i<64; i++)
{
devicePaths[i] = new char[256];
ZeroMemory(devicePaths[i],256);
}
Tuc_EnumTouchScreen(devicePaths, deviceCount);


在DELPHI中,应该如何声明?
我现在是这样声明:
function Tuc_EnumTouchScreen(out paths:PChar;out Handle:Integer):Boolean;stdcall; external 'TucLib.dll' name 'Tuc_EnumTouchScreen';

调用是这样:
procedure TForm1.Button1Click(Sender: TObject);
var
I,count:Integer;
paths: array[0..63] of PChar;
begin
for I := 0 to 63 do
begin
paths[I] := StrAlloc(256);
end;

Tuc_EnumTouchScreen(paths[0],count);
end;

运行提示,无法定位dll程序输入点,请问高手,应该如何声明和调用。
...全文
1056 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
看那山瞧那水 2016-08-01
  • 打赏
  • 举报
回复
D7以上版本 var I,count:Integer; paths: array[0..63] of PAnsiChar; function Tuc_EnumTouchScreen(out paths:PChar;out Handle:Integer):Boolean;stdcall; external 'TucLib.dll' name 'Tuc_EnumTouchScreen'; -> function Tuc_EnumTouchScreen(paths:PPAnsiChar; Handle:Integer):Boolean;stdcall; external 'TucLib.dll' name 'Tuc_EnumTouchScreen'; 调用 Tuc_EnumTouchScreen(@paths,Count); 如果paths是动态数组: paths: array of PAnsiChar; SetLength(paths,64); 调用 Tuc_EnumTouchScreen(paths,Count); 参数OUT PCHAR *paths是PPAnsiChar 不用OUT修饰符
  • 打赏
  • 举报
回复
1,从C函数声明来看,并没有__stdcall、__attribute__((stdcall))这种修饰,所以不能假定是stdcall调用约定。 2,OUT INT &count这是引用参数,也就是Pascal中的变参,应该翻译为var count: integer 3,不能使用动态数组作为paths参数,Delphi编译器对动态数组参数会隐含传入一个high bound参数,导致count参数获取不正确。

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧