Link to home
Start Free TrialLog in
Avatar of panJames
panJames

asked on

String in Windows message

Hello experts

I know how to send message to the system.
It looks like:

PostMessage(MyParams.HandleToForm, 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
Avatar of Thommy
Thommy
Flag of Germany image

Avatar of jimyX
jimyX

You can do something like this:


Str : String;

PostMessage(MyParams.HandleToForm, WM_THREAD_COMPLETE, @Str, LInteger1);
That one will not work. But this will:

  Str:string;
  A : Integer;

  Str := 'test';
  A := GlobalAddAtom(Pchar(Str));
  PostMessage(MyParams.HandleToForm, WM_THREAD_COMPLETE, iAtom, LInteger1);
 Str:string;
  A : Integer;

  Str := 'test';
  A := GlobalAddAtom(Pchar(Str));
  PostMessage(MyParams.HandleToForm, WM_THREAD_COMPLETE, A, length(Str));
ASKER CERTIFIED SOLUTION
Avatar of jimyX
jimyX

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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