Autor Beitrag
Softchaos67
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 103

XP Prof
Delphi 7
BeitragVerfasst: Mi 17.11.04 16:32 
Hallo,
ich habe das Beispiel aus SwissDelphiCenter verwendet.
Leider kommen bei meinem Receiver nur Schrottzeichen an.
Keine Ahnung wieso.
Seht ihr hier irgendeinen Fehler?
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
const WM_OPENFORM =WM_USER+2002; //eigene Message

//Sender
procedure TForm1.SendOpenForm(FormName, Parameter: String);
var
   aCopyData :TCopyDataStruct;
   hTargetWnd :HWND;
   str :String;
begin
   with aCopyData do begin
       str := FormName+';'+Parameter;
      dwData := 0;
      cbData := StrLen(PChar(str))+1;
      lpData := PChar(str);
      hTargetWnd := FindWindowEx(0,0,nil,PChar('WM_OPENFORM_APP'));
      if hTargetWnd<>0 then SendMessage(hTargetWnd,WM_OPENFORM,Longint(Handle),Longint(@aCopyData));
   end;
end;

// Empfänger
procedure WMOpenForm(var Msg :TWMCopyData);message WM_OPENFORM;
.
.
.
procedure TForm2.WMOpenForm(var Msg: TWMCopyData);
var
   sText :array[0..99]of Char;
   str :String;
begin
  StrLCopy(sText, Msg.CopyDataStruct.lpData, Msg.CopyDataStruct.cbData);
  ShowMessage(sText);
end;


In ShowMessage kommen nur seltsame Sonderzeichen an.
Woran könnte das liegen?
Gruss
Matthias
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Mi 17.11.04 17:24 
Hab deinen Code jetzt nur mal schnell überflogen... Aber in welcher Zeile sendest du die WM_COPYDATA Nachricht an dein Fenster? Ohne diese Nachricht weiß Windows doch nicht, das es die Daten prozessübergreifend speichern muss.

_________________
Ciao, Sprint.
Softchaos67 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 103

XP Prof
Delphi 7
BeitragVerfasst: Do 18.11.04 09:39 
Hallo,
ich habe eben eine eigene Message verwendet. Funktioniert das nur mit WM_COPYDATA?
Dann muss ich das nochmal überarbeiten.
Gruss
Matthias
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 18.11.04 10:54 
Also bei mir funktioniert es so: www.luckie-online.de...ges/WM_COPYDATA.html
Sender:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
type
  TMyRecord = packed record
    b: Boolean;
    s: string[255];
  end;
  PMyRecord = ^TMyRecord;

procedure TForm1.Button1Click(Sender: TObject);
var
  MyRecord: PMyRecord;
  cds: TCopyDataStruct;
  hWnd: THandle;
begin
  GetMem(MyRecord, sizeof(TMyRecord));
  try
    MyRecord.b := True;
    MyRecord.s := 'Hello world';
    cds.dwData := 0;
    cds.cbData := sizeof(TMyRecord);
    cds.lpData := MyRecord;
    hWnd := FindWindow(nil, 'Receiver');
    SendMessage(hWnd, WM_COPYDATA, Handle, Integer(@cds));
  finally
    FreeMem(MyRecord, sizeof(TMyRecord));
  end;
end;

Empfänger:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
type
  TForm1 = class(TForm)
    CheckBox1: TCheckBox;
    Edit1: TEdit;
  private
    { Private declarations }
  public
    { Public declarations }
    procedure WMCOPYDATA(var msg: TWMCopyData); message WM_COPYDATA;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

type
  TMyRecord = packed record
    b: Boolean;
    s: string[255];
  end;
  PMyRecord = ^TMyRecord;

procedure TForm1.WMCOPYDATA(var msg: TWMCopyData);
var
  MyRecord: PMyRecord;
  b: Boolean;
  s: String[255];
begin
  b := PMyRecord(msg.CopyDataStruct.lpData)^.b;
  s := PMyRecord(msg.CopyDataStruct.lpData)^.s;
  CheckBox1.Checked := b;
  Edit1.Text := s;
end;

Das habe ich doch vorhin schon mal gepostet. :gruebel:
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 18.11.04 11:22 
Softchaos67 hat folgendes geschrieben:
ich habe eben eine eigene Message verwendet. Funktioniert das nur mit WM_COPYDATA?
Dann muss ich das nochmal überarbeiten.

Ja, das geht nur mit WM_COPYDATA, da ja Prozessgrenzen überwunden werden und die Pointer daher nicht mehr gültig sind. Bei WM_COPYDATA mappt Windows die Daten automatisch zwischen den Prozessen...

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
Softchaos67 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 103

XP Prof
Delphi 7
BeitragVerfasst: Mo 22.11.04 13:06 
Ja, danke.
Mit WM_COPYDATA funzt es einwandfrei.
Ich wollte halt eine eigene Message verwenden.
Ist so aber auch in Ordnung.