因做一个项目,需要调用一个用C写的DLL文件的一个函数,
在该DLL文件的接口手册中有关该函数的描述如下:Synatax:
int ReadCard(Int ReadType,char* DataBuffer)
Description:
DataBuffer 必须分配1024字节的空间或者更大。
Return value:
0:正确执行;
-1:运行出错;我写的单元如下,可执行后出现一个地址错误:请各位大侠指教。
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm2 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
function ReadCard(ReadType: integer; DataBuffer: Pointer): integer; stdcall; external 'SiInterface.dll' name 'ReadCard';
implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
var
DataB: pchar;
begin
Edit1.Text := '';
if ReadCard(5, @DataB) = 0 then
Edit1.Text := DataB
else
Edit1.Text := '错误';
end;end.
在该DLL文件的接口手册中有关该函数的描述如下:Synatax:
int ReadCard(Int ReadType,char* DataBuffer)
Description:
DataBuffer 必须分配1024字节的空间或者更大。
Return value:
0:正确执行;
-1:运行出错;我写的单元如下,可执行后出现一个地址错误:请各位大侠指教。
unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm2 = class(TForm)
Edit1: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;
function ReadCard(ReadType: integer; DataBuffer: Pointer): integer; stdcall; external 'SiInterface.dll' name 'ReadCard';
implementation{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
var
DataB: pchar;
begin
Edit1.Text := '';
if ReadCard(5, @DataB) = 0 then
Edit1.Text := DataB
else
Edit1.Text := '错误';
end;end.
在C里面是:int ReadCard(Int ReadType,char* DataBuffer)
我在Delphi中对应写成:function ReadCard(ReadType: integer; DataBuffer: Pointer): integer;
不知是否正确,请指教。