A DDE conversation is initiated by a client by broadcasting a WM_DDE_INITIATE message to all top-level windows. (As you'll see when I discuss the DDE client program later in this chapter, this is accomplished by calling SendMessage with a 0xFFFF window handle as the first parameter.)
The WM_DDE_INITIATE message is handled by a DDE server in its main window procedure. As in every DDE message, the wParam parameter is the handle to the window sending the message. This is the window handle of the client. WndProc stores this in the variable hwndClient.
For the WM_DDE_INITIATE message, the low word of lParam is the atom identifying the desired application. This could be NULL if the client wants a response from any server. The high word of lParam is the atom identifying the desired topic. Again, this could be NULL if the client wants a response from a server that can supply any topic.
WndProc processes the WM_DDE_INITIATE message by calling GlobalAddAtom to add atoms for its application name (”DdePop“) and topic name (”US_Population“). It then checks if the atoms supplied in the low word and high word of lParam are NULL or match these atoms.
If the atoms match, then WndProc creates a hidden child window based on the ”DdePop.Server“ window class. This window (whose window procedure is ServerProc) will handle all subsequent DDE messages in the DDE conversation. The first of the two words reserved for the window is set to the handle of the client using SetWindowWord. WndProc then acknowledges the WM_DDE_INITIATE message by sending a WM- DDE_ACK message back to the client. The wParam parameter is the handle of the just-created server window, and lParam contains the atoms identifying the server application name and the topic name. (If the client requested all topics and the server supports multiple topics, then the server would send multiple WM_DDE_ACK messages back to the client, one for each topic it supports.)
A program that receives a WM_DDE_ACK message is responsible for deleting all atoms that accompany the message. WndProc calls GlobalDeleteAtom for the two atoms it created only if it does not send a WM_DDE_ACK message to the client.
The WM_DDE_INITIATE message and the WM_DDE_ACK message (in response to WM_DDE_INITIATE) are the only two DDE messages that are sent using SendMessage rather than posted using PostMessage. As we'll see later in this chapter, this means that a client sending a WM_DDE_INITIATE message receives the WM_DDE_ACK responses before the original SendMessage call has returned.