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!