5.3 Callback Function

An application that uses the DDEML must provide a callback function that processes the DDE events that affect the application. The DDEML notifies an application of such events by sending transactions to the application's DDE callback function. The transactions that a callback function receives depend on the callback-filter flags that the application specified in the DdeInitialize function and on whether the application is a client, a server, or both. The following example shows the general structure of a callback function for a typical client application:

HDDEDATA EXPENTRY DdeCallback(wType, wFmt, hConv, hsz1,
    hsz2, hData, dwData1, dwData2)
WORD wType;       /* transaction type                 */
WORD wFmt;        /* clipboard format                 */
HCONV hConv;      /* handle of the conversation       */
HSZ hsz1;         /* handle of a string               */
HSZ hsz2;         /* handle of a string               */
HDDEDATA hData;   /* handle of a global memory object */
DWORD dwData1;    /* transaction-specific data        */
DWORD dwData2;    /* transaction-specific data        */
{
    switch (wType) {
        case XTYP_REGISTER:
        case XTYP_UNREGISTER:
            .
            .
            .
            return (HDDEDATA) NULL;


        case XTYP_ADVDATA:
            .
            .
            .
            return (HDDEDATA) DDE_FACK;

        case XTYP_XACT_COMPLETE:
            .
            .
            .
            return (HDDEDATA) NULL;

        case XTYP_DISCONNECT:
            .
            .
            .
            return (HDDEDATA) NULL;

        default:
            return (HDDEDATA) NULL;
    }
}

The wType parameter specifies the transaction type sent to the callback function by the DDEML. The values of the remaining parameters depend on the transaction type. The transaction types and the events that generate them are described in the following sections of this chapter. For detailed information about each transaction type, see Section 5.8, “Transaction Management.”