5,392
社区成员
发帖
与我相关
我的任务
分享
uses
Sharemem,
SysUtils,
Forms,
Messages,
Windows,
Classes,
ActiveX,
comObj,
untPRJ_1_Setup in 'untPRJ_1_Setup.pas' {frmPRJ_1_Setup},
udmData in '..\Common\udmData.pas' {dmData: TDataModule},
untCommon in '..\Common\untCommon.pas',
AES in '..\Common\AES.pas',
ElAES in '..\Common\ElAES.pas';
{$R *.res}
var
DllApp: TApplication;
DLLScreen: TScreen;
TheForm: TForm;
TheClass: TPersistentClass;
procedure RunDLL(DLLName, FormName, FormCaption: string;
APP: TApplication; SC: TScreen) stdcall;
begin
Application := App;
Screen := SC;
RegisterClasses([TfrmPRJ_1_Setup]);
TheClass := GetClass('T' + FormName);
if (TheClass <> nil) and TheClass.InheritsFrom(TForm) then
begin
TheForm := TForm(TheClass.Create).Create(Application);
//TheForm := TfrmPRJ_1_Setup.Create(Application, FormCaption);
//TheForm.Show;
try
TheForm.ShowModal;
finally
FreeAndNil(TheForm);
//TheForm.Free;
end;
end;
end;
procedure DLLUnloadProc(dwReason: Dword);
begin
case dwReason of
//DLL_PROCESS_ATTACH, DLL_THREAD_ATTACH:
//CoInitialize(nil);
DLL_PROCESS_DETACH:
begin
//CoUninitialize;
Application := DLLApp;
Screen := DLLScreen;
if TheForm <> nil then
FreeAndNil(TheForm);
SendMessage(Application.Handle, WM_CLOSE, 0, 0);
FreeLibrary(Application.Handle);
end;
DLL_THREAD_DETACH:
//CoUninitialize;
end;
end;
exports
RunDLL;
begin
DLLApp := Application;
DLLScreen := Screen;
DLLProc := @DLLUnloadProc;
DLLUnloadProc(DLL_PROCESS_ATTACH);
end.
type
TRunDLL = procedure(DLLName, FormName, FormCaption: string;
Application: TApplication; Screen: TScreen); stdcall;
procedure TfrmMain.btnPRJ_1_SetupClick(Sender: TObject);
begin
RunDLLForm('PRJ_1_Setup.dll', 'frmPRJ_1_Setup', 'ノ靹テ', Application, Screen);
end;
procedure TfrmMain.RunDLLForm(DLLName, FormName, FormCaption: string;
APP: TApplication; SC: TScreen) stdcall;
var
GetDllHWND: HWND;
RunDLL: TRunDLL;
begin
GetDllHWND := LoadLibrary(PChar(DllName));
if GetDllHWND = 0 then
begin
MessageBox(0, PChar('テサモミユメオステ鉸ェ '+DLLName+' オトホトシ」ャヌ・キネマウフミヌキ・訒。'),
'シモヤリDLLホトシハァーワ', MB_OK);
Exit;
end;
try
@RunDLL := GetProcAddress(GetDllHWND, 'RunDLL');
if Assigned(@RunDLL) then
begin
try
RunDLL(UpperCase(Trim(DLLName)), UpperCase(Trim(FormName)),
FormCaption, APP, SC);
except
raise Exception.Create('T' + FormName + 'イサエ贇レ」。');
end;
end;
finally
FreeLibrary(GetDllHWND);
end;
end;
library Setting;
uses
Sharemem,
SysUtils,
Forms,
Messages,
Windows,
Classes,
ActiveX,
comObj,
UntSetting in '..\Form\UntSetting.pas' { FrmSetting } ;
{$R *.res}
var
DllApp: TApplication;
DllScr: TScreen;
TheForm: TForm;
TheClass: TPersistentClass;
procedure OpenMe(Parent: THandle; DllName, FrmName: string; App: TApplication;
Scr: TScreen); stdcall;
begin
Application := App; //问题在这
Screen := Scr;
RegisterClasses([TFrmSetting]);
TheClass := GetClass('T' + FrmName);
if (TheClass <> nil) and TheClass.InheritsFrom(TForm) then
begin
//Application.Handle := Parent;
TheForm := TForm(TheClass.Create).Create(Application);
try
TheForm.ShowModal;
finally
FreeAndNil(TheForm);
end;
end;
end;
procedure DLLUnloadProc(dwReason: Dword);
begin
case dwReason of
DLL_PROCESS_ATTACH, DLL_THREAD_ATTACH:
begin
{ 保存Dll初始的Application對象 }
DllApp := Application;
{ 保存Dll初始的Screen對象 }
DllScr := Screen;
// CoInitialize(nil);
end;
DLL_PROCESS_DETACH:
begin
{ 還原Dll的Application對象 }
Application := DllApp;
{ 還原Dll的Screen對象 }
Screen := DllScr;
if TheForm <> nil then
FreeAndNil(TheForm);
FreeLibrary(Application.Handle);
// CoUninitialize;
end;
DLL_THREAD_DETACH:
begin
CoUninitialize;
end;
end;
end;
exports OpenMe;
begin
DllProc := @DLLUnloadProc;
DLLUnloadProc(DLL_PROCESS_ATTACH);
end.
procedure TForm1.Button1Click(Sender: TObject);
begin
RunDLLForm(Pchar('PRJ_1_Setup.dll'), Pchar('frmPRJ_1_Setup'), Pchar(''), Application, Screen);
RunDLL(Pchar('PRJ_1_Setup.dll'), Pchar('frmPRJ_1_Setup'), Pchar(''), Application, Screen);
end;
procedure RunDLL(DLLName, FormName, FormCaption: Pchar; APP: TApplication; SC: TScreen); stdcall; external 'PRJ_1_Setup.dll';
procedure TForm1.Button1Click(Sender: TObject);
begin
//RunDLLForm(Pchar('PRJ_1_Setup.dll'), Pchar('frmPRJ_1_Setup'), Pchar(''), Application, Screen);
RunDLL(Pchar('PRJ_1_Setup.dll'), Pchar('frmPRJ_1_Setup'), Pchar(''), Application, Screen);
end;