[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

IPC using RegisterWindowMessage

Posted on 2000-04-29
7
Medium Priority
?
526 Views
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.
0
Comment
Question by:mfc_speak
  • 4
  • 3
7 Comments
 
LVL 32

Expert Comment

by:jhance
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.
0
 

Author Comment

by:mfc_speak
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).
0
 
LVL 32

Accepted Solution

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

Under WIN32 you CANNOT SHARE POINTERS BETWEEN PROCESSES.  Each process runs in its OWN 32-BIT MEMORY SPACE!

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.
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:mfc_speak
ID: 2765361
WM_COPYDATA did not work with PostMessage. It worked only with SendMessage!!!
0
 
LVL 32

Expert Comment

by:jhance
ID: 2765488
Jerk!  

Next time keep your stupid points.
0
 

Author Comment

by:mfc_speak
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 :-)
0
 
LVL 32

Expert Comment

by:jhance
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!!

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…
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.
Loops Section Overview
Suggested Courses

830 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