Using the Message Buffer

The following example shows how to use the message buffer:

MyGenerateMesage(HIMC hIMC, UINT msg, WPARAM wParam, LPARAMlParam)
{
    LPINPUTCONTEXT lpIMC;
    HGLOBAL hTemp;
    LPDWORD lpdwMsgBuf;
    DWORD dwMyNumMsg = 1;
 
    // Lock the input context.
    lpIMC = ImmLockIMC(hIMC);
    if (!lpIMC)
        // Error!
 
    // re-allocate the memory bloack for the message buffer.
    hTemp = ImmReSizeIMCC(lpIMC->hMsgBuf, 
        (lpIMC->dwNumMsgBuf + dwMyNumMsg) * sizeof(DWORD) * 3);
    if (!hTemp)
        // Error!
 
    lpIMC->hMsgBuf = hTemp;
 
    // Lock the memory for the message buffer.
    lpdwMsgBuf = ImmLockIMCC(lpIMC->hMsgBuf);
    if (!lpdwMsgBuf)
        // Error!
 
    lpdwNumMsgBuf += 3 * lpIMC->dwNumMsgBuf.
    // Set the number of the messages.
    lpIMC->dwNumMsgBuf += dwMyNumMsg;
 
    // Set the messages that the IME needs to generate.
    *lpdwMsgBuf++ = (DWORD) msg;
    *lpdwMsgBuf++ = (DWORD) wParam;
    *lpdwMsgBuf++ = (DWORD) lParam;
 
    // Unlock the memory for the message buffer and the input context.
    ImmUnlockIMCC(lpIMC->hMsgBuf);
    ImmLockIMC(hIMC);
 
    // Call ImmGenerateMessage function.
    ImmGenerateMessage(hIMC);
}