22.4.4 Carrying Out Commands in a Remote Application

A Windows application can use the WM_DDE_EXECUTE message to cause a certain command or series of commands to be carried out in another application. The client sends the server a WM_DDE_EXECUTE message containing a handle of a command string, as follows:

if (!(hCommand = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
        sizeof(szCommandString) + 1)))
    return;
if (!(lpCommand = GlobalLock(hCommand))) {
    GlobalFree(hCommand);
    return;
}
lstrcpy(lpCommand, szCommandString);
GlobalUnlock(hCommand);
if (!PostMessage(hwndServerDDE,
        WM_DDE_EXECUTE,
        hwndClientDDE,
        MAKELONG(0, hCommand))) {
    GlobalFree(hCommand);
}

The server attempts to carry out the specified command string. If the server is successful, it sends the client a positive WM_DDE_ACK message; otherwise, it sends a negative WM_DDE_ACK message. This WM_DDE_ACK message reuses the hCommand handle passed in the original WM_DDE_EXECUTE message.