Using the Translation Buffer in ImeToAsciiEx

The following example shows how to generate messages by passing a buffer to the ImeToAsciiEx function:


UINT ImeToAsciiEx(uVirKey, uScanCode, lpbKeyState, lpdwTransBuf, 
    fuState , hIMC )
{
    DWORD dwMyNumMsg = 0;

    .
    .
    .

    // Set the messages that the IME needs to generate.
    *lpdwTransBuf++ = (DWORD) msg;
    *lpdwTransBuf++ = (DWORD) wParam;
    *lpdwTransBuf++ = (DWORD) lParam;

    // Count the number of the messages that the IME needs to generate.
    dwMyNumMsg++;
    .
    .
    .

    return dwMyNumMsg;
}

The buffer that is specified by lpdwTransBuf is provided by the system. The ImeToAsciiEx function can put all of the messages into this buffer at one time. The number of messages that can be put in this buffer is given at the first double word of the buffer. If the ImeToAsciiEx function needs to generate more messages than the given number, the function can put all of the messages into hMsgBuf that is in the input context, and ImeToAsciiEx returns the number of the messages. When the return value of ImeToAsciiEx is larger than the specified value in lpdwTransBuf, the system does not pick up the messages from lpdwTransBuf. The system looks up the hMsgBuf of the input context that is passed as parameter of ImeToAsciiEx.