WM_COPYDATA message
-
Does WM_COPYDATA use some kind of shared memory concept when it uses the structure COPYDATASTRUCT?
-
Does WM_COPYDATA use some kind of shared memory concept when it uses the structure COPYDATASTRUCT?
When sending WM_COPYDATA message to another application, lParam must point to a COPYDATASTRUCT, and the passed data must not contain any addresses (pointers or references) that would not be available in the other process. Until the thread sending the message returns from the call, the data structure should be either locked or not modified by other threads of the calling process. The data received by the other process cannot modify / return any of the structure's content. The reason behind all these is that the OS is copying the given structure as a block, from the calling process to the receiving process. It is like calling WriteProcessMemory, on some temp variable (thread stack address) in the target process. The communication is one way! Regards,
Bornish ESRI Developer Network Compilers demystified - Function pointers in Visual Basic 6.0 Enables the use of function pointers in VB6 and shows how to embed native code in a VB application.
-
When sending WM_COPYDATA message to another application, lParam must point to a COPYDATASTRUCT, and the passed data must not contain any addresses (pointers or references) that would not be available in the other process. Until the thread sending the message returns from the call, the data structure should be either locked or not modified by other threads of the calling process. The data received by the other process cannot modify / return any of the structure's content. The reason behind all these is that the OS is copying the given structure as a block, from the calling process to the receiving process. It is like calling WriteProcessMemory, on some temp variable (thread stack address) in the target process. The communication is one way! Regards,
Bornish ESRI Developer Network Compilers demystified - Function pointers in Visual Basic 6.0 Enables the use of function pointers in VB6 and shows how to embed native code in a VB application.
While using the structure could we say that the OS implements one as a shared memory?
-
While using the structure could we say that the OS implements one as a shared memory?
Yes. The way I understand it... when you post a WM_COPYDATA message, the kernel creates a temporary memory mapped file containing the bytes at the location specified relative to the senders address space. This memory mapped file is accessable to the recieving application. Upon SendMessage() returning the memory mapped file is marked for deletion. Best Wishes, Randor (David Delaune)
-
Yes. The way I understand it... when you post a WM_COPYDATA message, the kernel creates a temporary memory mapped file containing the bytes at the location specified relative to the senders address space. This memory mapped file is accessable to the recieving application. Upon SendMessage() returning the memory mapped file is marked for deletion. Best Wishes, Randor (David Delaune)
Hmm,... reading a few times what MSDN, I understood that you cannot return data in the buffer given by the sending application... but, since I've never tried myself, I would consider David's interpretation. Have already found some sample code on CP using such technique to share memory... 2 ways. Well, it wouldn't be the first time when MSDN is missleading! Still, the opinions found are divided almost 50-50. If you're planning to try it out, please let us know about your findings. It would be great if you can try it out on different OS versions. While searching more info about it, I came across an interesting aspect: http://www.flounder.com/wm_copydata.htm[^] Hope you'll find this idea useful, and couldn't hurt using a GUID as explained there. Best wishes,
Bornish ESRI Developer Network Compilers demystified - Function pointers in Visual Basic 6.0 Enables the use of function pointers in VB6 and shows how to embed native code in a VB application.