VirtualBox

Changeset 97282 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 24, 2022 4:24:15 PM (2 years ago)
Author:
vboxsync
Message:

Shared Clipboard/Service: Factored out and renamed vboxClipboardSvcWinDataSet() into common Shared Clipboard Windows code to SharedClipboardWinDataWrite(), to also make use of such basic functionality in i.e. the unit tests.

Location:
trunk/src/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp

    r96407 r97282  
    937937}
    938938
     939/**
     940 * Writes (places) clipboard data into the Windows clipboard.
     941 *
     942 * @returns VBox status code.
     943 * @param   cfFormat            Windows clipboard format to write data for.
     944 * @param   pvData              Pointer to actual clipboard data to write.
     945 * @param   cbData              Size (in bytes) of actual clipboard data to write.
     946 *
     947 * @note    ASSUMES that the clipboard has already been opened.
     948 */
     949int SharedClipboardWinDataWrite(UINT cfFormat, void *pvData, uint32_t cbData)
     950{
     951    AssertPtrReturn(pvData, VERR_INVALID_POINTER);
     952    AssertReturn   (cbData, VERR_INVALID_PARAMETER);
     953
     954    int rc = VINF_SUCCESS;
     955
     956    HANDLE hMem = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, cbData);
     957
     958    LogFlowFunc(("hMem=%p\n", hMem));
     959
     960    if (hMem)
     961    {
     962        void *pMem = GlobalLock(hMem);
     963
     964        LogFlowFunc(("pMem=%p, GlobalSize=%zu\n", pMem, GlobalSize(hMem)));
     965
     966        if (pMem)
     967        {
     968            LogFlowFunc(("Setting data\n"));
     969
     970            memcpy(pMem, pvData, cbData);
     971
     972            /* The memory must be unlocked before inserting to the Clipboard. */
     973            GlobalUnlock(hMem);
     974
     975            /* 'hMem' contains the host clipboard data.
     976             * size is 'cb' and format is 'format'.
     977             */
     978            HANDLE hClip = SetClipboardData(cfFormat, hMem);
     979
     980            LogFlowFunc(("hClip=%p\n", hClip));
     981
     982            if (hClip)
     983            {
     984                /* The hMem ownership has gone to the system. Nothing to do. */
     985            }
     986            else
     987                rc = RTErrConvertFromWin32(GetLastError());
     988        }
     989        else
     990            rc = VERR_ACCESS_DENIED;
     991
     992        GlobalFree(hMem);
     993    }
     994    else
     995        rc = RTErrConvertFromWin32(GetLastError());
     996
     997    if (RT_FAILURE(rc))
     998        LogFunc(("Setting clipboard data failed with %Rrc\n", rc));
     999
     1000    LogFlowFuncLeaveRC(rc);
     1001    return rc;
     1002}
     1003
    9391004#ifdef VBOX_WITH_SHARED_CLIPBOARD_TRANSFERS
    9401005
  • trunk/src/VBox/HostServices/SharedClipboard/VBoxSharedClipboardSvc-win.cpp

    r97239 r97282  
    152152}
    153153
    154 /**
    155  * Sets (places) clipboard data into the Windows clipboard.
    156  *
    157  * @returns VBox status code.
    158  * @param   pCtx                Shared Clipboard context to use.
    159  * @param   cfFormat            Windows clipboard format to set data for.
    160  * @param   pvData              Pointer to actual clipboard data to set.
    161  * @param   cbData              Size (in bytes) of actual clipboard data to set.
    162  * @note
    163  */
    164 static int vboxClipboardSvcWinDataSet(PSHCLCONTEXT pCtx, UINT cfFormat, void *pvData, uint32_t cbData)
    165 {
    166     AssertPtrReturn(pCtx,   VERR_INVALID_POINTER);
    167     AssertPtrReturn(pvData, VERR_INVALID_POINTER);
    168     AssertReturn   (cbData, VERR_INVALID_PARAMETER);
    169 
    170     int rc = VINF_SUCCESS;
    171 
    172     HANDLE hMem = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, cbData);
    173 
    174     LogFlowFunc(("hMem=%p\n", hMem));
    175 
    176     if (hMem)
    177     {
    178         void *pMem = GlobalLock(hMem);
    179 
    180         LogFlowFunc(("pMem=%p, GlobalSize=%zu\n", pMem, GlobalSize(hMem)));
    181 
    182         if (pMem)
    183         {
    184             LogFlowFunc(("Setting data\n"));
    185 
    186             memcpy(pMem, pvData, cbData);
    187 
    188             /* The memory must be unlocked before inserting to the Clipboard. */
    189             GlobalUnlock(hMem);
    190 
    191             /* 'hMem' contains the host clipboard data.
    192              * size is 'cb' and format is 'format'.
    193              */
    194             HANDLE hClip = SetClipboardData(cfFormat, hMem);
    195 
    196             LogFlowFunc(("hClip=%p\n", hClip));
    197 
    198             if (hClip)
    199             {
    200                 /* The hMem ownership has gone to the system. Nothing to do. */
    201             }
    202             else
    203                 rc = RTErrConvertFromWin32(GetLastError());
    204         }
    205         else
    206             rc = VERR_ACCESS_DENIED;
    207 
    208         GlobalFree(hMem);
    209     }
    210     else
    211         rc = RTErrConvertFromWin32(GetLastError());
    212 
    213     if (RT_FAILURE(rc))
    214         LogRel(("Shared Clipboard: Setting clipboard data for Windows host failed with %Rrc\n", rc));
    215 
    216     LogFlowFuncLeaveRC(rc);
    217     return rc;
    218 }
    219 
    220154static int vboxClipboardSvcWinDataRead(PSHCLCONTEXT pCtx, UINT uFormat, void **ppvData, uint32_t *pcbData)
    221155{
     
    384318                    }
    385319
    386                     rc = vboxClipboardSvcWinDataSet(pCtx, uFormat, pvData, cbData);
     320                    rc = SharedClipboardWinDataWrite(uFormat, pvData, cbData);
     321                    if (RT_FAILURE(rc))
     322                        LogRel(("Shared Clipboard: Setting clipboard data for Windows host failed with %Rrc\n", rc));
    387323
    388324                    RTMemFree(pvData);
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