0

We've been dealing with an issue in our software ever since Microsoft released KB5000802/808 in early March. I've seen a similar post about it here, and the code we use is virtually the same (and hasn't changed in many years):

Calling Windows SelectObject in a printer-compatible device context returns NULL

In our case, we are actually printing OK, but our objects (bitmaps and text boxes) render invisibly on the screen (only "resize handles" appear) until we de-select and re-select the object. Rolling back the security update is a workaround but it's becoming more difficult to do this. We also have tested with Microsoft's hotfix KB5001649, but the issue persists. Has anyone else encountered this?

'''

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

'''

  • Please show a [mcve]. – IInspectable May 26 '21 at 15:15
  • Be sure to read the notes in [`SelectObject`](https://learn.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject): *Bitmaps can only be selected into memory DC's. A single bitmap cannot be selected into more than one DC at the same time.* – Mark Ransom May 26 '21 at 17:49
  • And why are you using `LR_VGACOLOR`? I have no idea what it does, the documentation about it is very sparse. It might be creating a bitmap that's incompatible with your DC. – Mark Ransom May 26 '21 at 17:52
  • In the minimal example, it loads a bitmap from disk. We are not actually loading it from disk but we are drawing it ourselves. But the hBitmap is valid and if we save it to disk it is correct. We are only selecting it into a memory DC and it is not being selected into more than one DC at a time. We did double-check if there were any recent changes on our side but this code has been in place for over 10 years. – David Endahl May 26 '21 at 19:48
  • Unfortunately it's possible for out-of-spec code to be working for years until an update causes the specs to be more strictly applied. – Mark Ransom May 27 '21 at 04:08
  • I'm sorry I can't determine which update patch caused the problem, but it seems to be related to [this](https://learn.microsoft.com/en-us/answers/questions/382852/enhanced-metafile-emf-rendering-regression-during.html?childToView=383109#comment-383109) thread, maybe you updated an additional patch that caused the problem. – Zeus May 27 '21 at 05:56
  • @dspinellis I wasn't able to comment on your original thread but are you able to confirm that the Microsoft fix worked for you? – David Endahl Jun 07 '21 at 14:04
  • Yes, after I updated the KB5001649 patch, I was able to solve the problem of the original thread. – Zeus Jun 08 '21 at 00:59

0 Answers0