IPC using RegisterWindowMessage

Posted on 2000-04-29
Last Modified: 2013-11-20
I have implemented IPC mechanism using RegisterWindowMessage .
The sending app allocates memory using GlobalAlloc and gets the pointer using GlobalLock and casts it to ptr to struct and assigns value to it. Then it calls GlobalUnlock and sends the HGLOBAL as lparam of PostMessage. The receiving app converts the HGLOBAL into
a pointer(GlobalLock) and the pointer is not NULL. But when I try to read the contents of the pointer I get an access violation. I tried various ways of GlobalLock etc but in vain.
Question by:mfc_speak
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
  • 3
LVL 32

Expert Comment

ID: 2761832
You CAN use RegisterWindowMessage to send messages between processes but you cannot send a memory pointer from one process to another.  Each process runs in its own virtual memory space and the addresses don't mix, at all.

There are a number of ways of doing this but the one that may lend itself to your method here is to use the WM_COPYDATA window message.

Author Comment

ID: 2761970
I feel that pointers can be shared across processes. I did a similar thing for clipboard copy and it worked fine. Since the global handles are allocated in the shared addr space common to all processes, I feel this should be possible.

Regarding WM_COPYDATA message, I read thru documentation. It says that an app must use SendMessage and not PostMessage to send it. But I need to send the data by PostMessage( which wont block my thread).
LVL 32

Accepted Solution

jhance earned 20 total points
ID: 2762074
I'm not really interested in HOW YOU FEEL about this.  


The clipboard is a different animal and is supported via the Windows API.  You don't operate on the clipboard via a pointer you get a handle to the clipboard from Windows.

The reason that WM_COPYDATA must use SendMessage is that the receiving application must accept the data while it is guaranteed to be valid.  If PostMessage were used the data might not still be available whenever the receiving process got around to accepting the message.

If you need some other scheme that doesn't rely on SendMessage you could use a memory mapped file, a disk file, a network socket connection, a pipe, a mailslot, or a shared memory area.

In none of the above cases, however, will you be sharing a memory pointer.  You will reference a handle to the object that Windows will manage for you.
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!


Author Comment

ID: 2765361
WM_COPYDATA did not work with PostMessage. It worked only with SendMessage!!!
LVL 32

Expert Comment

ID: 2765488

Next time keep your stupid points.

Author Comment

ID: 2765787
Hey!!! dont get hot. I given you the grade you deserved (and points of course). You said that WM_COPYDATA works with PostMessage (but it didn't)
Any way :-)
LVL 32

Expert Comment

ID: 2767862
I said:

"The reason that WM_COPYDATA must use SendMessage..."

I did NOT say that WM_COPYDATA works with PostMessage!

I'm HOT because you graded me with a "D".  That's why you're a jerk!  If this answer was so damned bad you should have just rejected it.

Next time, keep your stinking points!!


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

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 84
Perl Awk Need Help 3 145
Separate into files by filename 12 92
substring method in java 1 141
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

740 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