Solved

String in Windows message

Posted on 2010-11-17
6
530 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
Comment Utility
0
 
LVL 24

Expert Comment

by:jimyX
Comment Utility
You can do something like this:


Str : String;

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

Expert Comment

by:jimyX
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 24

Expert Comment

by:jimyX
Comment Utility
 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
Comment Utility
This also is valid:

Str : String;

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

Expert Comment

by:Russell Libby
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now