0

I am using Flutter to develop a Windows program, Need to disable input method, Find the relevant documentation, you can use the ImmDisableIME(0) method to disable the input method. But when I try to call this method, An exception was reported when running the project.

main.cpp

win32_window.cpp

How to properly disable the input method?

selbie
  • 100,020
  • 15
  • 103
  • 173
Saxxhw
  • 7
  • 1
  • 4
  • I'll answer the question anyway, but in general, please don't post links or pictures of code. Inline the code directly as text along with the error messages. – selbie Sep 26 '22 at 07:01

1 Answers1

0

An exception was reported when running the project

No. An exception was not reported when running the project. Rather, your program never ran to begin with because it had a compiler error.

Because you are passing -1 to a function expecting an unsigned integer (DWORD), the compiler is warning you (C4245). And your build environment treats warnings as errors (C2220).

To invoke it with -1 such that it disables for all threads in the current process, then invoke it as follows with a cast. It's as easy as that.

DWORD dwParam = (DWORD)(-1);
ImmDisableIME(dwParam);
selbie
  • 100,020
  • 15
  • 103
  • 173
  • Thank you very much for your reply. A lot of websites mentioned that the parameter should simply be -1 to disable all threads in this process. [link](https://github.com/MicrosoftDocs/sdk-api/blob/docs/sdk-api-src/content/immdev/nf-immdev-immdisableime.md). I tried using 0 or 1 but it still produces the error. – Saxxhw Sep 26 '22 at 10:16
  • `main.obj : error LNK2019: �޷��������ⲿ���� ImmDisableIME������ wWinMain �������˸÷��� [W:\WorkSpace\RouXinPai\workpad\build\windows\runner\workpad.vcxproj] W:\WorkSpace\RouXinPai\workpad\build\windows\runner\Debug\workpad.exe : fatal error LNK1120: 1 ���޷��������ⲿ���� [W:\WorkSpace\RouXinPai\workpad\build\windows\runner\workpad.vcxproj] Exception: Build process failed.` – Saxxhw Sep 26 '22 at 10:21
  • You are correct. `-1` means "disable for all threads in the process". Hence use a cast. I've updated my answer above, but effectively you can call it as: `ImmDisableIME((DWORD)-1);` – selbie Sep 26 '22 at 18:57
  • After inquiring some information, finally disabled the input method. First, add `#pragma comment(lib, "imm32.lib")` to the header of the `win32_window.cpp` file, Then call the `ImmDisableIME(GetCurrentThreadId())` method. Thank you for your help.&( ^___^ )& – Saxxhw Sep 27 '22 at 08:18