Picture.CopyOSHandle on Win32 with 32 bit pictures

I’m playing around with Picture.CopyOSHandle under Win32 builds with GDI+ enabled, and using the new-style 32 bit picture objects.

The documents say:

WindowsBMP	A 32-bit HBITMAP that you are responsible for releasing with DeleteObject. Supported in Windows GUI applications.

And it appears that this is a handle that points to a plain old BITMAP structure ( http://msdn.microsoft.com/en-us/library/windows/desktop/dd183371(v=vs.85).aspx ) which has a pointer to the color data. Here’s my sample code:

    // we use CopyOSHandle to get a handle to the object, then use GetObject to get the object
    // the object appears to be a simple BITMAP structure which includes a pointer to the image data, which we get a copy of.

    declare function DeleteObject lib kLibGDI32 (handle as Ptr) as boolean
    declare function GetObject lib kLibGDI32 alias "GetObjectA" (handle as Ptr, numberOfBytesToCopy as integer, mb as Ptr) as integer

    dim hbitmap as Ptr = thePicture.CopyOSHandle(picture.HandleType.WindowsBMP)  // must remember to call DeleteObject when done
    dim tmp as new MemoryBlock(1024)  // buffer to hold the object
    dim r as integer = GetObject(hbitmap,tmp.size,tmp)  // get the object (hmm - why does r = 84 bytes?)
    dim bm as BITMAP //  a structure
    bm.StringValue(true) = tmp.stringValue(0,bm.size)
    call DeleteObject(hbitmap)

Some questions I have:

  • when I call GetObject() it’s returning 84, suggesting that the structure it returns is 84 bytes long. However, the structure appears to be a BITMAP structure which is only 24 bytes long. What’s the extra stuff?
  • since this is just a plain old BITMAP structure, it seems like we can’t use the more advanced GDIPlus API to work with it - is there any way to get a handle back to the actual GDIPlus Bitmap instance?