200分!真正的高手帮帮忙,DLL中的cli窗口调用到主MDI窗口的panel中显示(200分)

  • 主题发起人 arisecloud
  • 开始时间
A

arisecloud

Unregistered / Unconfirmed
GUEST, unregistred user!
真正的高手帮帮忙DLL中的cli窗口调用到主MDI窗口的panel中显示
每次调用后,显示正常,就是在关闭cli窗口后出现错误提示
''Access Violation at address 77e0e603 in module 'user32.dll'. read of address 00000023



dll文件
///////////////
library dllset;
uses
Windows,
...{这里有很多单元,跟这里没关系}
Dialogs,
f1 in 'f1.pas' {Form1};
{$R *.res}
Function showset(ParentApplication: TApplication; ParentForm: TForm):hwnd; export; stdcall;
var
Form1: TForm1;
DllProc: Pointer; { Called whenever DLL entry point is called }

begin
Application:=ParentApplication;
Form1:=TForm1.Create(ParentForm);
Form1.MyParentForm:=ParentForm;
Form1.MyParentApplication:=ParentApplication;
Result:=Form1.Handle;
end;
procedure DLLUnloadProc(Reason: Integer); register;
begin
if Reason = DLL_PROCESS_DETACH then Application:=DllApplication;
end;
exports
showset;
begin
DllApplication:=Application;
DLLProc := @DLLUnloadProc;
end.
////////////////////
f1.pas文件
//////////////
unit f1;
interface
uses
Windows, .................;
type
TForm1 = class(TForm)
Button12: TButton;
..........

procedure FormClose(Sender: TObject; var Action: TCloseAction);
..............
private
{ Private declarations }
public
{ Public declarations }
MyParentForm: TForm;
MyParentApplication: TApplication;
end;
var
DllApplication: TApplication;
implementation

{$R *.dfm}

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:=caFree;
end;
end.
///////////////////////////////////////
调用DLL主文件
///////////////////////
unit main;

interface

uses
Windows,...;

type
TForm1 = class(TForm)
Panel1: TPanel;
procedure ToolButton6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }

end;

T_ProvaChild = Function (ParentApplication: TApplication;ParentForm: TForm):hwnd; stdcall; // ParentForm: TForm

var
Form1: TForm1;
procedure aaa(ahandle : hwnd);
implementation
{$R *.dfm}
procedure aaa(ahandle : hwnd);
begin
setparent(Ahandle,form1.Panel1.handle);
end;
procedure TForm1.ToolButton6Click(Sender: TObject);
var
DllHandle: THandle;
ProcAddr: FarProc;
ProvaChild: T_ProvaChild;
ahandle,phwd :hwnd;
begin
DllHandle := LoadLibrary('dll/setdb/dllset.dll');
ProcAddr := GetProcAddress(DllHandle, 'showset');
if ProcAddr <> nil then
begin
ProvaChild := ProcAddr;
Ahandle:=ProvaChild(Application,Self); // Panel1.Handle
aaa(Ahandle);
Showwindow(Ahandle,sw_shownormal);
end;
end;
end.
 
顶部