AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

DLL Form in Main Programm anzeigen?

Ein Thema von napsterxx · begonnen am 24. Mai 2007 · letzter Beitrag vom 25. Mai 2007
Antwort Antwort
Benutzerbild von RWarnecke
RWarnecke

Registriert seit: 31. Dez 2004
Ort: Stuttgart
4.408 Beiträge
 
Delphi XE8 Enterprise
 
#1

Re: DLL Form in Main Programm anzeigen?

  Alt 24. Mai 2007, 22:09
Das ist garnicht so einfach. In der DLL muss folgendes stehen :
Delphi-Quellcode:
library config;

uses
  SysUtils,
  Classes,
  Windows,
  Forms,
  Controls,
  ExtCtrls,
  ConfigurationMainUnit in 'ConfigurationMainUnit.pas{ConfigurationMain},
  dll_unit in 'dll_unit.pas';

{$R *.res}

procedure configuration(appHandle: THandle); stdcall;
begin
  if appHandle = 0 then apphandle := GetActiveWindow;
  Application.Handle := appHandle;
  try
    with TConfigurationMain.Create(Application) Do
      try
        ShowModal
      finally
        Free;
      end
  except
    On E: Exception Do Application.HandleException(E);
  end;
  Application.Handle := 0;
end;

exports
  configuration;

begin

end.
Die ConfigurationMainUnit.pas ist eine ganz einfache Unit mit einem Formular. Dieses kannst Du ganz normal händeln, wie jedes andere Formular auch.
In der DLLunit.pas habe ich dann folgendes stehen :
Delphi-Quellcode:
unit dll_unit;

interface
procedure configuration(appHandle: THandle); stdcall;

implementation

procedure configuration(appHandle: THandle); stdcall; external 'config.dll';

end.
Und in der MainForm.Unit habe ich dann folgendes stehen um das Formualar aus der ConfigurationMainUnit.pas aufzurufen :
Delphi-Quellcode:
uses
  dll_unit;

type
  TConfigWindow = procedure(appHandle: THandle); stdcall;

procedure TMainControl.Configuration_btnClick(Sender: TObject);
var
  hDLL : THandle;
  ConfigWindow : TConfigWindow;
begin
  hDLL := LoadLibrary(PChar(ExtractFilePath(ParamStr(0))+'config.dll'));
  if hDLL <> 0 then begin
    try
      ConfigWindow := GetProcAddress(hDLL, 'configuration');
      ConfigWindow(Application.Handle);
    finally
      FreeLibrary(hDLL);
    end;
  end;
end;

end.
So habe ich das gemacht mal für ein Programm. Ich hoffe es hilft dir weiter.
Rolf Warnecke
App4Mission
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:11 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz