When the application or system creates new input context, the system prepares the new input context. The new input context already includes IMCC, the components of IMC consisting of hCompStr, hCandInfo, hGuideLine, hPrivate and hMsgBuf. Basically, the IME does not need to create the input context and the components of the input context. The IME can change their size, and can retrieve a pointer to the components by locking them.
To access the input context, an IME must call ImmLockIMC to retrieve a pointer to the input context. ImmLockIMC increments the imm lock count for IMC, and ImmUnlockIMC decrements it.
To access one component of the input context, an IME must call ImmLockIMCC to get a pointer to IMCC. ImmLockIMCC increments the imm lock count for IMCC, and ImmUnlockIMC decrements it. ImmReSizeIMCC may resize IMCC to the specified size.
Occasionally, an IME may need to create one component of the input context by itself. In this case, the IME can call the ImmCreateIMCC function and obtain the handle of IMCC. This IMCC can be members of the INPUTCONTEXT structure (hCompStr, hCandInfo, hGuideLine, hPrivate or hMsgBuf).
ImmDestroyIMCC destroys one component of the input context.
The following example shows how to use an input context:
LPINPUTCONTEXT lpIMC; LPCOMOSITIONSTRING lpCompStr; HIMCC hMyCompStr; if (hIMC) { // It is not NULL context. lpIMC = ImmLockIMC(hIMC); if (!lpIMC) { MyError( "Can not lock hIMC"); return FALSE; } // Use lpIMC->hCompStr. lpCompStr = (LPCOMPOSITIONSTRING) ImmLockIMCC(lpIMC->hCompStr); // Access lpCompStr. ImmUnlockIMCC(lpIMC->hCompStr); // ReSize lpIMC->hCompStr. if (!(hMyCompStr = ImmReSizeIMCC(lpIMC->hCompStr,dwNewSize)) { MyError("Can not resize hCompStr"); ImmUnlockIMC(hIMC); return FALSE; } lpIMC->hCompStr = hMyCompStr; ImmUnlockIMC(hIMC); }