Changeset 81025 in vbox for trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp
- Timestamp:
- Sep 26, 2019 4:13:25 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/SharedClipboard/clipboard-win.cpp
r80966 r81025 181 181 if (!pWinCtx) 182 182 return; 183 184 LogFlowFuncEnter(); 183 185 184 186 if (RTCritSectIsInitialized(&pWinCtx->CritSect)) … … 894 896 AssertPtrReturn(pTransfer, VERR_INVALID_POINTER); 895 897 896 LogFlowFuncEnter(); 897 898 int rc; 898 LogFlowFunc(("pWinCtx=%p\n", pWinCtx)); 899 899 900 900 AssertReturn(pTransfer->pvUser == NULL, VERR_WRONG_ORDER); 901 901 902 SharedClipboardWinTransferCtx *pWinURITransferCtx = new SharedClipboardWinTransferCtx(); 903 if (pWinURITransferCtx) 904 { 905 pTransfer->pvUser = pWinURITransferCtx; 906 pTransfer->cbUser = sizeof(SharedClipboardWinTransferCtx); 907 908 pWinURITransferCtx->pDataObj = new SharedClipboardWinDataObject(pTransfer); 909 if (pWinURITransferCtx->pDataObj) 910 { 911 rc = pWinURITransferCtx->pDataObj->Init(); 912 if (RT_SUCCESS(rc)) 902 /* Make sure to enter the critical section before setting the clipboard data, as otherwise WM_CLIPBOARDUPDATE 903 * might get called *before* we had the opportunity to set pWinCtx->hWndClipboardOwnerUs below. */ 904 int rc = RTCritSectEnter(&pWinCtx->CritSect); 905 if (RT_SUCCESS(rc)) 906 { 907 SharedClipboardWinTransferCtx *pWinURITransferCtx = new SharedClipboardWinTransferCtx(); 908 if (pWinURITransferCtx) 909 { 910 pTransfer->pvUser = pWinURITransferCtx; 911 pTransfer->cbUser = sizeof(SharedClipboardWinTransferCtx); 912 913 pWinURITransferCtx->pDataObj = new SharedClipboardWinDataObject(pTransfer); 914 if (pWinURITransferCtx->pDataObj) 913 915 { 914 SharedClipboardWinClose(); 915 /* Note: Clipboard must be closed first before calling OleSetClipboard(). */ 916 917 /** @todo There is a potential race between SharedClipboardWinClose() and OleSetClipboard(), 918 * where another application could own the clipboard (open), and thus the call to 919 * OleSetClipboard() will fail. Needs (better) fixing. */ 920 HRESULT hr = S_OK; 921 922 for (unsigned uTries = 0; uTries < 3; uTries++) 916 rc = pWinURITransferCtx->pDataObj->Init(); 917 if (RT_SUCCESS(rc)) 923 918 { 924 /* Make sure to enter the critical section before setting the clipboard data, as otherwise WM_CLIPBOARDUPDATE 925 * might get called *before* we had the opportunity to set pWinCtx->hWndClipboardOwnerUs below. */ 926 rc = RTCritSectEnter(&pWinCtx->CritSect); 927 if (RT_SUCCESS(rc)) 919 SharedClipboardWinClose(); 920 /* Note: Clipboard must be closed first before calling OleSetClipboard(). */ 921 922 /** @todo There is a potential race between SharedClipboardWinClose() and OleSetClipboard(), 923 * where another application could own the clipboard (open), and thus the call to 924 * OleSetClipboard() will fail. Needs (better) fixing. */ 925 HRESULT hr = S_OK; 926 927 for (unsigned uTries = 0; uTries < 3; uTries++) 928 928 { 929 929 hr = OleSetClipboard(pWinURITransferCtx->pDataObj); … … 939 939 pWinCtx->hWndClipboardOwnerUs = GetClipboardOwner(); 940 940 941 rc = RTCritSectLeave(&pWinCtx->CritSect); 942 AssertRC(rc); 941 LogFlowFunc(("hWndClipboardOwnerUs=%p\n", pWinCtx->hWndClipboardOwnerUs)); 943 942 break; 944 943 } 944 945 LogFlowFunc(("Failed with %Rhrc (try %u/3)\n", hr, uTries + 1)); 946 RTThreadSleep(500); /* Wait a bit. */ 945 947 } 946 948 947 rc = RTCritSectLeave(&pWinCtx->CritSect); 948 AssertRCBreak(rc); 949 950 LogFlowFunc(("Failed with %Rhrc (try %u/3)\n", hr, uTries + 1)); 951 RTThreadSleep(500); /* Wait a bit. */ 952 } 953 954 if (FAILED(hr)) 955 { 956 rc = VERR_ACCESS_DENIED; /** @todo Fudge; fix this. */ 957 LogRel(("Shared Clipboard: Failed with %Rhrc when setting data object to clipboard\n", hr)); 949 if (FAILED(hr)) 950 { 951 rc = VERR_ACCESS_DENIED; /** @todo Fudge; fix this. */ 952 LogRel(("Shared Clipboard: Failed with %Rhrc when setting data object to clipboard\n", hr)); 953 } 958 954 } 959 955 } 956 else 957 rc = VERR_NO_MEMORY; 960 958 } 961 959 else 962 960 rc = VERR_NO_MEMORY; 963 } 964 else 965 rc = VERR_NO_MEMORY; 961 962 int rc2 = RTCritSectLeave(&pWinCtx->CritSect); 963 AssertRC(rc2); 964 } 966 965 967 966 LogFlowFuncLeaveRC(rc);
Note:
See TracChangeset
for help on using the changeset viewer.