Changeset 26742 in vbox for trunk/src/VBox/Additions/WINNT/VBoxTray
- Timestamp:
- Feb 24, 2010 12:51:09 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxTray/VBoxClipboard.cpp
r24320 r26742 6 6 7 7 /* 8 * Copyright (C) 2006-20 07Sun Microsystems, Inc.8 * Copyright (C) 2006-2010 Sun Microsystems, Inc. 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 22 22 23 23 #include "VBoxTray.h" 24 #include "helpers.h" 25 24 26 #include <VBox/HostServices/VBoxClipboardSvc.h> 25 #include "helpers.h"26 #include <iprt/asm.h>27 27 #include <strsafe.h> 28 28 … … 46 46 } VBOXCLIPBOARDCONTEXT; 47 47 48 49 48 static char gachWindowClassName[] = "VBoxSharedClipboardClass"; 50 49 51 50 52 #define VBOX_INIT_CALL(__a, __b, __c) do { \ 53 (__a)->hdr.result = VINF_SUCCESS; \ 54 (__a)->hdr.u32ClientID = (__c)->u32ClientID; \ 55 (__a)->hdr.u32Function = (__b); \ 56 (__a)->hdr.cParms = (sizeof (*(__a)) - sizeof ((__a)->hdr)) / sizeof (HGCMFunctionParameter); \ 57 } while (0) 58 59 60 //static bool vboxClipboardIsSameAsLastSent (VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format, 61 // void *pv, uint32_t cb) 62 //{ 63 // uint64_t u64CRC = RTCrc64 (pv, cb); 64 // 65 // if ( pCtx->u32LastSentFormat == u32Format 66 // && pCtx->u64LastSentCRC64 == u64CRC) 67 // { 68 // return true; 69 // } 70 // 71 // pCtx->u64LastSentCRC64 = u64CRC; 72 // pCtx->u32LastSentFormat = u32Format; 73 // 74 // return false; 75 //} 76 77 static int vboxClipboardConnect (VBOXCLIPBOARDCONTEXT *pCtx) 78 { 79 VBoxGuestHGCMConnectInfo info; 80 81 RT_ZERO (info); 82 83 info.Loc.type = VMMDevHGCMLoc_LocalHost_Existing; 84 85 memcpy (info.Loc.u.host.achName, "VBoxSharedClipboard", sizeof ("VBoxSharedClipboard")); 86 87 DWORD cbReturned; 88 89 if (DeviceIoControl (pCtx->pEnv->hDriver, 90 VBOXGUEST_IOCTL_HGCM_CONNECT, 91 &info, sizeof (info), 92 &info, sizeof (info), 93 &cbReturned, 94 NULL)) 95 { 96 if (info.result == VINF_SUCCESS) 97 { 98 pCtx->u32ClientID = info.u32ClientID; 99 } 51 static int vboxClipboardChanged(VBOXCLIPBOARDCONTEXT *pCtx) 52 { 53 AssertPtr(pCtx); 54 55 /* Query list of available formats and report to host. */ 56 int rc = VINF_SUCCESS; 57 if (FALSE == OpenClipboard(pCtx->hwnd)) 58 { 59 rc = RTErrConvertFromWin32(GetLastError()); 100 60 } 101 61 else 102 62 { 103 info.result = VERR_NOT_SUPPORTED;104 }105 106 return info.result;107 }108 109 static void vboxClipboardDisconnect (VBOXCLIPBOARDCONTEXT *pCtx)110 {111 if (pCtx->u32ClientID == 0)112 {113 return;114 }115 116 VBoxGuestHGCMDisconnectInfo info;117 118 RT_ZERO (info);119 120 info.u32ClientID = pCtx->u32ClientID;121 122 DWORD cbReturned;123 124 DeviceIoControl (pCtx->pEnv->hDriver,125 VBOXGUEST_IOCTL_HGCM_DISCONNECT,126 &info, sizeof (info),127 &info, sizeof (info),128 &cbReturned,129 NULL);130 131 return;132 }133 134 135 static void VBoxHGCMParmUInt32Set (HGCMFunctionParameter *pParm, uint32_t u32)136 {137 pParm->type = VMMDevHGCMParmType_32bit;138 pParm->u.value32 = u32;139 }140 141 static int VBoxHGCMParmUInt32Get (HGCMFunctionParameter *pParm, uint32_t *pu32)142 {143 if (pParm->type == VMMDevHGCMParmType_32bit)144 {145 *pu32 = pParm->u.value32;146 return VINF_SUCCESS;147 }148 149 return VERR_INVALID_PARAMETER;150 }151 152 static void VBoxHGCMParmPtrSet (HGCMFunctionParameter *pParm, void *pv, uint32_t cb)153 {154 pParm->type = VMMDevHGCMParmType_LinAddr;155 pParm->u.Pointer.size = cb;156 pParm->u.Pointer.u.linearAddr = (uintptr_t)pv;157 }158 159 160 static int vboxCall (HANDLE hDriver, void *pvData, unsigned cbData)161 {162 DWORD cbReturned;163 164 if (DeviceIoControl (hDriver,165 VBOXGUEST_IOCTL_HGCM_CALL(cbData),166 pvData, cbData,167 pvData, cbData,168 &cbReturned,169 NULL))170 {171 return VINF_SUCCESS;172 }173 174 return VERR_NOT_SUPPORTED;175 }176 177 static int vboxClipboardReportFormats (VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Formats)178 {179 VBoxClipboardFormats parms;180 181 VBOX_INIT_CALL(&parms, VBOX_SHARED_CLIPBOARD_FN_FORMATS, pCtx);182 183 VBoxHGCMParmUInt32Set (&parms.formats, u32Formats);184 185 int rc = vboxCall (pCtx->pEnv->hDriver, &parms, sizeof (parms));186 187 if (RT_SUCCESS (rc))188 {189 rc = parms.hdr.result;190 }191 192 return rc;193 }194 195 static int vboxClipboardReadData (VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format, void *pv, uint32_t cb, uint32_t *pcbActual)196 {197 VBoxClipboardReadData parms;198 199 VBOX_INIT_CALL(&parms, VBOX_SHARED_CLIPBOARD_FN_READ_DATA, pCtx);200 201 VBoxHGCMParmUInt32Set (&parms.format, u32Format);202 VBoxHGCMParmPtrSet (&parms.ptr, pv, cb);203 VBoxHGCMParmUInt32Set (&parms.size, 0);204 205 int rc = vboxCall (pCtx->pEnv->hDriver, &parms, sizeof (parms));206 207 if (RT_SUCCESS (rc))208 {209 rc = parms.hdr.result;210 211 if (RT_SUCCESS (rc))212 {213 uint32_t u32Size;214 215 rc = VBoxHGCMParmUInt32Get (&parms.size, &u32Size);216 217 Log (("vboxClipboardReadData: actual size = %d, rc = %d\n", u32Size, rc));218 219 if (RT_SUCCESS (rc))220 {221 if (pcbActual)222 {223 *pcbActual = u32Size;224 }225 }226 }227 }228 229 return rc;230 }231 232 static int vboxClipboardWriteData (VBOXCLIPBOARDCONTEXT *pCtx, uint32_t u32Format,233 void *pv, uint32_t cb)234 {235 // if (vboxClipboardIsSameAsLastSent (pCtx, u32Format, pv, cb))236 // {237 // Log (("vboxClipboardWriteData: The data to be sent are the same as the last sent.\n"));238 // return VINF_SUCCESS;239 // }240 241 VBoxClipboardWriteData parms;242 243 VBOX_INIT_CALL(&parms, VBOX_SHARED_CLIPBOARD_FN_WRITE_DATA, pCtx);244 245 VBoxHGCMParmUInt32Set (&parms.format, u32Format);246 VBoxHGCMParmPtrSet (&parms.ptr, pv, cb);247 248 int rc = vboxCall (pCtx->pEnv->hDriver, &parms, sizeof (parms));249 250 if (RT_SUCCESS (rc))251 {252 rc = parms.hdr.result;253 }254 255 return rc;256 }257 258 static void vboxClipboardChanged (VBOXCLIPBOARDCONTEXT *pCtx)259 {260 /* Query list of available formats and report to host. */261 if (OpenClipboard (pCtx->hwnd))262 {263 63 uint32_t u32Formats = 0; 264 265 64 UINT format = 0; 266 65 267 66 while ((format = EnumClipboardFormats (format)) != 0) 268 67 { 269 Log (("vboxClipboardChanged: format 0x%08X\n", format));68 Log (("vboxClipboardChanged: format = 0x%08X\n", format)); 270 69 switch (format) 271 70 { … … 286 85 287 86 int cActual = GetClipboardFormatName(format, szFormatName, sizeof(szFormatName)/sizeof (TCHAR)); 288 289 87 if (cActual) 290 88 { … … 300 98 301 99 CloseClipboard (); 302 303 vboxClipboardReportFormats (pCtx, u32Formats);304 }100 rc = VbglR3ClipboardReportFormats(pCtx->u32ClientID, u32Formats); 101 } 102 return rc; 305 103 } 306 104 … … 330 128 { 331 129 /* Pass the message further. */ 332 rc = SendMessage 130 rc = SendMessage(pCtx->hwndNextInChain, WM_CHANGECBCHAIN, wParam, lParam); 333 131 } 334 132 } … … 342 140 { 343 141 /* Clipboard was updated by another application. */ 344 vboxClipboardChanged (pCtx);142 vboxClipboardChanged(pCtx); /** @todo r=andy Check for return code! */ 345 143 } 346 144 347 145 /* Pass the message to next windows in the clipboard chain. */ 348 rc = SendMessage 146 rc = SendMessage(pCtx->hwndNextInChain, msg, wParam, lParam); 349 147 } break; 350 148 … … 358 156 /* Insert the requested clipboard format data into the clipboard. */ 359 157 uint32_t u32Format = 0; 360 361 158 UINT format = (UINT)wParam; 362 159 363 Log (("vboxClipboardProcessMsg: WM_RENDERFORMAT, format %x\n", format)); 364 160 Log (("vboxClipboardProcessMsg: WM_RENDERFORMAT, format = %x\n", format)); 365 161 switch (format) 366 162 { … … 394 190 { 395 191 /* Unsupported clipboard format is requested. */ 396 EmptyClipboard (); 192 Log(("vboxClipboardProcessMsg: Unsupported clipboard format requested: %ld\n", u32Format)); 193 EmptyClipboard(); 397 194 } 398 195 else 399 196 { 400 const uint32_t cbPrealloc = 4096; 197 const uint32_t cbPrealloc = 4096; /* @todo r=andy Make it dynamic for supporting larger text buffers! */ 401 198 uint32_t cb = 0; 402 199 403 200 /* Preallocate a buffer, most of small text transfers will fit into it. */ 404 HANDLE hMem = GlobalAlloc 405 Log((" hMem%p\n", hMem));201 HANDLE hMem = GlobalAlloc(GMEM_DDESHARE | GMEM_MOVEABLE, cbPrealloc); 202 Log(("vboxClipboardProcessMsg: Preallocated handle hMem = %p\n", hMem)); 406 203 407 204 if (hMem) 408 205 { 409 void *pMem = GlobalLock 410 Log((" pMem %p, GlobalSize %d\n", pMem, GlobalSize(hMem)));206 void *pMem = GlobalLock(hMem); 207 Log(("vboxClipboardProcessMsg: Locked pMem = %p, GlobalSize = %ld\n", pMem, GlobalSize(hMem))); 411 208 412 209 if (pMem) 413 210 { 414 211 /* Read the host data to the preallocated buffer. */ 415 int vboxrc = vboxClipboardReadData (pCtx, u32Format, pMem, cbPrealloc, &cb);416 Log(("vboxClipboard ReadData vboxrc %d\n", vboxrc));417 418 if (RT_SUCCESS 212 int vboxrc = VbglR3ClipboardReadData(pCtx->u32ClientID, u32Format, pMem, cbPrealloc, &cb); 213 Log(("vboxClipboardProcessMsg: VbglR3ClipboardReadData returned with rc = %Rrc\n", vboxrc)); 214 215 if (RT_SUCCESS(vboxrc)) 419 216 { 420 217 if (cb == 0) … … 424 221 * the clipboard empty code path. 425 222 */ 426 GlobalUnlock 427 GlobalFree 223 GlobalUnlock(hMem); 224 GlobalFree(hMem); 428 225 hMem = NULL; 429 226 } 430 227 else if (cb > cbPrealloc) 431 228 { 432 GlobalUnlock 229 GlobalUnlock(hMem); 433 230 434 231 /* The preallocated buffer is too small, adjust the size. */ 435 hMem = GlobalReAlloc 436 Log((" hMem%p\n", hMem));232 hMem = GlobalReAlloc(hMem, cb, 0); 233 Log(("vboxClipboardProcessMsg: Reallocated hMem = %p\n", hMem)); 437 234 438 235 if (hMem) 439 236 { 440 pMem = GlobalLock 441 Log((" pMem %p, GlobalSize %d\n", pMem, GlobalSize(hMem)));237 pMem = GlobalLock(hMem); 238 Log(("vboxClipboardProcessMsg: Locked pMem = %p, GlobalSize = %ld\n", pMem, GlobalSize(hMem))); 442 239 443 240 if (pMem) … … 445 242 /* Read the host data to the preallocated buffer. */ 446 243 uint32_t cbNew = 0; 447 vboxrc = vboxClipboardReadData (pCtx, u32Format, pMem, cb, &cbNew);448 Log((" vboxClipboardReadData vboxrc %d, cb = %d, cbNew = %d\n", vboxrc, cb, cbNew));244 vboxrc = VbglR3ClipboardReadData(pCtx->u32ClientID, u32Format, pMem, cb, &cbNew); 245 Log(("VbglR3ClipboardReadData returned with rc = %Rrc, cb = %d, cbNew = %d\n", vboxrc, cb, cbNew)); 449 246 450 247 if (RT_SUCCESS (vboxrc) && cbNew <= cb) … … 454 251 else 455 252 { 456 GlobalUnlock 457 GlobalFree 253 GlobalUnlock(hMem); 254 GlobalFree(hMem); 458 255 hMem = NULL; 459 256 } … … 461 258 else 462 259 { 463 GlobalFree 260 GlobalFree(hMem); 464 261 hMem = NULL; 465 262 } … … 476 273 { 477 274 size_t cbActual = 0; 478 HRESULT hrc = StringCbLengthW 275 HRESULT hrc = StringCbLengthW((LPWSTR)pMem, cb, &cbActual); 479 276 if (FAILED (hrc)) 480 277 { 481 278 /* Discard invalid data. */ 482 GlobalUnlock 483 GlobalFree 279 GlobalUnlock(hMem); 280 GlobalFree(hMem); 484 281 hMem = NULL; 485 282 } … … 496 293 if (hMem) 497 294 { 498 GlobalUnlock 499 500 hMem = GlobalReAlloc 501 Log((" hMem%p\n", hMem));295 GlobalUnlock(hMem); 296 297 hMem = GlobalReAlloc(hMem, cb, 0); 298 Log(("vboxClipboardProcessMsg: Reallocated hMem = %p\n", hMem)); 502 299 503 300 if (hMem) … … 507 304 */ 508 305 HANDLE hClip = SetClipboardData (format, hMem); 509 Log((" WM_RENDERFORMAT hClip%p\n", hClip));306 Log(("vboxClipboardProcessMsg: WM_RENDERFORMAT hClip = %p\n", hClip)); 510 307 511 308 if (hClip) … … 522 319 if (hMem) 523 320 { 524 GlobalUnlock 321 GlobalUnlock(hMem); 525 322 } 526 323 } … … 528 325 if (hMem) 529 326 { 530 GlobalFree 327 GlobalFree(hMem); 531 328 } 532 329 } 533 330 534 331 /* Something went wrong. */ 535 EmptyClipboard 332 EmptyClipboard(); 536 333 } 537 334 } break; … … 545 342 { 546 343 EmptyClipboard(); 547 548 344 CloseClipboard(); 549 345 } … … 555 351 uint32_t u32Formats = (uint32_t)lParam; 556 352 557 if (OpenClipboard (hwnd)) 353 if (FALSE == OpenClipboard (hwnd)) 354 { 355 Log(("vboxClipboardProcessMsg: WM_USER: Failed to open clipboard! Last error = %ld\n", GetLastError())); 356 } 357 else 558 358 { 559 359 EmptyClipboard(); … … 563 363 if (u32Formats & VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 564 364 { 565 Log(("window proc WM_USER: VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT\n")); 566 567 hClip = SetClipboardData (CF_UNICODETEXT, NULL); 365 Log(("vboxClipboardProcessMsg: WM_USER: VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT\n")); 366 hClip = SetClipboardData(CF_UNICODETEXT, NULL); 568 367 } 569 368 570 369 if (u32Formats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP) 571 370 { 572 Log(("window proc WM_USER: VBOX_SHARED_CLIPBOARD_FMT_BITMAP\n")); 573 574 hClip = SetClipboardData (CF_DIB, NULL); 371 Log(("vboxClipboardProcessMsg: WM_USER: VBOX_SHARED_CLIPBOARD_FMT_BITMAP\n")); 372 hClip = SetClipboardData(CF_DIB, NULL); 575 373 } 576 374 … … 578 376 { 579 377 UINT format = RegisterClipboardFormat ("HTML Format"); 580 Log((" window procWM_USER: VBOX_SHARED_CLIPBOARD_FMT_HTML 0x%04X\n", format));378 Log(("vboxClipboardProcessMsg: WM_USER: VBOX_SHARED_CLIPBOARD_FMT_HTML 0x%04X\n", format)); 581 379 if (format != 0) 582 380 { 583 hClip = SetClipboardData 381 hClip = SetClipboardData(format, NULL); 584 382 } 585 383 } 586 384 587 385 CloseClipboard(); 588 589 Log(("window proc WM_USER: hClip %p, err %d\n", hClip, GetLastError ())); 590 } 591 else 592 { 593 Log(("window proc WM_USER: failed to open clipboard\n")); 386 Log(("vboxClipboardProcessMsg: WM_USER: hClip = %p, err = %ld\n", hClip, GetLastError ())); 594 387 } 595 388 } break; … … 602 395 HANDLE hClip = NULL; 603 396 604 if (OpenClipboard (hwnd)) 605 { 397 if (FALSE == OpenClipboard(hwnd)) 398 { 399 } 400 else 401 { 402 int vboxrc; 606 403 if (u32Formats & VBOX_SHARED_CLIPBOARD_FMT_BITMAP) 607 404 { 608 hClip = GetClipboardData 405 hClip = GetClipboardData(CF_DIB); 609 406 610 407 if (hClip != NULL) 611 408 { 612 LPVOID lp = GlobalLock (hClip); 613 409 LPVOID lp = GlobalLock(hClip); 614 410 if (lp != NULL) 615 411 { 616 Log(("CF_DIB\n")); 617 618 vboxClipboardWriteData (pCtx, VBOX_SHARED_CLIPBOARD_FMT_BITMAP, 619 lp, GlobalSize (hClip)); 620 412 Log(("vboxClipboardProcessMsg: WM_USER + 1: CF_DIB\n")); 413 vboxrc = VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_BITMAP, 414 lp, GlobalSize(hClip)); 621 415 GlobalUnlock(hClip); 622 416 } … … 637 431 if (uniString != NULL) 638 432 { 639 Log(("CF_UNICODETEXT\n")); 640 641 vboxClipboardWriteData (pCtx, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, 642 uniString, (lstrlenW (uniString) + 1) * 2); 643 433 Log(("vboxClipboardProcessMsg: WM_USER + 1: CF_UNICODETEXT\n")); 434 vboxrc = VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT, 435 uniString, (lstrlenW(uniString) + 1) * 2); 644 436 GlobalUnlock(hClip); 645 437 } … … 653 445 { 654 446 UINT format = RegisterClipboardFormat ("HTML Format"); 655 656 447 if (format != 0) 657 448 { 658 449 hClip = GetClipboardData (format); 659 660 450 if (hClip != NULL) 661 451 { … … 664 454 if (lp != NULL) 665 455 { 666 Log(("CF_HTML\n")); 667 668 vboxClipboardWriteData (pCtx, VBOX_SHARED_CLIPBOARD_FMT_HTML, 669 lp, GlobalSize (hClip)); 670 456 Log(("vboxClipboardProcessMsg: WM_USER + 1: CF_HTML\n")); 457 vboxrc = VbglR3ClipboardWriteData(pCtx->u32ClientID, VBOX_SHARED_CLIPBOARD_FMT_HTML, 458 lp, GlobalSize(hClip)); 671 459 GlobalUnlock(hClip); 672 460 } … … 685 473 { 686 474 /* Requested clipboard format is not available, send empty data. */ 687 vboxClipboardWriteData (pCtx, 0, NULL, 0);475 VbglR3ClipboardWriteData(pCtx->u32ClientID, 0, NULL, 0); 688 476 } 689 477 } break; … … 702 490 static int vboxClipboardInit (VBOXCLIPBOARDCONTEXT *pCtx) 703 491 { 704 int rc = VINF_SUCCESS;705 706 492 /* Register the Window Class. */ 707 493 WNDCLASS wc; … … 720 506 pCtx->atomWindowClass = RegisterClass (&wc); 721 507 508 int rc = VINF_SUCCESS; 722 509 if (pCtx->atomWindowClass == 0) 723 510 { … … 745 532 } 746 533 534 Log(("vboxClipboardInit returned with rc = %Rrc\n", rc)); 747 535 return rc; 748 536 } … … 775 563 } 776 564 777 int VBoxClipboardInit (const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread) 778 { 779 int rc = VINF_SUCCESS; 780 565 int VBoxClipboardInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread) 566 { 781 567 Log (("VboxClipboardInit\n")); 782 783 568 if (gCtx.pEnv) 784 569 { … … 788 573 789 574 RT_ZERO (gCtx); 790 791 575 gCtx.pEnv = pEnv; 792 576 793 rc = vboxClipboardConnect (&gCtx); 794 577 int rc = VbglR3ClipboardConnect(&gCtx.u32ClientID); 795 578 if (RT_SUCCESS (rc)) 796 579 { 797 rc = vboxClipboardInit (&gCtx); 798 799 Log (("vboxClipboardInit: rc = %d\n", rc)); 800 580 rc = vboxClipboardInit(&gCtx); 801 581 if (RT_SUCCESS (rc)) 802 582 { … … 804 584 *pfStartThread = true; 805 585 } 586 else 587 { 588 VbglR3ClipboardDisconnect(gCtx.u32ClientID); 589 } 806 590 } 807 591 808 592 if (RT_SUCCESS (rc)) 809 {810 593 *ppInstance = &gCtx; 811 }812 else813 {814 vboxClipboardDisconnect (&gCtx);815 }816 817 594 return rc; 818 595 } 819 596 820 unsigned __stdcall VBoxClipboardThread (void *pInstance) 821 { 597 unsigned __stdcall VBoxClipboardThread(void *pInstance) 598 { 599 Log(("VBoxClipboardThread\n")); 600 822 601 VBOXCLIPBOARDCONTEXT *pCtx = (VBOXCLIPBOARDCONTEXT *)pInstance; 823 824 Log(("VBoxClipboardThread\n")); 825 826 /* Open the new driver instance to not interfere with other callers. */ 827 HANDLE hDriver = CreateFile(VBOXGUEST_DEVICE_NAME, 828 GENERIC_READ | GENERIC_WRITE, 829 FILE_SHARE_READ | FILE_SHARE_WRITE, 830 NULL, 831 OPEN_EXISTING, 832 FILE_ATTRIBUTE_NORMAL, 833 NULL); 602 AssertPtr(pCtx); 834 603 835 604 /* The thread waits for incoming messages from the host. */ 836 605 for (;;) 837 606 { 838 VBoxClipboardGetHostMsg parms; 839 840 VBOX_INIT_CALL(&parms, VBOX_SHARED_CLIPBOARD_FN_GET_HOST_MSG, pCtx); 841 842 VBoxHGCMParmUInt32Set (&parms.msg, 0); 843 VBoxHGCMParmUInt32Set (&parms.formats, 0); 844 845 DWORD cbReturned; 846 847 if (!DeviceIoControl (hDriver, 848 VBOXGUEST_IOCTL_HGCM_CALL(sizeof (parms)), 849 &parms, sizeof (parms), 850 &parms, sizeof (parms), 851 &cbReturned, 852 NULL)) 853 { 854 Log(("Failed to call the driver for host message.\n")); 855 607 uint32_t u32Msg; 608 uint32_t u32Formats; 609 int rc = VbglR3ClipboardGetHostMsg(pCtx->u32ClientID, &u32Msg, &u32Formats); 610 if (RT_FAILURE(rc)) 611 { 612 Log(("VBoxClipboardThread: Failed to call the driver for host message! rc = %Rrc\n", rc)); 613 if (rc == VERR_INTERRUPTED) 614 { 615 /* Wait for termination event. */ 616 WaitForSingleObject(pCtx->pEnv->hStopEvent, INFINITE); 617 break; 618 } 856 619 /* Wait a bit before retrying. */ 620 AssertPtr(pCtx->pEnv); 857 621 if (WaitForSingleObject(pCtx->pEnv->hStopEvent, 1000) == WAIT_OBJECT_0) 858 622 { 859 623 break; 860 624 } 861 862 625 continue; 626 } 627 else 628 { 629 Log(("VBoxClipboardThread: VbglR3ClipboardGetHostMsg u32Msg = %ld, u32Formats = %ld\n", u32Msg, u32Formats)); 630 switch (u32Msg) 631 { 632 case VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS: 633 { 634 /* The host has announced available clipboard formats. 635 * Forward the information to the window, so it can later 636 * respond to WM_RENDERFORMAT message. */ 637 ::PostMessage (pCtx->hwnd, WM_USER, 0, u32Formats); 638 } break; 639 640 case VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA: 641 { 642 /* The host needs data in the specified format. */ 643 ::PostMessage (pCtx->hwnd, WM_USER + 1, 0, u32Formats); 644 } break; 645 646 case VBOX_SHARED_CLIPBOARD_HOST_MSG_QUIT: 647 { 648 /* The host is terminating. */ 649 rc = VERR_INTERRUPTED; 650 } break; 651 652 default: 653 { 654 Log(("VBoxClipboardThread: Unsupported message from host! Message = %ld\n", u32Msg)); 655 } 656 } 863 657 } 864 865 int rc = parms.hdr.result; 866 867 if (RT_SUCCESS (rc)) 868 { 869 uint32_t u32Msg; 870 uint32_t u32Formats; 871 872 rc = VBoxHGCMParmUInt32Get (&parms.msg, &u32Msg); 873 874 if (RT_SUCCESS (rc)) 875 { 876 rc = VBoxHGCMParmUInt32Get (&parms.formats, &u32Formats); 877 878 if (RT_SUCCESS (rc)) 879 { 880 Log(("vboxClipboardHostEvent u32Msg %d, u32Formats %d\n", u32Msg, u32Formats)); 881 882 switch (u32Msg) 883 { 884 case VBOX_SHARED_CLIPBOARD_HOST_MSG_FORMATS: 885 { 886 /* The host has announced available clipboard formats. 887 * Forward the information to the window, so it can later 888 * respond to WM_RENDERFORMAT message. 889 */ 890 ::PostMessage (pCtx->hwnd, WM_USER, 0, u32Formats); 891 } break; 892 case VBOX_SHARED_CLIPBOARD_HOST_MSG_READ_DATA: 893 { 894 /* The host needs data in the specified format. 895 */ 896 ::PostMessage (pCtx->hwnd, WM_USER + 1, 0, u32Formats); 897 } break; 898 case VBOX_SHARED_CLIPBOARD_HOST_MSG_QUIT: 899 { 900 /* The host is terminating. 901 */ 902 rc = VERR_INTERRUPTED; 903 } break; 904 default: 905 { 906 Log(("Unsupported message from host!!!\n")); 907 } 908 } 909 } 910 } 911 } 912 913 if (rc == VERR_INTERRUPTED) 914 { 915 /* Wait for termination event. */ 916 WaitForSingleObject(pCtx->pEnv->hStopEvent, INFINITE); 917 break; 918 } 919 920 if (RT_FAILURE (rc)) 921 { 922 /* Wait a bit before retrying. */ 923 if (WaitForSingleObject(pCtx->pEnv->hStopEvent, 1000) == WAIT_OBJECT_0) 924 { 925 break; 926 } 927 928 continue; 929 } 930 931 Log(("processed host event rc = %d\n", rc)); 932 } 933 934 CloseHandle (hDriver); 935 658 } 936 659 return 0; 937 660 } 938 661 939 void VBoxClipboardDestroy 662 void VBoxClipboardDestroy(const VBOXSERVICEENV *pEnv, void *pInstance) 940 663 { 941 664 VBOXCLIPBOARDCONTEXT *pCtx = (VBOXCLIPBOARDCONTEXT *)pInstance; 942 943 665 if (pCtx != &gCtx) 944 666 { 945 Log(("VBoxClipboardDestroy: invalid instance %p (our %p)!!!\n", pCtx, &gCtx)); 946 667 Log(("VBoxClipboardDestroy: invalid instance %p (our = %p)!\n", pCtx, &gCtx)); 947 668 pCtx = &gCtx; 948 669 } 949 670 950 671 vboxClipboardDestroy (pCtx); 951 952 vboxClipboardDisconnect (pCtx); 953 672 VbglR3ClipboardDisconnect(pCtx->u32ClientID); 954 673 memset (pCtx, 0, sizeof (*pCtx)); 955 956 674 return; 957 675 } 676
Note:
See TracChangeset
for help on using the changeset viewer.