我试图在VisualStudio2022项目中使用来自ImmGetContext()的<imm.h>,这会导致以下错误:
1>Project.obj : error LNK2019: unresolved external symbol ImmGetContext referenced in function "void __cdecl activeWindowChangeHandler(struct HWINEVENTHOOK__ *,unsigned long,struct HWND__ *,long,long,unsigned long,unsigned long)" (?activeWindowChangeHandler@@YAXPEAUHWINEVENTHOOK__@@KPEAUHWND__@@JJKK@Z)
1>Project.obj : error LNK2019: unresolved external symbol ImmGetConversionStatus referenced in function "void __cdecl activeWindowChangeHandler(struct HWINEVENTHOOK__ *,unsigned long,struct HWND__ *,long,long,unsigned long,unsigned long)" (?activeWindowChangeHandler@@YAXPEAUHWINEVENTHOOK__@@KPEAUHWND__@@JJKK@Z)
1>C:\Users\username\Project\x64\Debug\Project.exe : fatal error LNK1120: 2 unresolved externals我尝试将imm32.dll从操作系统本身添加到项目的项目-> Linker -> General以及Linker选项中。它似乎已被识别,但无法解析,以下是更改后的新错误:
1>C:\Windows\SysWOW64\imm32.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2D0不能正确地解析C:\Windows\SysWOW64\或C:\Windows\System32\中的那个。
下面是我要实现的代码:
#include <iostream>
#include <windows.h>
using namespace std;
void CALLBACK activeWindowChangeHandler(HWINEVENTHOOK hWinEventHook, DWORD dwEvent, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime) {
DWORD dwConversion, dwSentence;
auto himc = ImmGetContext(hwnd);
if (ImmGetConversionStatus(himc, &dwConversion, &dwSentence)) {
wcout << L"Current conversion mode: " << dwConversion << L"sentence mode: " << dwSentence << endl;
}
else {
wcout << L"Failed to get conversion mode" << endl;
}
}
int main() {
auto hEvent = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, NULL, activeWindowChangeHandler, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
while (true);
}谢谢!
发布于 2022-09-02 01:35:30
好像我做得完全错了。将#pragma comment(lib, "imm32")添加到代码中解决了这个问题。
发布于 2022-09-02 01:18:55
您正在使用的库应该是用于Win32的,您应该包括_和_
#include <immdev.h>
#include <imm.h>https://stackoverflow.com/questions/73576743
复制相似问题