Solved

String in Windows message

Posted on 2010-11-17
6
536 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 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