• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

WinGDI: CreateDIBSection

clickynext

Platinum Member
Hi all,

I had a question about a specific function in the winGDI api, CreateDIBsection()

It looks to me like you pass this function a BITMAPINFO and a void**, and it points that pointer to direct memory access to the bits it allocates. However, it doesn't pass you back anything specifying how much memory it allocated, and so the buffer returned appears to be unbounded. I can't figure out how to check whether I'm going out of bounds when I'm using the allocated memory other than to just trust that it was done correctly.

Is there a way to do this that I've overlooked?

Thanks!
 
It either succeeds (returning a HBITMAP) or fails returning NULL. The size of the memory area returned by *ppvBits is bounded by the dimensions YOU specify in BITMAPINFO.BITMAPINFOHEADER (pbmi.bmiHeader). You can check your bounding by using biWidth * biHeight * (biBitCount / 8).

If there is not enough memory available to allocate for the function call, CreateDIBSection will return NULL, and GetLastError will in turn return "Insufficient Memory".
 
Hmm, thanks for the reply. That makes sense, but doesn't change the fact that there's no guarantee that CreateDIBSection did its job correctly. But I suppose the API can be considered trustable so there's no real need to worry.

Thanks 🙂
 
but doesn't change the fact that there's no guarantee that CreateDIBSection did its job correctly.

"Requirements:
Windows NT/2000: Requires Windows NT 3.1 or later.
Windows 95/98: Requires Windows 95 or later."

I think we'd know by now if the function behaved erratically 🙂
 
Back
Top