0

I am trying to create Cursor from png, and CreateDIBSection() is throwing.

Follwoing is the snippet of code:

HDC hdc = GetDC(NULL);
void* lpBits = NULL;
HBITMAP  hBitmap;
try
{
 hBitmap = CreateDIBSection(
  hdc,
  (BITMAPINFO*)&bi,
  0,
  &lpBits,
  NULL,
  (DWORD)0);
}

ReleaseDC(NULL, hdc);

As CreateDIBSection is throwing, the code to release DC is not getting executed. can you please let me know the possible issue behind this?

Naveen
  • 74,600
  • 47
  • 176
  • 233
Anaamika
  • 9
  • 1
  • have u initialized BITMAPINFO properly ? – Ashish Feb 15 '10 at 07:08
  • BITMAPV5HEADER bi = { }; bi.bV5Size = sizeof bi; bi.bV5Width = lWidth; bi.bV5Height = lHeight; bi.bV5Planes = 1; bi.bV5BitCount = 32; bi.bV5Compression = BI_BITFIELDS; // alpha format for Windows XP. bi.bV5AlphaMask = 0xFF000000; bi.bV5RedMask = 0x00FF0000; bi.bV5GreenMask = 0x0000FF00; bi.bV5BlueMask = 0x000000FF; I have used these values. – Anaamika Feb 15 '10 at 07:16

1 Answers1

0

You should make structure zeroed out:

ZeroMemory(&bi,sizeof(BITMAPV5HEADER));

Try out this link , it may help you :

http://support.microsoft.com/kb/318876

Ashish
  • 8,441
  • 12
  • 55
  • 92