在加载时有条件地链接到符号



我想为Windows 7或8构建一个Win32程序。我希望能够在Windows 8上支持触摸注入。InitializeTouchInjection是初始化此符号的符号,但仅在 Windows 8 中可用。有没有办法在加载时或运行时检查 Windows 版本和指向此符号的链接?目前,我在 Windows 7 中加载时遇到未定义的链接。

使用 GetProcAddress 允许代码检查符号是否退出,如果没有,则提供替代行为。在这种情况下,触摸注入仅在 Windows 8 中。

typedef BOOL(WINAPI *InitTouch) (_In_ UINT32 maxCount, _In_ DWORD dwMode);
InitTouch fp =  (InitTouch)GetProcAddress(GetModuleHandle(TEXT("User32.dll")),                               
"InitializeTouchInjection");
if ((fp != NULL) && fp(TOUCH_LIMIT, TOUCH_FEEDBACK_DEFAULT))
{
// Behavio(u)r with the feature
}
else
{
// Behavio(u)r without the feature
}

最新更新