Announcement

Collapse
No announcement yet.

Messages zw. aufrufendem Programm und Dll oder anderem Programm

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Messages zw. aufrufendem Programm und Dll oder anderem Programm

    Wie kann ich einer Dll einen Text (nat. PChar)für Titelleiste oder ähnlichem übergeben und wie bekomme ich von selbiger einen Text zurück?
    Funktioniert das auch mit einem Programm, welches aus meiner Anwendung gestartet wird (ebenfalls selbst programmiert).
    Ich programmiere mit Delphi 4.

  • #2
    Hallo,

    wenn das Fensterhandle bekannt ist, kann über die API-Funktion <b>SetWindowText</b> die Fensterbeschriftung geändert werden.

    Universeller (weil flexibler) ist das Verschicken der <b>WM_COPYDATA</b>-Botschaft, da auf diesem Weg beliebige Datenstrukturen (also auch Text) anwendungsübergreifend ausgetauscht werden können

    Comment


    • #3
      Ich will Daten zwischen meinem Programm und dynamisch geladener DLL austauschen.
      Nach langem stöbern im Net bin ich auf folgende Komponente gestossen:
      TBrdcast component for delphi 3 v1.0 *
      Jean-Pierre Linteau ([email protected]) *
      *
      This component is used to easily broadcast (send) and receive *
      message to/from other applications. Messages contains 3 parts : *
      Received shortstring, received double and received key. *

      Mit der Einbindung in Delphi4 hatte ich keine Probleme, sie funktioniert auch hervorragend, nur wird beim senden auch der Internet-Explorer gestartet. Das war für mich leider zuviel und seitdem bin ich am basteln. Als Programmier-Neuling (~1Jahr)habe ich überraschend wenig Probleme mich in Delphi-Pascal zurechtzufinden, aber API.......

      ich setze mal den Inhalt der Pas-Datei mit hinzu, vielleicht fällt Ihnen etwas auf, was den Internet-Explorer startet und man kann es aus der Komponente entfernen oder richtigstellen. Möglicherweise liegt es am IE5, der ja bei Erstellung der Komponente noch nicht auf dem Markt war::

      //------------------------------------------------------------------*
      // TBrdcast component for delphi 3 v1.0 *
      // Jean-Pierre Linteau ([email protected]) *
      // *
      // This component is used to easily broadcast (send) and receive *
      // message to/from other applications. Messages contains 3 parts : *
      // Received shortstring, received double and received key. *
      //------------------------------------------------------------------*
      // Properties: *
      // InKey : The value of the key received (integer) *
      // InData : double received *
      // InText : Shortstring received *
      // Key : The value of the key to send (integer) *
      // OutText : the shortstring to send *
      // OutData : the data to send *
      // EnableInput : enable reception of message *
      // EnableOutput : enable sending of message *
      // *
      // Method : *
      // Broadcast : This will send the stuff to other apps. *
      // *
      // Events : *
      // OnBroadcastMsg : fire when a message is received *
      // *
      // Note: *
      // The key value (an integer) could be use to "secure" communica- *
      // between processes. Setting the receiver to verify the value *
      // transmitted. *
      //------------------------------------------------------------------*
      // Copyright 1997 : Jean-Pierre Linteau *
      // *
      // LEGAL : This component is FREEWARE. I make no guarantees, *
      // or warranties of any kind, you USE IT AT YOUR OWN RISK. *
      // *
      // Can be freely used abused and distributed in commercial and *
      // private environments, provided this notice is not modified in *
      // any way. *
      //------------------------------------------------------------------*
      // History : *
      // *
      &#10

      Comment


      • #4
        der Rest1:
        *
        // v 1.0 : Initial release (april 98 ) *
        // *
        // wish list : replacing shortstring with string... *
        // *
        //------------------------------------------------------------------*

        unit Brdcast;

        interface

        uses
        Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

        type
        Tlisten = procedure(inText: shortstring ; inData : double ; inKey :integer)
        of object;

        TMsgPack = record
        texte : shortstring;
        data : double;
        end;

        TBroadcast = class(TComponent)

        private
        FOnBroadcastMsg : Tlisten;
        FWinHandle : HWND;
        FKey : DWORD;
        FenableOutput, FenableInput : boolean;
        FOutText : shortstring;
        FOutData : double;
        t : TcopyDataStruct;
        dataPack, InMsg : ^TMsgPack;
        precv : pcopydataStruct;
        protected
        Constructor Create(AOwner: TComponent); Override;
        Destructor Destroy; Override;
        procedure WndProc(var Msg : Tmessage);
        public
        InText : shortstring;
        InData : double;
        InKey : integer;
        procedure Broadcast;
        published
        property Key : DWORD read Fkey write Fkey;
        property EnableInput : boolean read FEnableInput write FEnableInput;
        property EnableOutput : boolean read FEnableOutput write FEnableOutput;
        property OutText : shortString read FOutText write FOutText;
        property OutData : double read FOutData write FOutData;
        property OnBroadcastMsg: Tlisten read fOnBroadcastMsg write fOnBroadcastMsg;
        end;

        procedure Register;

        implementation

        Constructor TBroadcast.Create(AOwner: TComponent);
        begin
        inherited Create(AOwner);
        FWinHandle := AllocateHWND(WndProc);
        end;

        procedure TBroadcast.Broadcast;
        begin
        if FenableOutput then
        begin
        new(datapack);
        datapack^.texte:= FOutText;
        datapack^.data:= FOutData;
        t.dwData:= Fkey;
        t.lpData:= datapack;
        t.cbData:= sizeOf(datapack^);
        SendMessage(wnd_broadcast,WM_COPYDATA,FWinHandle,L ongInt(@t));
        end;
        end;

        procedure TBroadcast.WndProc(var msg: TMessage);
        begin
        if (enableInput AND (msg.msg = WM_COPYDATA)) then
        begin
        precv := pCopyDataStruct(msg.Lparam);
        inMsg:= precv.lpdata;
        inText:= inMsg^.texte;
        inData:= inMsg^.data;
        inKEY:= precv.dwData;
        if assigned(FonBroadcastMsg) then FonBroadcastMsg(inText,inData,inkey);
        end;
        //msg.Result:= DefWindowProc(FwinHandle,msg.msg,msg.wParam,Msg.lp aram);
        end;

        Destructor TBroadcast.Destroy;
        begin
        DeallocateHWnd(FWinHandle);
        inherited Destroy;
        end;

        procedure Register;
        begin
        RegisterComponents('System', [TBroadcast]);
        end;

        end.

        Ich habe auch schon dem Autor gemailt, aber noch nichts bekommen!!

        Viel Glück und schon mal Danke im Voraus
        CIAO Arn

        Comment


        • #5
          Hallo,

          die <b>WM_COPYDATA</b>-Botschaft wird via Broadcast an alle (!) Top-Level-Fenster geschickt. Das "magische" Fenster-Handle wnd_broadcast entspricht HWND_BROADCAST:
          <pre>
          SendMessage(wnd_broadcast,WM_COPYDATA,FWinHandle,L ongInt(@t));
          </pre>
          Somit muss man zwangsläufig damit rechnen, das andere Anwendungen, die ebenfalls WM_COPYDATA nutzen, allergisch reagieren. Um diesen Effekt zu beseitigen, muss nur der Empfänger der Botschaft präzisiert werden. Anstelle von wnd_broadcast ist das konkrete Fensterhandle der eigenen Anwendung einzusetzen

          Comment


          • #6
            Dann müßte es ja funktionieren, wenn ich die Komponente so abändere, dass sie für WM_CopyData Variablen annimmt. Beim eisetzen der Komponente in der Anwendung dann die Variable benenne, also das entsprechende Fensterhandle angebe.
            Mal schauen <b>ob</b> und <b>wie</b> ich das hinkriege. Es hilft mir auf jedenfall weiter.
            <b><font size="+3">Danke</font></b>
            Wenn ichs geschafft habe, melde ich mich wieder.
            Tschüss, Arn

            Comment

            Working...
            X