Einzelnen Beitrag anzeigen

CocoPops
(Gast)

n/a Beiträge
 
#1

WMCopyData in Konsolenanwendung

  Alt 2. Apr 2014, 16:43
Gemeinde.

Ich probiere mich momentan ein wenig mit Konsolenanwendungen und WMCopyData herum.
Ich nutzte WMCopyData schon sehr sehr häufig zwischen zwei VCL-Programmen und es funktioniert super.
Aber VCL > Konsole, das will nicht so wie ich gerne hätte.

Ich gehe so vor.

Ich ändere im Konsolenprogramm den Fenstertitel:
SetConsoleTitle(PWideChar('TTestWindow'));

Dann erstelle ich mir eine kleine Klasse im Konsolenprogramm:
Delphi-Quellcode:
type
 TProcs = class
 private
  procedure WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;
 end;
Und schließlich WMCopyData:
Delphi-Quellcode:
procedure TProcs.WMCopyData(var Msg: TWMCopyData);
var
 s: string;
begin
 s := string(PChar(Msg.CopyDataStruct.lpData));

 WriteLn(s);
end;
Das Senden aus dem VCL-Programm heraus sieh so aus und das Fensterhandle der Konsole wird auch gefunden (showmessage):
Delphi-Quellcode:
var
 hExisting: THandle;
 pName: PChar;
 aCopyData: TCopyDataStruct;
begin
 hExisting := FindWindow(nil, 'TTestWindow');

 if hExisting <> 0 then
  begin
   showmessage('TTest wurde gefunden!');
   
   with aCopyData do
    begin
     pName := PWideChar('Hallo Konsole!');
     dwData := 0;
     cbData := (StrLen(pName) + 1) * SizeOf(Char);
     lpData := pName;
    end;

   SendMessage(hExisting, WM_COPYDATA, 0, LongInt(@aCopyData));
  end;
Es wird erfolgreich SendMessage ausgeführt. Aber ich schaffe es nicht ganz korrekt, diese Message in der Konsole pr WMCopyData-Prozedur aufzufangen.

WO ist der Fehler?
  Mit Zitat antworten Zitat