Microsoft KB Archive/301358

= PRB: J/Direct Call to IMM32.ImmSetOpenStatus Fails on Windows 2000 =

Article ID: 301358

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Java Virtual Machine, when used with:
 * Microsoft Windows 2000 Standard Edition

-



This article was previously published under Q301358



SYMPTOMS
On Windows 2000 with Japanese support enabled, a J/Direct call to the IMM32.ImmSetOpenStatus function always fails, returning false in a Java applet. For example, the following sample code always returns false: int hImc = IMM32.ImmGetContext(0); boolean b = IMM32.ImmSetOpenStatus(hImc, true);



CAUSE
This problem occurs because the call to the ImmSetOpenStatus function is made from an invalid input context thread. The input context thread should be a browser-created thread; however, in this example, java.lang.Thread calls ImmSetOpenStatus of IMM32.



RESOLUTION
To ensure that the correct input context thread is used (namely, to get onto the correct thread to own the window), follow these steps:   Call the SetWindowLong function with the GWL_WNDPROC index as follows to create a subclass of the window that specifies the associated window procedure: int root = com.ms.wfc.util.Root.alloc(new HookProc); com.ms.win32.User32.SetWindowLong(hWnd, com.ms.win32.wing.GWL_WNDPROC, DllLib.addrOf(root));   Create the HookProc window procedure class so that it extends the com.ms.dll.Callback class, and make sure to use the CallWindowProc function to call the previously registered window procedure for any messages that HookProc does not process as follows: class HookProc extends Callback { ...   public int callback(int hwnd, int msg, int wparam, int lparam) { ...        ...    int hImc = IMM32.ImmGetContext(hwnd); boolean b = IMM32.ImmSetOpenStatus(hImc, true); ...        ...    return 0; }        ... }                    

