Autor Beitrag
hazelnoot
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Di 08.08.06 08:29 
hallo!

ich hab eine kleine frage und zwar ich hab einen TMessage datentyp mit dem namen msg. Ich moechte mir nun aus diesem msg den Datentyp TStrings wieder heraushohlen!

wie geht das? irgendwas mit lparam aber genau weis ich das nun auch nich!

folgendes hab ich schon:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
procedure TTestThread.WndProc(var msg : TMessage);
var
  buffer:String;
begin
  buffer := PString(msg.lParam)^;

  //PChar(PCopyDataStruct(msg.lParam)^.lpData)
  Writeln(buffer);
end;

aber da kommt immer eine speicherzugriffsfehlermeldung

danke schonmal im vorraus

mfg hazelnoot!
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 08.08.06 14:14 
Wie speicherst Du den String in den LParam der Message?
Geht die Nachricht über Prozess-Grenzen hinweg?

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
kotzekocher
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Mi 09.08.06 12:03 
Was jetzt? Tstrings oder einfach nur String? Das ist schon ein Unterschied. Bei nem einfachen String würde ich einfach in PChar umwandeln, dann abschicken und hinterher wieder zurück nach String.

mfg
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Mi 09.08.06 18:13 
Hab genau das selbe Problem.
user profile iconkotzekocher hat folgendes geschrieben:
Bei nem einfachen String würde ich einfach in PChar umwandeln, dann abschicken und hinterher wieder zurück nach String.

SendMessage verlangt als LParam einen Integer. Soll ich da etwa so schreiben?:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var
  S: String;
begin
  S := 'blub';
  SendMessage(Form1.Handle, WM_USER+1, 0, Integer(PChar(S)));
end;

Da gibts wieder ne Zugriffsverletzung :(

EDIT: String ist bei mir gemeint, kein TStrings
tommie-lie
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 4373

Ubuntu 7.10 "Gutsy Gibbon"

BeitragVerfasst: Mi 09.08.06 18:59 
user profile iconChryzler hat folgendes geschrieben:
Soll ich da etwa so schreiben?:
ausblenden Delphi-Quelltext
1:
Integer(PChar(S))					
Ja.

Chryzler hat folgendes geschrieben:
Da gibts wieder ne Zugriffsverletzung :(
BenBEs Frage: Über Prozessgrenzen hinweg? Wie liest du den Wert aus? Wie gehst du sicher, daß S durch die Compiler Magic nicht wieder zerstört wird?

_________________
Your computer is designed to become slower and more unreliable over time, so you have to upgrade. But if you'd like some false hope, I can tell you how to defragment your disk. - Dilbert
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Mi 09.08.06 19:11 
Ich hab in einer DLL nen Text (PWideChar), den ich per SendMessage zu einer anderen Anwendung schicken will, die den Text dann ausgibt. In der DLL wandle ich den PWideChar in einen String um (WideCharToString), verschick in dann, und im Hautprogramm mach ich wieder nen String draus.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 10.08.06 17:53 
Über Prozessgrenzen hinweg musst Du zwingend die Nachricht WM_COPYDATA nehmen, wenn Du Daten senden willst, weil sich dabei die Zeiger ändern. windows übersetzt diese dann für dich bereits richtig.

Weiterhin musst Du Typen-Konformität beachten: Wenn Du einen PWideChar hast, musst Du WideString oder PWideString zum Senden nutzen; ein normaler PChar ist ANSI und schneidet damit nach dem ersten Zeichen ab.

Alternativ kannst Du Dir mal die AddAtomW-API-Funktion anschauen. Die könnte Dir helfen, da damit Strings global gespeichert werden können. Die Speicher-Verwaltung musst Du dann aber selbst machen.

Ansonsten empfehle ich Dir mal eine Suche nach IPC (Inter Process Communication), wo solche Dinge auch erklärt sind.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Do 10.08.06 19:26 
Ich habs mit WM_COPYDATA gelöst. THX! :zustimm:
@hazelnoot: Hier ist ein Beispiel zur Verwendung von WM_COPYDATA