Microsoft KB Archive/106386

From BetaArchive Wiki

HOWTO: Retrieve DIBs from the Clipboard


The information in this article applies to:

  • Microsoft Win32 Software Development Kit (SDK)


Retrieving a DIB (device-independent bitmap) from the clipboard can take significantly more time than retrieving a bitmap from the clipboard. The difference stems from the fact that a bitmap is a GDI object and a DIB is a global memory object.


When SetClipBoardData() is passed a global memory handle, as it is when it is passed a handle to a DIB, all the data gets copied into the Win32 server and put into a sharable section of memory. When the DIB is retrieved with GetClipBoardData(), the shared memory is mapped into the application's virtual address space and the memory handle is cached. Any subsequent calls to GetClipBoardData() return quickly, because the memory does not have to be remapped.

In contrast, when retrieving a bitmap with GetClipBoardData(), only a handle is created, because a bitmap is a GDI object.

When CloseClipboard() is called, all of the cached handles to shared memory and GDI objects are deleted.

Rather than reopening the clipboard, it is a good idea to keep a local copy of anything retrieved from the clipboard if the item will be used again after the clipboard has been closed. In general, data should be retrieved from the clipboard only when the application is doing a paste or if the application is a clipboard viewer processing a WM_DRAWCLIPBOARD message.

The data for a GDI object exists on the server side. In other words, bitmaps and DDBs (device-dependent bitmaps) exist in the Win32 subsystem address space. Only the handles of GDI objects are private to an application. Therefore, to make a bitmap or a DDB accessible to another application, only a call to DuplicateHandle() is needed.

Note that even though it is faster to retrieve a DDB from the clipboard, it is still recommended to put a DIB on the clipboard rather than a DDB.

Additional query words:

Keywords : kbClipboard kbOSWinNT kbOSWin2000 kbGrpDSUser kbOSWin
Issue type : kbhowto
Technology : kbWin32SDKSearch kbAudDeveloper kbSDKSearch kbWin32sSearch

Last Reviewed: July 12, 2000
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.