delphi dll form

dll 接口函数申明
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;



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值