Solved

Send a Message to an Application

Posted on 1998-04-14
6
211 Views
Last Modified: 2010-04-10
I'd like to send a message in my application to other
applications.
my application receives data from serial port and process
these data. once i finish this process  i want to notify
 any other applications of getting theses data or use theses data.how can i send message to other application.
0
Comment
Question by:khs
[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
6 Comments
 
LVL 5

Expert Comment

by:yonat
ID: 1184288
In MS Windows, use SendMessage() or PostMessage().
0
 

Author Comment

by:khs
ID: 1184289
sorry! your answer is not suite for me. i'd like to konw detailed
example code.
I already know SendMessage() and PostMessage() functions.


0
 

Accepted Solution

by:
gds earned 100 total points
ID: 1184290
In 32-bit Windows there are several ways of doing an inter-process communication:

1.  You can set up a piece of global shared memory, using CreateFileMapping, OpenFileMapping and MapViewOfFile.  Then use a named mutex to control access to the shared memory, and a global named event to signal from the source to the client that new data is available.

2.  Use a named pipe.  Make the client app listen on a pipe, and have the source app stuff data into the pipe.  This has the advantage over (1) that the two processes can be on separate computers.

3.  Use an RPC call from the source to the client.  You can configure an RPC to work purely locally using a lightweight RPC, so the processes can be on the same computer.

4.  Failing all of that, use

PostMessage(HWND_BROADCAST,msgMyMessage,0,0)

where msgMyMessage is a userdefined message ID obtained from a call to RegisterWindowMessage.  All top-level windows will receive the message, but (presumably) only your client apps will understand the registered message.
0
Industry Leaders: 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!

 

Author Comment

by:khs
ID: 1184291
I don't understand your answer.I am a novice.
I am using now MFC 5.0 .
0
 
LVL 11

Expert Comment

by:alexo
ID: 1184292
Sending messages to other applications is easy.  You need to aquire the window handle of the other application window you'd like to send messages to.  For example, you can use:

    hwnd = FindWindow(NULL, "the title of the window");
    if (hwnd != NULL)
        PostMessage(hwnd, message, 0, 0);

Or, you can broadcast a message to all windows in the system:

    PostMessage(HWND_BROADCAST, message, 0, 0);

Where "message" is either one of the standard messages (WM_xxx) or a user-defined one.

You can define messages for inter-application communications by asking Windows to provide a unique message number:

    message = RegisterWindowMessage("Message ID string");

Note that the program that receives the message should now how to deal with it :-)

Is this a satisfactory answer?

0
 

Expert Comment

by:Skrobotz
ID: 1184293
Use the Command:

In the Sending Program use
RegisterWindowMessage(..)
and
PostMessage(..)

In the program that must recieve the message use the command
RegisterWindowMessage(..) and wrote a Routine to process the Message.


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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

623 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