可以调用过程,可是调用完后就进入一个像汇编程序一样的调试界面,并提示:too many consecutive exceptions 'access violation at 0x000000:read of address 0x000000' .
不知道是什么原因?
//动态连接库
library Project1;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
sharemem,Dialogs,
SysUtils,
Classes;{$R *.res}
procedure display;export;
begin
showmessage('dll dialog');
end;
exports
display;
begin
end.//程序调用
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Tsh = procedure;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
p:Tsh;
MyHandle:THandle;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
MyHandle:=windows.LoadLibrary('.\project1.dll');
if MyHandle<>0 then
begin
@p:=windows.GetProcAddress(MyHandle,'display');
if @p<>nil then
begin
Tsh(p);
windows.FreeLibrary(MyHandle);
end;
end
else ShowMessage('DLL do not exist.'); // Windows.FreeLibrary(MyHandle);
end;end.
不知道是什么原因?
//动态连接库
library Project1;{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }uses
sharemem,Dialogs,
SysUtils,
Classes;{$R *.res}
procedure display;export;
begin
showmessage('dll dialog');
end;
exports
display;
begin
end.//程序调用
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Tsh = procedure;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
p:Tsh;
MyHandle:THandle;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
MyHandle:=windows.LoadLibrary('.\project1.dll');
if MyHandle<>0 then
begin
@p:=windows.GetProcAddress(MyHandle,'display');
if @p<>nil then
begin
Tsh(p);
windows.FreeLibrary(MyHandle);
end;
end
else ShowMessage('DLL do not exist.'); // Windows.FreeLibrary(MyHandle);
end;end.
begin
showmessage('dll dialog');
end;type
Tsh = procedure;stdcall;
procedure display; external 'project1.dll';
要不会不知道是你的dll接口还是对procedure 的从新定义.这个会产生歧义,最好是随便定义一个参数什么的比较好.