none
Native calls to IME fail to work in Windows 7 RRS feed

  • Question

  • We have C# code that works perfectly fine in Windows XP to enable the IME for a particular locale.  However, the same code under Windows 7 fails to enable the IME and set it to the desired locale.  Here is the code:

    			[DllImport ("user32.dll")]
    			private static extern int LoadKeyboardLayout (string pwszKLID, int Flags);
    			[DllImport ("user32.dll")]
    			private static extern bool SystemParametersInfo (int uiAction, int uiParam, int[] pvParam, int fWinIni);
    			[DllImport ("imm32.dll")]
    			private static extern IntPtr ImmGetContext (IntPtr hWnd);
    			[DllImport ("imm32.dll")]
    			private static extern bool ImmSetOpenStatus (IntPtr hIMC, bool fOpen);
    			[DllImport ("imm32.dll")]
    			private static extern bool ImmReleaseContext (IntPtr hWnd, IntPtr hIMC);
    			[DllImport ("imm32.dll")]
    			private static extern bool ImmSetConversionStatus (IntPtr hIMC, int conv, int sent);
    			// Windows API constants.
    			private const int KLF_ACTIVATE = 1;
    			private const int SPI_SETSHOWIMEUI = 111;
    			public static void SetInputKeyboard (ILocaleIME locale, IntPtr handle)
    			{
    				int iRet = LoadKeyboardLayout (locale.CodePage, KLF_ACTIVATE);
    				IntPtr hIMC = ImmGetContext (handle);
    				bool bRet = ImmSetOpenStatus (hIMC, true);
    				bRet = ImmSetConversionStatus (hIMC, (int)locale.ConversionModeFlags, (int)locale.SentenceModeFlags);
    				bRet = ImmReleaseContext (handle, hIMC);
    				if (locale.ShowIMEUI)
    					bRet = SystemParametersInfo (SPI_SETSHOWIMEUI, 0, null, 0);
    			}

    As far as the paramerter values go, for Korean (ko_KR) locale.CodePage would be "e0010412", locale.ConversionModeFlags would be Native | FullShape, locale.SentenceModeFlags would be PluralClause, and local.ShowIMEUI would be false.  All the return values indicate success (i.e. bools are true) and there is no other indication of a failure, but the IME does not get switched on.  Same code works great in XP.

    Is this another permissions issue?  Any help would be appreciated.

    Tuesday, July 31, 2012 7:15 PM

All replies

  • Hi Rich,

    Welcome to the MSDN Forum.

    Did you get any exceptions and what are them? And would you like to tell us which line throw the exceptions? Thank you.

    Did you try to run it as administrator?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 1, 2012 8:43 AM
    Moderator
  • Mike,

    No, I did not get any exceptions.  The return values were good from the native calls when I looked at them in the debugger.  There is nothing logged in the event log either.  I am already running as administrator.

    Rich

    Wednesday, August 1, 2012 2:13 PM
  • Hi Rich,

    I have checked the API

    SystemParametersInfo  

    again, your code is

    SystemParametersInfo (SPI_SETSHOWIMEUI, 0, null, 0);

    But for SPI_SETSHOWIMEUI

    Sets whether the IME status window is visible or not on a per-user basis. The uiParamparameter specifies TRUE for on or FALSE for off.

    So how about change your code to 

    SystemParametersInfo (SPI_SETSHOWIMEUI, True, null, 0);

    In addition, What type is

    ILocaleIME 

    ?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, August 2, 2012 6:20 AM
    Moderator
  • ILocaleIME is our own internal type:

    	public interface ILocaleIME
    	{
    		string CodePage { get; }
    		KeyboardEmulator.IMEHelper.ConversionMode ConversionModeFlags { get; }
    		bool IsIMENeeded { get; }
    		KeyboardEmulator.IMEHelper.SentenceMode SentenceModeFlags { get; }
    		bool ShowIMEUI { get; }
     
    		bool KeyPressed(KeyButton key, out Keys[] keysToSend);
    	}
    Thursday, September 13, 2012 7:37 PM
  • Hi Rich,

    Welcome to back.

    How about my above suggestion?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, September 14, 2012 2:55 AM
    Moderator
  • Hi Mike,

    Unfortunately, your suggested change did not solve my problem.  Is there any other information I can provide to help diagnose the issue.

    Rich

    Friday, September 14, 2012 6:02 PM
  • Hi Rich,

    How about run your application with "run as administrator"?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, September 17, 2012 2:50 AM
    Moderator
  • It is already being run as administrator.
    Thursday, September 20, 2012 8:39 PM
  • It is already being run as administrator.

    Mike,

    I hope you are still paying attention to this thread.  I have written a simple test program that can demonstrate the problem, in this example, switching between English and Korean.  It has no dependencies on any of our custom code.  I can send you a ZIP file of the project.  After being built, the same executable will run correctly under Windows XP.  It will switch the Korean IME on and off and type the correct characters.   Running under Windows 7, it will fail to switch to the Korean IME.  Running as administrator does not help and no exceptions are thrown.

    Is there a way I can send you the source for this test program so you can build and try it yourself?

    FYI, for Windows XP, I have the Korean Input System (IME 2002) configured on my system.  For Windows 7, I have the Microsoft IME configured.

    Rich

    Wednesday, October 10, 2012 2:54 PM
  • Hi Rich,

    Sorry for delay response.

    You can upload your project on skydrive or any other website, and post the download link here. In this way, any other interested members can also test it and response to this thread.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, October 11, 2012 6:33 AM
    Moderator
  • Hi Mike,

    Sorry for my long absence.  Many other project distractions.  I've posted the source of my IME test program to Dropbox.  Here is a link to it.

    https://www.dropbox.com/s/84rdst59fsirq18/IMEtest.zip


    Rich

    Monday, December 3, 2012 1:53 PM
  • Hi Rich,

    I reproduced your issue, please post it on connect site: http://connect.microsoft.com/VisualStudio 

    When you finished, please post this link here, so the other one which is interested this can follow up well.

    Thank you.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 4, 2012 8:14 AM
    Moderator
  • OK, Mike.  I've posted my problem and test program source to connect.microsoft.com and await their response.  When I have a resolution, I will post it here.


    Rich

    Here is the link to the item I created on connect.microsoft.com in case anyone else wants to follow.  Still waiting for a resolution.

    http://connect.microsoft.com/VisualStudio/feedback/details/773427/native-calls-to-ime-fail-to-work-in-windows-7

    Tuesday, December 4, 2012 4:34 PM