dll代码如下:
library Project2;uses
SysUtils,
Classes,
Pic in 'Pic.pas' {Form1};{$R *.res}begin
end.
unit Pic;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls;type
TForm1 = class(TForm)
Image1: TImage;
private
{ Private declarations }
public
{ Public declarations }
end;function aa(ahandle :THandle) : TPicture;stdcall;implementation
function aa(aHandle :THandle) : tpicture;
var
picform : TForm1;
begin
application.Handle := aHandle;
picform := TForm1.Create(application);
try
picform.ShowModal;
result := picform.Image1.Picture;
finally
picform.Free;
end;
end;
{$R *.dfm}end.
调用DLL的应用程序代码如下:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Taa = function (ahandle :THandle) : TPicture;stdcall;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
LibHandle : THandle;
aa : Taa;
begin
LibHandle := LoadLibrary('Project.dll');
try
@aa := GetProcAddress(LibHandle,'aa');
aa(application.Handle);
finally
freeLibrary(LibHandle);
end;
end;end.编译DLL顺利通过,运行调用DLL的应用程序也通过 ,但是单击调用DLL的应用程序上的按扭后 就出现什么地址发生冲突的错误了。请高手帮忙指点。
library Project2;uses
SysUtils,
Classes,
Pic in 'Pic.pas' {Form1};{$R *.res}begin
end.
unit Pic;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, jpeg, ExtCtrls;type
TForm1 = class(TForm)
Image1: TImage;
private
{ Private declarations }
public
{ Public declarations }
end;function aa(ahandle :THandle) : TPicture;stdcall;implementation
function aa(aHandle :THandle) : tpicture;
var
picform : TForm1;
begin
application.Handle := aHandle;
picform := TForm1.Create(application);
try
picform.ShowModal;
result := picform.Image1.Picture;
finally
picform.Free;
end;
end;
{$R *.dfm}end.
调用DLL的应用程序代码如下:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
Taa = function (ahandle :THandle) : TPicture;stdcall;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
LibHandle : THandle;
aa : Taa;
begin
LibHandle := LoadLibrary('Project.dll');
try
@aa := GetProcAddress(LibHandle,'aa');
aa(application.Handle);
finally
freeLibrary(LibHandle);
end;
end;end.编译DLL顺利通过,运行调用DLL的应用程序也通过 ,但是单击调用DLL的应用程序上的按扭后 就出现什么地址发生冲突的错误了。请高手帮忙指点。
var
LibHandle : THandle;
aa : Taa;
begin
LibHandle := LoadLibrary('Project.dll');
if LibHandle = 0 then
begin
showmessage('0');
exit;
end;
try
@aa := GetProcAddress(LibHandle,'aa');
if @aa = nil then
begin
showmessage('nil');
exit;
end;
aa(application.Handle);
finally
freeLibrary(LibHandle);
end;
end;