Changeset 1305 in vbox for trunk/src/VBox/Additions
- Timestamp:
- Mar 7, 2007 4:44:05 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/WINNT/VBoxService/VBoxClipboard.cpp
r1216 r1305 260 260 *pcbActual = u32Size; 261 261 } 262 else263 {264 if (u32Size != cb)265 {266 rc = VERR_INVALID_PARAMETER;267 }268 }269 262 } 270 263 } … … 426 419 else 427 420 { 428 /* Query the size of available data. */421 const uint32_t cbPrealloc = 4096; 429 422 uint32_t cb = 0; 430 431 int vboxrc = vboxClipboardReadData (pCtx, u32Format, NULL, 0, &cb);432 433 dprintf((" vboxClipboardReadData vboxrc = %d, cb = %d\n", vboxrc, cb));434 435 if ( VBOX_SUCCESS (vboxrc) && cb > 0)423 424 /* Preallocate a buffer, most of small text transfers will fit into it. */ 425 HANDLE hMem = GlobalAlloc (GMEM_DDESHARE | GMEM_MOVEABLE, cbPrealloc); 426 dprintf(("hMem %p\n", hMem)); 427 428 if (hMem) 436 429 { 437 HANDLE hMem = GlobalAlloc (GMEM_DDESHARE | GMEM_MOVEABLE, cb); 438 439 dprintf(("hMem %p\n", hMem)); 440 430 void *pMem = GlobalLock (hMem); 431 dprintf(("pMem %p, GlobalSize %d\n", pMem, GlobalSize (hMem))); 432 433 if (pMem) 434 { 435 /* Read the host data to the preallocated buffer. */ 436 int vboxrc = vboxClipboardReadData (pCtx, u32Format, pMem, cbPrealloc, &cb); 437 dprintf(("vboxClipboardReadData vboxrc %d\n", vboxrc)); 438 439 if (VBOX_SUCCESS (rc)) 440 { 441 if (cb > cbPrealloc) 442 { 443 GlobalUnlock (hMem); 444 445 /* The preallocated buffer is too small, adjust the size. */ 446 hMem = GlobalReAlloc (hMem, cb, 0); 447 dprintf(("hMem %p\n", hMem)); 448 449 if (hMem) 450 { 451 pMem = GlobalLock (hMem); 452 dprintf(("pMem %p, GlobalSize %d\n", pMem, GlobalSize (hMem))); 453 454 if (pMem) 455 { 456 /* Read the host data to the preallocated buffer. */ 457 uint32_t cbNew = 0; 458 vboxrc = vboxClipboardReadData (pCtx, u32Format, pMem, cb, &cbNew); 459 dprintf(("vboxClipboardReadData vboxrc %d, cb = %d, cbNew = %d\n", vboxrc, cb, cbNew)); 460 461 if (VBOX_SUCCESS (vboxrc) && cbNew <= cb) 462 { 463 cb = cbNew; 464 } 465 else 466 { 467 GlobalUnlock (pMem); 468 GlobalFree (hMem); 469 hMem = NULL; 470 } 471 } 472 else 473 { 474 GlobalFree (hMem); 475 hMem = NULL; 476 } 477 } 478 } 479 480 if (hMem) 481 { 482 /* pMem is the address of the data. cb is the size of returned data. */ 483 /* Verify the size of returned text. */ 484 if (u32Format == VBOX_SHARED_CLIPBOARD_FMT_UNICODETEXT) 485 { 486 cb = (lstrlenW((LPWSTR)pMem) + 1) * 2; 487 } 488 489 GlobalUnlock (hMem); 490 491 hMem = GlobalReAlloc (hMem, cb, 0); 492 dprintf(("hMem %p\n", hMem)); 493 494 if (hMem) 495 { 496 /* 'hMem' contains the host clipboard data. 497 * size is 'cb' and format is 'format'. 498 */ 499 HANDLE hClip = SetClipboardData (format, hMem); 500 dprintf(("WM_RENDERFORMAT hClip %p\n", hClip)); 501 502 if (hClip) 503 { 504 /* The hMem ownership has gone to the system. Finish the processing. */ 505 break; 506 } 507 508 /* Cleanup follows. */ 509 } 510 } 511 } 512 513 if (hMem) 514 { 515 GlobalUnlock (hMem); 516 } 517 } 518 441 519 if (hMem) 442 520 { 443 void *pMem = GlobalLock (hMem);444 445 dprintf(("pMem %p, GlobalSize %d\n", pMem, GlobalSize (hMem)));446 447 if (pMem)448 {449 /* Read the host data. */450 vboxrc = vboxClipboardReadData (pCtx, u32Format, pMem, cb, NULL);451 452 dprintf(("vboxClipboardReadData vboxrc %d\n", vboxrc));453 454 if (VBOX_SUCCESS (vboxrc))455 {456 // /* Remember the which data was transferred. */457 // vboxClipboardIsSameAsLastSent (pCtx, u32Format, pMem, cb);458 459 /* The memory must be unlocked before inserting to the Clipboard. */460 GlobalUnlock (hMem);461 462 /* 'hMem' contains the host clipboard data.463 * size is 'cb' and format is 'format'.464 */465 HANDLE hClip = SetClipboardData (format, hMem);466 467 dprintf(("WM_RENDERFORMAT hClip %p\n", hClip));468 469 if (hClip)470 {471 /* The hMem ownership has gone to the system. Finish the processsing. */472 break;473 }474 475 /* Cleanup follows. */476 }477 else478 {479 GlobalUnlock (hMem);480 }481 }482 483 521 GlobalFree (hMem); 484 522 }
Note:
See TracChangeset
for help on using the changeset viewer.