DDE is designed to allow applications that follow the protocol to
share/pass data back and forth. An "envelope and letter" analogy,
which is listed below, provides an example of how this works:
If some information needs to be sent from one person/application
to another person/application, do the following:
a. Address the envelope: Call GlobalAlloc() on a piece of global
memory with the GMEM_DDESHARE flag.
b. Write the letter on a piece of paper: Call GlobalLock() and
write to the global memory.
c. Seal the letter: Call the GlobalUnlock() function.
d. Send the letter off to the other person: Use the PostMessage()
function with a WM_DDE_DATA message that has the hGlobalMemory
in it.
To receive and read the letter, the other person/application
does the following:
a. Get the letter: A WM_DDE_DATA message is found in the message
queue, along with the handle of the global memory,
hGlobalMemory.
b. Open the envelope: Call GlobalLock (hGlobalMemory).
c. Make a copy of the letter and read it:
1) Create a new envelope: Call GlobalAlloc(hNewEnvelope) and
use the GMEM_DDESHARE flag IF the letter needs to be sent
back.
2) Open the new envelope: Call GlobalLock(hNewEnvelope).
3) Copy the contents of the old letter to the new letter,
modifying the contents at this time if necessary.
4) Seal the envelope: Call GlobalUnlock().
If the person/application wants to send the letter back to
the person/application that originally sent the letter, perhaps
with some answers to questions asked in the original letter, the
following procedure should be used:
5) Send the letter: Call PostMessage() with the new handle to
global memory.
d. When done with the old letter, throw it away: Use GlobalUnlock()
on the handle and then call GlobalFree().
According to the DDE specification, the rules for freeing the
global memory object are as follows:
Receiver deletes memory unless either of the following is true:
1) fRelease flag is zero.
2) The fRelease flag is 1; however, the receiving (client)
application responds with a negative WM_DDE_ACK message.
For more information, please refer to Chapter 15 in the
Windows SDK reference manual.