|
<pre lang="text">Found this very useful piece of code to get bitmap info from handle and would like to know HOW it works.
I think if I get how the LPBITAMPINFO gets filled I probably will also understand why using global handle is necessary. Or maybe not.</pre>
// a DIB is in the clipboard, draw it out
GLOBALHANDLE hGMem ;
LPBITMAPINFO lpBI ;
void* pDIBBits;
OpenClipboard() ;
hGMem = GetClipboardData(CF_DIB) ;
ASSERT(hGMem);
TRACE("\nfills LPBITMAPINFO");
lpBI = (LPBITMAPINFO)GlobalLock(hGMem) ;
Appreciate any help.
CHeers Vaclav
-- modified 15-Jan-13 15:54pm.
|
|
|
|
|
GLOBALHANDLE hGMem ; LPBITMAPINFO lpBI ; void* pDIBBits;
OpenClipboard() ; hGMem = GetClipboardData(CF_DIB) ; ASSERT(hGMem); TRACE("\nfills LPBITMAPINFO");
lpBI = (LPBITMAPINFO)GlobalLock(hGMem) ;
At this point you can copy the memory block pointed to by lpBI into your program's address space and process it as required. You should then unlock and release hGMem (which is a system resource), and release the clipboard so other applications can use it.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
Richard,
thanks for adding the comments.
I am still unclear how you get from HANDLE (pointer) - returned by GetClipboardData to BITMAPINFO (pointer).
I guess I still do not get the casting.
This may be to stupid , but why this would not work?
lpBI = (LPBITMAPINFO) GetCLipboardData(CF_DIB)
Maybe the key is really in usage of GLOBALHANDLE.
|
|
|
|
|
Vaclav_Sal wrote: Maybe the key is really in usage of GLOBALHANDLE. Exactly so. The GetCLipboardData() function returns a global handle, and you then need to use the GlobalLock() function to get a pointer to addressable memory. Remember that HANDLE s are 'opaque' types which you cannot use directly, even though they may at times point to some real memory. This is because they are owned by the Windows system and their contents at any one time is not guaranteed to be useful in user space.
One of these days I'm going to think of a really clever signature.
|
|
|
|