Solved

String in Windows message

Posted on 2010-11-17
6
532 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:panJames
  • 4
6 Comments
 
LVL 19

Expert Comment

by:Thommy
ID: 34154219
0
 
LVL 24

Expert Comment

by:jimyX
ID: 34154231
You can do something like this:


Str : String;

PostMessage(MyParams.HandleToForm, WM_THREAD_COMPLETE, @Str, LInteger1);
0
 
LVL 24

Expert Comment

by:jimyX
ID: 34154285
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);
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 24

Expert Comment

by:jimyX
ID: 34154403
 Str:string;
  A : Integer;

  Str := 'test';
  A := GlobalAddAtom(Pchar(Str));
  PostMessage(MyParams.HandleToForm, WM_THREAD_COMPLETE, A, length(Str));
0
 
LVL 24

Accepted Solution

by:
jimyX earned 500 total points
ID: 34154615
This also is valid:

Str : String;

PostMessage(MyParams.HandleToForm, WM_THREAD_COMPLETE, integer(Str), length(Str));
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 34155054
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

0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi : could not find program, '...exe' 2 171
Downloading email attachments 2 73
drawing animated level bar based on numbers 3 97
Find and Replace Stream with 0s 8 62
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question