X
xac
Unregistered / Unconfirmed
GUEST, unregistred user!
就下面的代码,我在调用时,能正常显示DLL 中MDI窗体
可是在,主程序退出时,就会出现非法操作,216 错误,
各位高手能帮我我看看吗?
'0x00fa34aa'指令引用0x01003398内存,该内存不能为"read"
Runtime Error 216 at 00fa34aa
动态库如下:
library ProjectDll;
uses
Windows,
SysUtils,
Classes,
Controls,
Forms,
UnitDll in 'UnitDll.pas' {Form1};
procedure CreateChild(ParentApplication: TApplication
ParentForm: TForm;ParentScreen:TScreen)
export
stdcall;
var
Form1: Tform1;
begin
Screen:=ParentScreen;
Application:=ParentApplication;
Form1:=TForm1.Create(ParentForm);
Form1.Caption:='Title';
Form1.Show;
end;
exports
CreateChild;
begin
end.
============================================
unit UnitDll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$R *.dfm}
end.
==========================================
调用:
unit ld2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
T_ProvaChild=procedure (ParentApplication:Tapplication;ParentForm:Tform;ParentScreen:Tscreen);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
DllHandle: THandle;
ProcAddr: FarProc;
ProvaChild: T_ProvaChild;
begin
DllHandle := LoadLibrary('ProjectDll.dll');
ProcAddr := GetProcAddress(DllHandle, 'CreateChild');
if ProcAddr <> nil then
begin
ProvaChild := ProcAddr;
ProvaChild(Application,Self,Screen);
end;
end;
end.
可是在,主程序退出时,就会出现非法操作,216 错误,
各位高手能帮我我看看吗?
'0x00fa34aa'指令引用0x01003398内存,该内存不能为"read"
Runtime Error 216 at 00fa34aa
动态库如下:
library ProjectDll;
uses
Windows,
SysUtils,
Classes,
Controls,
Forms,
UnitDll in 'UnitDll.pas' {Form1};
procedure CreateChild(ParentApplication: TApplication
ParentForm: TForm;ParentScreen:TScreen)
export
stdcall;
var
Form1: Tform1;
begin
Screen:=ParentScreen;
Application:=ParentApplication;
Form1:=TForm1.Create(ParentForm);
Form1.Caption:='Title';
Form1.Show;
end;
exports
CreateChild;
begin
end.
============================================
unit UnitDll;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
implementation
{$R *.dfm}
end.
==========================================
调用:
unit ld2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
T_ProvaChild=procedure (ParentApplication:Tapplication;ParentForm:Tform;ParentScreen:Tscreen);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
DllHandle: THandle;
ProcAddr: FarProc;
ProvaChild: T_ProvaChild;
begin
DllHandle := LoadLibrary('ProjectDll.dll');
ProcAddr := GetProcAddress(DllHandle, 'CreateChild');
if ProcAddr <> nil then
begin
ProvaChild := ProcAddr;
ProvaChild(Application,Self,Screen);
end;
end;
end.