function CreateFormEx(App: TApplication; Aparent: TWinControl;
var Ahandle: Thandle): boolean; stdcall; export;
实现
function CreateFormEx(App: TApplication;Aparent: TWinControl;
var Ahandle: Thandle; var WordOptions: TWordOptions): boolean; stdcall; export;
begin
Application.Handle := App.Handle;
with TFrmNorTend.Create(App) do
begin
Result := true;
Windows.SetParent(Handle, Aparent.Handle);
Ahandle := Handle;
Show;
end;
end;
var
CurWinhandle: THandle;
调用:(动态调用)
procedure TFrmMain.loadDllForm(pointers: string);
var
DLL: THandle;
CreateFormEx: TCreateFormEx;
oldHandle: THandle;
begin
DLL := StrToInt64(pointers);
@CreateFormEx := GetProcAddress(DLL, 'CreateFormEx ');
if @CreateFormEx < > nil then
begin
oldHandle := CurWinhandle;
CreateFormEx(Application, Panel1(要显示dll窗口的panel), CurWinhandle);
closelastHand(oldHandle);
end;
end;
function TMainForm.LoadDll(DllPath, DllFunc: string): Boolean;
type
TIntFunc = function(App: TApplication; Parent:THandle):THandle; stdcall;
var
Th: THandle;
Tf: TIntFunc;
Tp: TFarProc;
begin
result := true;
Th := LoadLibrary(pchar(DllPath)); {装载DLL}
if Th > 0 then
try
Tp := GetProcAddress(Th, pchar(DllFunc));
if Tp <> nil then
begin
Tf := TIntFunc(Tp);
//Tf(application.Handle, application.Icon.Handle); {调用函数}//20100331
tf(Application, TabSheet1.Handle);
end
else application.MessageBox('函数没有找到', '提示');
finally
FreeLibrary(Th); {释放DLL}
end
else
application.MessageBox('DLL没有找到', '提示');
end;
dll form 的圖標問題,很多資料上說隻要把mainForm的application.handle傳進去給dll的applicaton就可以了
試了還是不可以,還要加icon的handle才可以
Application.Handle := App.Handle;
Application.Icon.Handle := App.Icon.Handle;