Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Message que question...

Posted on 1999-07-22
Medium Priority
Last Modified: 2010-04-04
Hi everyone...

I would like to know if it is possible to send a string between programs... The TMsg structure only allows me to send two integers along with the message (lParam & wParam).Can I create my "own" message structure, or am I bound to this format? I could use a shared memory area and only transmit the handle and size, but I would like to use a more "elegant" way, if all possible. Any comments are welcome :-)

Thanks, Car...
Question by:Cariarer
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

Author Comment

ID: 1390464
Edited text of question.
LVL 10

Expert Comment

ID: 1390465
Car, you won't come around the shared memory area as you want obviously send the string to another process. Usually different processes cannot access memory of each other.

Ciao, Mike

Expert Comment

ID: 1390466
The message structure can not be changed. Actually message structure members are used as function parameters, so changing (enlarging) message structure will have no effect.
You can only share string between two applications if the string located in shared memory. This can be done using GlobalAlloc and sending the memory handler received from GlobalAlloc..

You can also pass the string using clipboard.

Another possibility is using global atom table. This restricts string length (upto 255 characters) and puts some restrictions on string contents (atom names mus be unique, but atoms have usage counter so it's OK).
To use this approach You create an atom using
and then send received value

CustomMsg is id for Custom Window Message, see Q.10184790 there is detailed explanation of implementing custom message.

In receiver application the string can be accessed by GlobalGetAtomName function (see Win32 help for details).
After atom name retrieval (the string) the atom should be deleted using GlobalDeleteAtom.

Instead of using "dynamic" custom message it's possible to define "static" custom message : const CustomMessage = WM_USER+1;
Any way this should be done in all involved applications.
It's also possible to use existing message, but be carefull there could be problems.

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 20

Expert Comment

ID: 1390467
There are two good possibilites:

(1) Use WM_COPYDATA (internally it uses memory mapped files) or
(2) use memory mapped files.


Regards, Madshi.

Expert Comment

ID: 1390468
Here is some pseudo code to give you the general idea (it's from my memory, args might be ordered wrong, function names may be wrong...)

procedure SendString(s: string; hWndOtherApp: HWND);
var p: PChar;
    MsgID: UINT;
  GlobalAlloc(p, Length(s)), GMEMSHARED or GMEMFIXED or something);
  StrPCopy(p, s);
  MsgID := RegisterWindowMessage("SendString");
  SendMessage(hWndOtherApp, MsgID, 0, lParam(p));

You don't have to use RegisterWindowMessage, you could use WM_USER + xxx if you want.

When your other picks up the message, it should cast lParam as a pchar and copy it to a string variable with StrPas.


LVL 10

Expert Comment

ID: 1390469
I can send you a working example with WM_COPDYDATA


Author Comment

ID: 1390470
Hi Everyone...

I think I decided to use the shared memory method with GlobalAlloc anyway. I will use PostMessageTimeOut to transmit the message, because the allocated memory for this string has to be freed afterwards and I also don't want to send further strings if the other process is either not responding or not existent anymore. Since I allready was knowing how to do that, I propose to give the points to the person who can answer me the following question first: How  can I use the RegisterWindowsMessage function... I can see how I have to use it to send a message, since Phil used it in his code, but how can I use it to "get" the message. Usally I use something like:
procedure WMIBInit(var Message : TcustomMsg); message WM_IBINIT;
But the WM_IBINIT has to be a constant. So how do I get that message? With a global message handler? Anyway, the person who submits the answer first, get's the points...

Thanks, Car...
LVL 10

Accepted Solution

Lischke earned 150 total points
ID: 1390471
Hi Car,

Handling this kind of message is a bit different than predefined ones. You have overwrite WndProc of the control in question and check the arriving messages

with an if statement:

procedure TMyControl.WndProc(var Msg: TMessage);

  if Msg.Msg = WM_IBINIT then
  else inherited;

Ciao, Mike

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

664 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