panJames
asked on
String in Windows message
Hello experts
I know how to send message to the system.
It looks like:
PostMessage(MyParams.Handl eToForm, WM_THREAD_COMPLETE, LInteger0,
LInteger1);
Where I have handle to the form with procedure, name of the procedure and two integer parameters.
Question:
How can I pass parameter of String type?
Thank you
panJames
I know how to send message to the system.
It looks like:
PostMessage(MyParams.Handl
LInteger1);
Where I have handle to the form with procedure, name of the procedure and two integer parameters.
Question:
How can I pass parameter of String type?
Thank you
panJames
You can do something like this:
Str : String;
PostMessage(MyParams.Handl eToForm, WM_THREAD_COMPLETE, @Str, LInteger1);
Str : String;
PostMessage(MyParams.Handl
That one will not work. But this will:
Str:string;
A : Integer;
Str := 'test';
A := GlobalAddAtom(Pchar(Str));
PostMessage(MyParams.Handl eToForm, WM_THREAD_COMPLETE, iAtom, LInteger1);
Str:string;
A : Integer;
Str := 'test';
A := GlobalAddAtom(Pchar(Str));
PostMessage(MyParams.Handl
Str:string;
A : Integer;
Str := 'test';
A := GlobalAddAtom(Pchar(Str));
PostMessage(MyParams.Handl eToForm, WM_THREAD_COMPLETE, A, length(Str));
A : Integer;
Str := 'test';
A := GlobalAddAtom(Pchar(Str));
PostMessage(MyParams.Handl
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Just keep the following rules in mind when passing strings (or any pointers, eg objects, etc):
- If you PostMessage with a string, you have to ensure the pointer (string) does not go out of scope before the window processes the message. Not a recommended way of sending strings.
- If you are SendMessage(..) ing strings/pointers, you can do so without issues as long as the window handling the message exists within the process.
- If you are SendMessage(..) ing strings/pointers to a window that exists in another process, then you will need to use some form of IPC (WM_COPYDATA, atoms, etc) as the pointer you are passing needs to be mapped into the process space of the window handling the message.
Russell
- If you PostMessage with a string, you have to ensure the pointer (string) does not go out of scope before the window processes the message. Not a recommended way of sending strings.
- If you are SendMessage(..) ing strings/pointers, you can do so without issues as long as the window handling the message exists within the process.
- If you are SendMessage(..) ing strings/pointers to a window that exists in another process, then you will need to use some form of IPC (WM_COPYDATA, atoms, etc) as the pointer you are passing needs to be mapped into the process space of the window handling the message.
Russell
http://about-delphi.blogspot.com/2008/08/message-handling-in-delphi.html