BUG: BitBlt() Bitmap on VGA Display Causes GP Fault

Last reviewed: January 5, 1995
Article ID: Q87494
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) for Windows version 3.1

SYMPTOMS

When an application for the Microsoft Windows environment calls BitBlt() to copy a large (640 x 480) bitmap to the VGA screen, the application experiences a general protection (GP) fault.

RESOLUTION

Increase the size of the bitmap to store one additional scan line. Use the BitBlt function to copy only the desired portion of the bitmap to the screen.

STATUS

Microsoft has confirmed this to be a problem with Windows version 3.1. We are researching this problem and will post more information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

There are two methods for increasing the size of the bitmap. If the contents of the bitmap are fixed, Microsoft Paintbrush or a similar image- editing tool can be used to add or remove a scanline from the bitmap.

If the image changes, the following eight steps add a scanline to a bitmap under program control and copy the bitmap to the screen. The handle to the original bitmap is stored in the hBMPOriginal variable.

  1. Declare variables.

          HBITMAP hBMPCompatible, hBMPOld1, hBMPOld2;
          HDC hDCMem1, hDCMem2, HDCScreen;
    

  2. Retrieve a display context (DC) for the screen.

          hDCScreen = GetDC(NULL);
    

  3. Create a bitmap compatible with the screen that contains one more scanline than the original bitmap.

          hBMPCompatible = CreateCompatibleBitmap(hDCScreen, 640, 481);
    

  4. Create two memory DCs compatible with the screen.

          hDCMem1 = CreateCompatibleDC(hDCScreen);
          hDCMem2 = CreateCompatibleDC(hDCScreen);
    

  5. Select the original bitmap into one of the DCs. Select the new bitmap into the other.

          hBMPOld1 = SelectObject(hDCMem1, hBMPOriginal);
          hBMPOld2 = SelectObject(hDCMem2, hBMPCompatible);
    

  6. Use the BitBlt function to copy the original bitmap into the compatible bitmap. The function does not fill the bottom scanline because the bottom scanline is not copied to the screen.

          BitBlt(hDCMem2, 0, 0, 640, 480, hDCMem1, 0, 0, SRCCOPY);
    

  7. Copy the compatible bitmap to the screen.

          BitBlt(hDCScreen, 0, 0, 640, 480, hDCMem2, 0, 0, SRCCOPY);
    

  8. Free resources. Note that the code below deletes the compatible bitmap. If the bitmap is required later in the program, defer deleting the bitmap until just before the application closes.

          hBMPCompatible = SelectObject(hDCMem2, hBMPOld2);
          DeleteObject(hBMPCompatible);
          hBMPOriginal = SelectObject(hDCMem1, hBMPOld1);
          DeleteDC(hDCMem1);
          DeleteDC(hDCMem2);
          ReleaseDC(NULL, hDCScreen);
    


Additional reference words: buglist3.10 3.10 scan line
KBCategory: kbprg kbbuglist
KBSubcategory: GdiBmp


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 5, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.