【问题标题】:Conditionally link to symbol at load time在加载时有条件地链接到符号
【发布时间】:2015-07-31 17:26:56
【问题描述】:

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

【问题讨论】:

  • 您可能想了解 Windows API 中的 dynamic link library functions
  • 使用 delayload 或 GetProcAddress
  • 使用 GetProcAddress 解决了我的问题。

标签: c++ winapi dll


【解决方案1】:

使用 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
}

【讨论】:

    猜你喜欢
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    • 2011-12-09
    • 2016-01-11
    • 1970-01-01
    • 2014-06-28
    • 2017-06-02
    • 2021-05-17
    相关资源
    最近更新 更多