Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Send a Message to an Application

Posted on 1998-04-14
6
Medium Priority
?
219 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
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 200 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

783 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