T
the19hells
Unregistered / Unconfirmed
GUEST, unregistred user!
因本人刚学,估计问题不少,所以先送50分,先谢谢了各位。
问题如下,我用以下方法在主窗口中调用子窗口
procedure TMainForm.O_rsExecute(Sender: TObject);
var
DllHandle: THandle;
ProcAddr: FarProc;
ProvaChild: T_ProvaChild;
Mutex:THandle;
begin
Mutex:=CreateMutex(NIL,True,'TOFrom_rs');
IF GetLastError=ERROR_ALREADY_EXISTS THEN
begin
MessageBox(0,'已有一个窗体运行!','提示!',mb_OK);
ReleaseMutex(Mutex);
end
else begin
DllHandle := LoadLibrary('o.dll');
try
ProcAddr := GetProcAddress(DllHandle, 'Createform');
if ProcAddr <> nil then
begin
ProvaChild := ProcAddr;
ProvaChild(Application,Self);
Speedbutton1.Enabled :=False;
end;
except
FreeLibrary(DllHandle);
end;
end;
end;
以下为DLL中的函数:
library o;
uses
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
Activex,
O_rs in 'O_rs.pas' {OForm_rs};
var
DllApplication: TApplication;
procedure Createform(ParentApplication:TApplication;ParentForm:TForm); export; stdcall;
var
OForm_rs: TOForm_rs;
begin
Application:=ParentApplication;
OForm_rs:=TOForm_rs.Create(ParentForm);
OForm_rs.MyParentForm:=ParentForm;
OForm_rs.MyParentApplication:=ParentApplication;
OForm_rs.Show;
end;
procedure DLLUnloadProc(Reason: Integer); register;
begin
if Reason = DLL_PROCESS_DETACH then Application:=DllApplication;
end;
Exports
Createform name 'Createform';
{$R *.res}
begin
CoInitialize(Nil);
DllApplication:=Application;
DLLProc := @DLLUnloadProc;
end.
运行时发现,只在第一次执行时才可以调出子窗口,关闭子窗口后再执行会提示‘已经存在’,但是不关闭子窗口执行调用时也能提示‘已经存在’,反复不得其解,望赐教!谢谢!
问题如下,我用以下方法在主窗口中调用子窗口
procedure TMainForm.O_rsExecute(Sender: TObject);
var
DllHandle: THandle;
ProcAddr: FarProc;
ProvaChild: T_ProvaChild;
Mutex:THandle;
begin
Mutex:=CreateMutex(NIL,True,'TOFrom_rs');
IF GetLastError=ERROR_ALREADY_EXISTS THEN
begin
MessageBox(0,'已有一个窗体运行!','提示!',mb_OK);
ReleaseMutex(Mutex);
end
else begin
DllHandle := LoadLibrary('o.dll');
try
ProcAddr := GetProcAddress(DllHandle, 'Createform');
if ProcAddr <> nil then
begin
ProvaChild := ProcAddr;
ProvaChild(Application,Self);
Speedbutton1.Enabled :=False;
end;
except
FreeLibrary(DllHandle);
end;
end;
end;
以下为DLL中的函数:
library o;
uses
Windows,
Messages,
SysUtils,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
Activex,
O_rs in 'O_rs.pas' {OForm_rs};
var
DllApplication: TApplication;
procedure Createform(ParentApplication:TApplication;ParentForm:TForm); export; stdcall;
var
OForm_rs: TOForm_rs;
begin
Application:=ParentApplication;
OForm_rs:=TOForm_rs.Create(ParentForm);
OForm_rs.MyParentForm:=ParentForm;
OForm_rs.MyParentApplication:=ParentApplication;
OForm_rs.Show;
end;
procedure DLLUnloadProc(Reason: Integer); register;
begin
if Reason = DLL_PROCESS_DETACH then Application:=DllApplication;
end;
Exports
Createform name 'Createform';
{$R *.res}
begin
CoInitialize(Nil);
DllApplication:=Application;
DLLProc := @DLLUnloadProc;
end.
运行时发现,只在第一次执行时才可以调出子窗口,关闭子窗口后再执行会提示‘已经存在’,但是不关闭子窗口执行调用时也能提示‘已经存在’,反复不得其解,望赐教!谢谢!