2015-05-19 29 views
0

我想爲Windows 7或Windows 8創建一個Win32程序。我希望能夠在Windows 8上支持觸摸注入。InitializeTouchInjection是初始化此符號的符號,但僅限於在Windows 8中可用。在加載時間或運行時檢查Windows版本和鏈接到此符號是否有方法?目前我在Windows 7中加載時得到未定義的鏈接。在加載時條件鏈接到符號

+0

您可能想了解[動態鏈接庫函數](https://msdn.microsoft.com/zh-cn/library/windows/desktop /ms682599%28v=vs.85%29.aspx)在Windows API中。 –

+2

使用delayload或GetProcAddress –

+0

使用GetProcAddress解決了我的問題。 –

回答

0

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