I created dynamic library(dll) which is using function GetScaleFactorForMonitor
from windows API. However this function was introduced in Windows 8.1 and those dll won't load at Windows 7 obviously. I am thinking about the solution to have two versions of the same method in one dll and use it according to Windows version.
Does anyone have any suggestions. I would be up to keep GetScaleFactorForMonitor
in my code.
You basically need something like this:
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
...
}
You probably want to rearrange this for your needs, but you should get the idea.
You don't really need
haveGetScaleFactorForMonitor
, you can simply check ifpGETSCALEFACTORFORMONITOR
is NULL or not@RemyLebeau I simplified the code somewhat, thanks
Thanks that's worked for me. I just replace first line with typedef int
(*GetScaleFactor)(HMONITOR hMonitor, DEVICE_SCALE_FACTOR *nScaleFactor);