5

A recent Windows 10 update (probably and also mysteriously KB4577586) seems to have had the effect of causing calls to SelectObject with a bitmap handle as an argument to return NULL when performed in a printer-compatible device context.

The relevant lines can be seen in this bitmap printing example, which works fine on earlier Windows 10 versions, and seems to have worked fine for the past ten years. You can find a full minimal working example in this GitHub repository.

hBitmap = (HBITMAP)LoadImage(NULL,szFileName,IMAGE_BITMAP,0,0,LR_CREATEDIBSECTION|LR_DEFAULTSIZE|LR_LOADFROMFILE|LR_VGACOLOR);
// [...]
HDC prn = GetPrinterDC(hwnd);
hdcMem = CreateCompatibleDC(prn);
HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, hBitmap);
// hbmOld is NULL at this point, indicating SelectObject failure

The problem stops occurring after uninstalling Windows update KB5000802, but this is obviously not a long-term fix.

Diomidis Spinellis
  • 18,734
  • 5
  • 61
  • 83
  • 3
    Looks like something similar to my problem: https://stackoverflow.com/questions/66606632/images-not-printing-after-the-latest-security-update (Solved it by uninstalling the KB5000808/802) – IgorD Mar 12 '21 at 23:06
  • 2
    @RemyLebeau According to the [SelectObject documentation](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject) and [this detailed explanation](https://devblogs.microsoft.com/oldnewthing/20100416-00/?p=14313) SelectObject will return NULL only in an error case. In the example I posted it returns NULL after the Windows update and in that case nothing is printed. – Diomidis Spinellis Mar 13 '21 at 05:56
  • 2
    And as a confirmation that SelectObject() is the only problem here, creating a HDC at startup from a hdc of a regular window, selecting a bitmap in it with SelectObject() and then using that memory DC later will eventually print the bitmap. Unfortunately, this is not a solution of any kind. – IgorD Mar 13 '21 at 14:26
  • 2
    Hi,I can reproduce this issue now. And I will confirm it with Internal engineer, and response here if there is any update.Thanks for your understanding. – Zeus Mar 15 '21 at 06:06
  • @SongZhu-MSFT: thank you! This is a critical issue for us as customer reports are rolling in and there's no work-around other than not printing logos onto invoices or uninstalling KB5000808/802 resolves the problem. – UweBaemayr Mar 17 '21 at 16:40
  • 1
    According to this, Microsoft seems to have acknowledged the bug and is working on a fix. https://www.bleepingcomputer.com/news/microsoft/microsoft-warns-of-more-printing-issues-caused-by-march-updates/ – UweBaemayr Mar 18 '21 at 15:59
  • 1
    [The hotfix is out](https://support.microsoft.com/en-us/topic/march-18-2021-kb5001649-os-builds-19041-870-and-19042-870-out-of-band-ebbe0617-3a63-467a-aaaa-2a4c68a6de33). "Updates an issue that fails to print the graphical content in a document after installing the March 9, 2021 update." – Raymond Chen Mar 19 '21 at 15:54

0 Answers0