簡體   English   中英

對 dll 中的 Windows 7 和 Windows 10 使用不同的功能

[英]Using different functions for Windows 7 and Windows 10 in dll

我創建了動態庫(dll),它使用來自 windows GetScaleFactorForMonitor的 function GetScaleFactorForMonitor。 然而這個 function 是在 Windows 8.1 中引入的,那些 dll 顯然不會在 ZAEA23489CE3AA9B63406EBA 加載。 我正在考慮在一個 dll 中使用相同方法的兩個版本並根據 Windows 版本使用它的解決方案。

有沒有人有什么建議。 我會在我的代碼中保留GetScaleFactorForMonitor

你基本上需要這樣的東西:

typedef HRESULT CALLBACK GETSCALEFACTORFORMONITOR(HMONITOR hMon, DEVICE_SCALE_FACTOR* pScale);

...

HMODULE hm = LoadLibrary("Shcore.dll");     // GetScaleFactorForMonitor is here

GETSCALEFACTORFORMONITOR* pGETSCALEFACTORFORMONITOR = NULL;

if (hm)
{
  pGETSCALEFACTORFORMONITOR = (GETSCALEFACTORFORMONITOR*)GetProcAddress(hm, "GetScaleFactorForMonitor");
}

if (pGETSCALEFACTORFORMONITOR)
{ 
  // GetScaleFactorForMonitor exists, call it like this:
  HRESULT hr = (*pGETSCALEFACTORFORMONITOR)(whatever parameters);   // call GetScaleFactorForMonitor
  // instead of like this:
  // HRESULT hr = GetScaleFactorForMonitor(whatever parameters);
}
else
{
  // GetScaleFactorForMonitor not available
  ...
}

您可能想根據需要重新安排它,但您應該明白這一點。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM