改用Delphi调用动态库(原C#调用动态库)

hong6530 2012-09-21 02:56:54
用C#调用正常
[DllImport("plcommpro.dll", EntryPoint = "GetDeviceData")]
public static extern int GetDeviceData(IntPtr h, ref byte buffer, int buffersize, string tablename, string filename, string filter, string options);

private void btngetdat_Click(object sender, EventArgs e)
{
int ret = 0;
int BUFFERSIZE = 10 * 1024 * 1024;
byte[] buffer = new byte[BUFFERSIZE];
if (IntPtr.Zero != h)
{
ret = GetDeviceData(h, ref buffer[0],BUFFERSIZE, "user", "*", "", "");
}
else
{
MessageBox.Show("Connect device failed!");
return;
}
}


改Delphi调用出错,求指点
Type TGetDeviceData=function(h:hWnd;var buffer:array of PByte;BufferSize: Longint; TableName,FieldNames,Filter,Options: string):Integer;Stdcall;

procedure TfrmMain.dxBarLargeButton2Click(Sender: TObject);
var
buffer :array of PByte;
lBUFFERSIZE: Longint;
ret,lLength,lStrat,lEnd: Integer;
devtablename, str, devdatfilter, options:string;
begin
ret :=0;
lBUFFERSIZE :=10*1024*1024;
SetLength(buffer,lBUFFERSIZE);
ret :=GetDeviceData(h,buffer,lBUFFERSIZE, 'user', '*', '','');
if ret >= 0 then
begin
ShowMessage(IntToStr(ret));
end;
end;

...全文
327 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
山东蓝鸟贵薪 2013-01-01
  • 打赏
  • 举报
回复
delphi可以调用C#的DLL文件, 但是要注意C#的DLL文件中的接口的,否则就会出错的
SS_LO 2013-01-01
  • 打赏
  • 举报
回复
buffer:array of PByte ----> buffer:array of byte or buffer:Pbyte test???
fang 2012-12-31
  • 打赏
  • 举报
回复
Type TGetDeviceData=function(h:hWnd;var buffer:array of PByte;BufferSize: Longint; TableName,FieldNames,Filter,Options: string):Integer;Stdcall; 是不是调用约定的问题啊,Stdcall换成cdecl试下;
hxy3100 2012-12-19
  • 打赏
  • 举报
回复
var buffer:array of PByte改成var buffer:array of Byte试试
SQLDebug_Fan 2012-12-18
  • 打赏
  • 举报
回复
DELPHI要调C#的动态,需要做成COM
javamy038 2012-12-17
  • 打赏
  • 举报
回复
谢谢。虽然根本看不懂 !!

1,184

社区成员

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

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