Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CreateDIBSection problem

Status
Not open for further replies.

hankgao0703

Programmer
Jul 18, 2001
27
CA
Doese anybody know what exactly the reason can cause CreateDIBSection fails.

I call CreateDIBSection, but it fails occassionaly.

Thanks.
 
There are a lot of reasons.
For example:
1. Bad handle to device context
2. Bad BITMAPINFO (members) : bmiHeader or color info (You can have 3-4 errors here only)
3. Wrong color data type indicator
4. Null pointer to variable to receive a pointer to the bitmap's bit values
5. Wrong handle to a file mapping object or offset to the bitmap bit values (if the handle is not NULL).
And: if You use multithreading, all can be wrong, what should be right.
You should use it so:
BITMAPINFO *pDIB - Pointer to right BITMAPINFO!
LPBYTE lpBits;
HDC hDC = GetDC( NULL ); //Desktop DC, if You do not know, wich HWND You should use
HBITMAP hBitmap = CreateDIBSection( hDC, pDIB, DIB_RGB_COLORS, (void**)&lpBits, NULL, 0 );
......
ReleaseDC( NULL, hDC ); //Do not forget!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top