Microsoft KB Archive/87494

From BetaArchive Wiki

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

Q87494

3.10 WINDOWS kbprg kbbuglist



The information in this article applies to:


  • Microsoft Windows Software Development Kit (SDK) 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 bug in the Microsoft products listed at the beginning of this article.



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 query words: buglist3.10 3.10 scan line

Keywords : kbOSWin310 _IK kbSDKWin16
Issue type : kbbug
Technology : kbAudDeveloper kbWin3xSearch kbSDKSearch kbWinSDKSearch kbWinSDK310


Last Reviewed: July 14, 1999
© 2001 Microsoft Corporation. All rights reserved. Terms of Use.