PRB: GetObject() Always Returns Positive Height For DIB Sections (186586)



The information in this article applies to:

  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Professional
  • Microsoft Windows NT Server 4.0
  • Microsoft Windows NT Workstation 4.0

This article was previously published under Q186586

SYMPTOMS

When you use GetObject() to obtain information about a DIB section, GetObject() always returns a DIBSECTION containing a BITMAPINFOHEADER with a positive height value, regardless of the sign of the height it was created with. If you need to track the sign of the height in an application, you will need to do this programmatically.

MORE INFORMATION

The following code demonstrates this problem:

Sample Code



   // Code to create a DIB section that will be used as
   // a test case.
   HBITMAP CreateADIBSection(int iWidth, int iHeight)
   {
       BITMAPINFO bmi;
       BYTE *pBits;
       HDC hdc = GetDC(NULL);
       HBITMAP hbm;
				


       // Initialize the header.
       bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
       bmi.bmiHeader.biWidth = iWidth;
       bmi.bmiHeader.biHeight = iHeight;
       bmi.bmiHeader.biPlanes = 1;
       bmi.bmiHeader.biBitCount = 24;
       bmi.bmiHeader.biCompression = BI_RGB;
				


       // Create the surface.
       hbm = CreateDIBSection(hdc,        // Handle to device context.
                              &bmi,       // Pointer to creation parameters
                              DIB_RGB_COLORS,   // Unused.
                              &pBits,     // Address of pointer to surface.
                              NULL,       // No file mapping object.
                              0);         // No offset.
				


       // Clean up.
       ReleaseDC(NULL, hdc);
				


return(hbm);

   }
				




   // Create a DIB section with a negative height, and then
   // display its height as returned from GetObject().
   {
       char       szMessage[128];
       int        nHeight = -100;
       HBITMAP    hbm = CreateADIBSection(10, nHeight); // Create a test
                                                        // case.
       DIBSECTION ds;
				


       // Fill out a DIBSECTION for the test case.
       GetObject(hbm, sizeof(ds), &ds);
				


wsprintf(szMessage, "Created with height: %li\n" "Height reported by GetObject(): %li", nHeight, ds.dsBmih.biHeight);



MessageBox(NULL, szMessage, "Status...", MB_ICONINFORMATION);

   }
				

Modification Type:MinorLast Reviewed:3/7/2005
Keywords:kbcode kbFAQ kbprb KB186586