VirtualBox

Ignore:
Timestamp:
May 2, 2016 11:41:08 AM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106982
Message:

SharedClipboard: vboxOpenClipboard cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp

    r60772 r60784  
    9999{
    100100    /* "OpenClipboard fails if another window has the clipboard open."
    101     * So try a few times and wait up to 1 second.
    102     */
    103     int rc;
    104 
    105     uint32_t u32SleepMS = 1;
    106     int i;
    107     for (i = 0; i <= 9; ++i) /* u32SleepMS = [1..512] */
     101     * So try a few times and wait up to 1 second.
     102     */
     103    BOOL fOpened = FALSE;
     104
     105    int i = 0;
     106    for (;;)
    108107    {
    109108        if (OpenClipboard(hwnd))
    110109        {
    111             rc = 0;
     110            fOpened = TRUE;
    112111            break;
    113112        }
    114         rc = RTErrConvertFromWin32(GetLastError());
    115        
    116         RTThreadSleep(u32SleepMS);
    117         u32SleepMS <<= 1;
    118     }
     113
     114        if (i >= 10) /* sleep interval = [1..512] ms */
     115            break;
     116
     117        RTThreadSleep(1 << i);
     118        ++i;
     119    }
     120
    119121#ifdef LOG_ENABLED
    120122    if (i > 0)
    121         LogFlow(("vboxOpenClipboard: %d times tried to open clipboard. \n", ++i));
     123        LogFlowFunc(("%d times tried to open clipboard.\n", i + 1));
    122124#endif
     125
     126    int rc;
     127    if (fOpened)
     128        rc = VINF_SUCCESS;
     129    else
     130    {
     131        const DWORD err = GetLastError();
     132        LogFlowFunc(("error %d\n", err));
     133        rc = RTErrConvertFromWin32(err);
     134    }
     135
    123136    return rc;
    124137}
     
    131144    /* Query list of available formats and report to host. */
    132145    int rc = vboxOpenClipboard(pCtx->hwnd);
    133     if(RT_SUCCESS(rc))
     146    if (RT_SUCCESS(rc))
    134147    {
    135148        uint32_t u32Formats = 0;
     
    502515             * windows is to be destroyed and therefore the guest side becomes inactive.
    503516             */
    504             int res = vboxOpenClipboard(hwnd);
    505             if (RT_SUCCESS(res))
     517            int vboxrc = vboxOpenClipboard(hwnd);
     518            if (RT_SUCCESS(vboxrc))
    506519            {
    507520                EmptyClipboard();
     
    510523            else
    511524            {
    512                 LogFlowFunc(("WM_RENDERALLFORMATS: Failed to open clipboard! rc: %Rrc\n", res));
     525                LogFlowFunc(("WM_RENDERALLFORMATS: Failed to open clipboard! rc: %Rrc\n", vboxrc));
    513526            }
    514527        } break;
     
    519532            uint32_t u32Formats = (uint32_t)lParam;
    520533           
    521             int res = vboxOpenClipboard(hwnd);
    522             if(RT_SUCCESS(res))
     534            int vboxrc = vboxOpenClipboard(hwnd);
     535            if (RT_SUCCESS(vboxrc))
    523536            {
    524537                EmptyClipboard();
     
    553566            else
    554567            {
    555                 LogFlowFunc(("WM_USER: Failed to open clipboard! error = %Rrc\n", res));
     568                LogFlowFunc(("WM_USER: Failed to open clipboard! error = %Rrc\n", vboxrc));
    556569            }
    557570        } break;
     
    563576            HANDLE hClip = NULL;
    564577
    565             int res = vboxOpenClipboard(hwnd);
    566             if (RT_SUCCESS(res))
    567             {
    568                 int vboxrc;
     578            int vboxrc = vboxOpenClipboard(hwnd);
     579            if (RT_SUCCESS(vboxrc))
     580            {
    569581                if (u32Formats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP)
    570582                {
     
    637649            else
    638650            {
    639                 LogFlowFunc(("WM_USER: Failed to open clipboard! rc: %Rrc\n", res));
     651                LogFlowFunc(("WM_USER: Failed to open clipboard! rc: %Rrc\n", vboxrc));
    640652            }
    641653
Note: See TracChangeset for help on using the changeset viewer.

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