IPC using RegisterWindowMessage

Posted on 2000-04-29
Medium Priority
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.
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.


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

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.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month11 days, 6 hours left to enroll

752 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