Windows Mobile 6.5
A version of this page is also available for

This function creates a device-independent bitmap (DIB) that applications can write to directly. The function returns a handle to the bitmap.

HBITMAP CreateDIBSection(
  HDC hdc, 
  const BITMAPINFO* pbmi, 
  UINT iUsage, 
  void** ppvBits, 
  HANDLE hSection, 
  DWORD dwOffset


[in] Handle to a device context.

If the value of iUsage is DIB_PAL_COLORS, the function uses this device context's logical palette to initialize the device-independent bitmap's colors.


[in] Pointer to a BITMAPINFO structure that specifies various attributes of the device-independent bitmap, including the bitmap's dimensions and colors.


[in] Specifies the type of data contained in the bmiColors array member of the BITMAPINFO structure pointed to by pbmi (either logical palette indexes or literal RGB values).

The following values are defined.

Value Description


The BITMAPINFO structure contains an array of bit masks or a palette depending on the value of the biCompression member of the structure. These values are used when rendering the bitmap.

This value can be specified along with any bit count.


The BITMAPINFO.bmiColors array is ignored, and the destination palette is used when rendering the bitmap.

This value can only be specified with an 8-bpp bitmap.


[in] Pointer to a variable that receives a pointer to the location of the device-independent bitmap's bit values.


[in] Set this parameter to NULL.


[in] Ignored.

A handle to the newly created device-independent bitmap indicates success, and *ppvBits points to the bitmap's bit values.

NULL indicates failure, and *ppvBits is NULL.

To get extended error information, call GetLastError.

The system allocates memory for the device-independent bitmap. The system closes the handle to that memory when you later delete the device-independent bitmap by calling the DeleteObject function.

In Windows CE 2.0 and later, the BITMAPINFO structure must include a color table if the images are palletized (usually 1-, 2-, 4-, and 8-bpp formats).

For 16-bpp or 32-bpp non-palletized images, the color table must be three entries long; the entries must specify the values of the red, green, and blue bitmasks.

Also, the biCompression member in the BITMAPINFOHEADER structure should be set to BI_BITFIELDS. BI_RGB is not supported for these bit depths. GDI ignores the color table for 24-bpp images; their pixels must be stored in Blue-Green-Red (BGR) format.

Windows Embedded CE does not support 332 bitfields devices.

In Windows CE 1.0 and 1.01, the BITMAPINFO structure pointed to by the pbmi parameter must specify 1 or 2 bits per pixel.

The memory of a DIBSECTION is DWORD-aligned by row.

Windows Embedded CEWindows CE 1.0 and later
Windows MobileWindows Mobile Version 5.0 and later

Community Additions