Reputation: 22293
If I read the description of the PostMessage API, it has this sentence:
The system only does marshalling for system messages (those in the range 0 to (WM_USER-1)). To send other messages (those >= WM_USER) to another process, you must do custom marshalling.
I am curious what is that "message marshalling"?
Upvotes: 3
Views: 1598
Reputation: 597101
Messages sometimes pass pointers to memory buffers in their parameters. If you send a memory address as-is from one process to another, the address will not have the same meaning in the receiving process.
For system messages, like WM_SETTEXT
and WM_COPYDATA
for example, the OS knows how to work with the memory buffers for those messages. When sending such a message across processes, the OS automatically allocates an appropriate memory buffer in the receiving process and fills it with a copy of the original data. The message parameters are then adjusted to point at the new memory address accordingly before the message is delivered to the target message handler.
For custom messages that contain pointers, the OS cannot automatically marshal the data for you, so you have to perform your own custom marshaling.
That is what message marshaling is about. Copying externally-referenced data from one process to another in a safe way so that any pointers in the message make sense within the address space of the receiving process.
Upvotes: 9
Reputation: 43359
Consider one thing that is fundamentally different about separate Win32 processes that makes IPC complicated... their address spaces.
Marshalling very generally refers to packaging data up for communication across hosts/processes. In this case, Windows takes care of any pointers in messages that it knows about so that they are valid pointers in the address space of the receiving process. In other words, if a message points to something in the sending process Windows makes sure that what it points to is copied and that after it is received the message is altered so that it points to wherever that memory was copied in the new address space.
Windows cannot do anything even remotely like that for user messages because it does not know how to interpret any of it and thus it becomes your responsibility to marshal the data for any message >= WM_USER
.
Upvotes: 5