VirtualBox

Changeset 97282 in vbox for trunk/src/VBox/HostServices


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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