调用DLL中的FORM时,系统提示access violation at adress in module 'about.dll',read of adress

  • 主题发起人 主题发起人 gst
  • 开始时间 开始时间
G

gst

Unregistered / Unconfirmed
GUEST, unregistred user!
调用DLL中的FORM时,系统提示access violation at adress in module 'about.dll',read of adress (100分)<br />-------DLL单元如下
library about;
uses
SysUtils,
Classes,
aboutunit in 'aboutunit.pas' {AboutDllForm};
{$R *.RES}
exports AboutDllFormCreate;
begin
end.
--------ABOUTUNIT单元如下:
unit aboutunit;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls;

type
TAboutDllForm = class(TForm)
Bevel1: TBevel;
Image1: TImage;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ Private declarations }
step:integer;
public
{ Public declarations }
end;

var
AboutDllForm: TAboutDllForm;

function AboutDllFormCreate:integer; stdcall;
implementation

{$R *.DFM}
function AboutDllFormCreate:integer; stdcall;
begin
showmessage('hello');
AboutDllForm:=TAboutDllForm.Create(Application);
AboutDllForm.ShowModal;

end;

procedure TAboutDllForm.Timer1Timer(Sender: TObject);
begin
If step&gt;AboutDllForm.Image1.Height Then step:=AboutDllForm.Image1.Height
Else If step&lt;-200 Then step:=AboutDllForm.Image1.Height
Else step:=step-1;
AboutDllForm.Paint;
end;

procedure TAboutDllForm.FormPaint(Sender: TObject);
var Bitmap:TBitMap;
begin
Bitmap:=TBitmap.Create;
Bitmap.LoadFromFile('about.bmp');
AboutDllForm.Image1.Canvas.Brush.Color:=clBlack;
AboutDllForm.Image1.Canvas.Rectangle(AboutDllForm.Image1.ClientRect);
AboutDllForm.Image1.Canvas.Draw(10,step,BitMap);
end;
end.
---------DLL的调用单元如下:
unit testdlg;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
Function AboutDllFormCreate:integer; stdcall; external 'about.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
AboutDllFormCreate;
end;
end.
程序的功能是在DLL中显示一个FORM,FORM中的IMAGE控件从下到上的动态显示一个图片
,实际运行中ABOUTUNIT中的SHOEMESSAGE可以正常显示,但是FORM不行,系统提示系统提示
access violation at adress in module 'about.dll',read of adress FFFFFFF
请问为什么,如何处理?????
 
DLL的调用

procedure TForm1.Button1Click(Sender: TObject);
var hr:Thandle;
begin
hr:=loadlibrary('about.dll');
if hr=0 then showmessage('dll false!')
else
begin
@AboutDllFormCreate:=GetProcAddress(hr,AboutDllFormCreate);
AboutDllFormCreate;
end;
freelibrary(hr);
end;
 
但是系统提示[Error] testdlg.pas(36): Left side cannot be assigned to
请问如何解决
 

Function AboutDllFormCreate:integer; stdcall;

procedure TForm1.Button1Click(Sender: TObject);
var hr:Thandle;
begin
hr:=loadlibrary('about.dll');
if hr=0 then showmessage('dll false!')
else
begin
@AboutDllFormCreate:=GetProcAddress(hr,'AboutDllFormCreate');
AboutDllFormCreate;
end;
freelibrary(hr);
end;
 
可是问题依旧,我用的是DELPHI 5.0
 
改一下试试:
function AboutDllFormCreate:integer; stdcall;
begin
showmessage('hello');
AboutDllForm:=TAboutDllForm.Create(nil);
try
AboutDllForm.ShowModal;
finally
AboutDllForm.Free;
end;
end;
或者在 exe 和 DLL 的工程文件 (*.dpr) 中第一个引用 sharemem 单元。
library mydll;
uses sharemem, ...;
...
program myexe;
uses sharemem, ...;
...
 
function AboutDllFormCreate(AHandle:THandle):integer; stdcall;
begin
application.handle:=AHandle; //
showmessage('hello');
AboutDllForm:=TAboutDllForm.Create(Application);
AboutDllForm.ShowModal;
end;

exe:
procedure TForm1.Button1Click(Sender: TObject);
var hr:Thandle;
begin
hr:=loadlibrary('about.dll');
if hr=0 then showmessage('dll false!')
else
begin
@AboutDllFormCreate:=GetProcAddress(hr,AboutDllFormCreate);
AboutDllFormCreate(handle);//
end;
freelibrary(hr);
end;

// 而且好像stdcall也会发生问题(delphi教程中也是用stdcall),老出问题,
我用expert后不会
// sharemem 是要传string参数给dll时才要(见delphi中自动生成的dll的e文说明)
 
procedure TForm1.Button1Click(Sender: TObject);
type
TAboutDllFormCreate = function:integer;
var hr:Thandle;
AboutDllFormCreate : TABoutdllformcreate;
begin
hr:=loadlibrary('about.dll');
if hr=0 then showmessage('dll false!')
else
begin
@AboutDllFormCreate:=GetProcAddress(hr,AboutDllFormCreate);
AboutDllFormCreate;
end;
freelibrary(hr);
end;
 
接受答案了.
 
后退
顶部