B
bluesky2006
Unregistered / Unconfirmed
GUEST, unregistred user!
我用VC++做了一个dll,想用Delphi调用它。编译通过了,但是执行时候总弹出 Access violation at address00403E58 in module 'Project1.exe'.Read of address255FFF8.这样的错误。请教各位大侠!
我的VC++的函数是:
extern "C" _declspec(dllexport) int getDate(U16* adDate)
在Delphi中的调用如下:
在Unit2中声明
interface
type
TgetDate=function( adDateointer):Integer; stdcall;
在Unit1中
type
pointer=^Linkdata;
LinkData=Record
num:word;
nextointer;
end;
var
Form1: TForm1;
implementation
uses Unit2;
procedure TForm1.Button1Click(Sender: TObject);
var
getDate:TgetDate;
s,i:Integer;
Infor: pointer;
date:array[1..1000]of word;
begin
getMem(Infor,sizeof(word));
i:=1;
Handle:=LoadLibrary('PC.dll');//将“PC.dll”的文件映象映射进调用进程的地址空间
if Handle<>0 then
begin
@getDate:=GetProcAddress(Handle,'getDate');//取得DLL中函数getDate( )的地址
if @getDate<>nil then
begin
s:=getDate(Infor);
while (intToStr(Infor.num) <>'') do
begin
date:=Infor.num;
Memo1.Lines.Add(IntTostr(date));
Infor:=Infor.next;
i:=i+1;
end;
else
ShowMessage('调用函数“GetProcAddress”时出错!');
FreeLibrary(Handle); //从进程的地址空间中解除“MaxMin.dll”文件的映射
FreeMem(infor);
end;
end.
我的VC++的函数是:
extern "C" _declspec(dllexport) int getDate(U16* adDate)
在Delphi中的调用如下:
在Unit2中声明
interface
type
TgetDate=function( adDateointer):Integer; stdcall;
在Unit1中
type
pointer=^Linkdata;
LinkData=Record
num:word;
nextointer;
end;
var
Form1: TForm1;
implementation
uses Unit2;
procedure TForm1.Button1Click(Sender: TObject);
var
getDate:TgetDate;
s,i:Integer;
Infor: pointer;
date:array[1..1000]of word;
begin
getMem(Infor,sizeof(word));
i:=1;
Handle:=LoadLibrary('PC.dll');//将“PC.dll”的文件映象映射进调用进程的地址空间
if Handle<>0 then
begin
@getDate:=GetProcAddress(Handle,'getDate');//取得DLL中函数getDate( )的地址
if @getDate<>nil then
begin
s:=getDate(Infor);
while (intToStr(Infor.num) <>'') do
begin
date:=Infor.num;
Memo1.Lines.Add(IntTostr(date));
Infor:=Infor.next;
i:=i+1;
end;
else
ShowMessage('调用函数“GetProcAddress”时出错!');
FreeLibrary(Handle); //从进程的地址空间中解除“MaxMin.dll”文件的映射
FreeMem(infor);
end;
end.