VirtualBox

Ignore:
Timestamp:
Apr 25, 2018 12:21:09 PM (7 years ago)
Author:
vboxsync
Message:

UIDesktopWidgetWatchdog.cpp: Only resolve EnumDisplayMonitors once, and make sure to perfectly match the function pointer with the SDK headers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIDesktopWidgetWatchdog.cpp

    r71429 r72011  
    5959} MONITOR_DPI_TYPE;
    6060
    61 bool MonitorEnumProcF(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lpClipRect, LPARAM dwData)
     61static BOOL CALLBACK MonitorEnumProcF(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lpClipRect, LPARAM dwData)
    6262{
    6363    /* These required for clipped screens only: */
     
    432432
    433433#ifdef VBOX_WS_WIN
    434 
    435     /* Dynamically access User32.dll: */
    436     QLibrary user32("User32.dll", NULL);
    437 
    438     /* Enumerate available monitors through EnumDisplayMonitors (available since Windows 2k): */
    439     typedef bool (*MonitorEnumProcFP)(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lpClipRect, LPARAM dwData);
    440     typedef bool (*EnumDisplayMonitorsFP)(HDC hdc, LPCRECT lprcRect, MonitorEnumProcFP lpfnEnum, LPARAM dwData);
    441     EnumDisplayMonitorsFP EnumDisplayMonitorsF = (EnumDisplayMonitorsFP)user32.resolve("EnumDisplayMonitors");
    442     if (EnumDisplayMonitorsF)
     434    /* Dynamically resolve EnumDisplayMonitors (available since Windows 2k) first time through: */
     435    static bool volatile                  s_fResolved = false;
     436    static decltype(EnumDisplayMonitors) *s_pfnEnumDisplayMonitors = NULL;
     437    decltype(EnumDisplayMonitors)        *pfnEnumDisplayMonitors;
     438    if (s_fResolved)
     439        pfnEnumDisplayMonitors = s_pfnEnumDisplayMonitors;
     440    else
     441    {
     442        pfnEnumDisplayMonitors = (decltype(EnumDisplayMonitors) *)GetProcAddress(GetModuleHandleW(L"USER32.DLL"),
     443                                                                                 "EnumDisplayMonitors");
     444        s_pfnEnumDisplayMonitors = pfnEnumDisplayMonitors;
     445        s_fResolved = true;
     446    }
     447
     448    /* Enumerate available monitors through EnumDisplayMonitors if available: */
     449    if (pfnEnumDisplayMonitors)
    443450    {
    444451        QList<QPair<int, int> > listOfScreenDPI;
    445         EnumDisplayMonitorsF(0, 0, MonitorEnumProcF, (LPARAM)&listOfScreenDPI);
     452        pfnEnumDisplayMonitors(0, 0, MonitorEnumProcF, (LPARAM)&listOfScreenDPI);
    446453        if (iHostScreenIndex >= 0 && iHostScreenIndex < listOfScreenDPI.size())
    447454        {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette