4

I am trying to use GetGuiResources to find the Gui resources used by my program.It takes a flag as the second parameter. I am interested to know the difference between GR_USEROBJECTS and GR_GDIOBJECTS . I couldn't find any documentation around it. Can anyone explain what is the difference between them? I also know that by default maximum 10k GDI handles can be opened process at a time. Is the value returned by GR_GDIOBJECTS counted as part of this 10k limit?

IInspectable
  • 46,945
  • 8
  • 85
  • 181
Naveen
  • 74,600
  • 47
  • 176
  • 233

1 Answers1

8

GR_USEROBJECTS are User32 objects, windows and menus.

GR_GDIOBJECTS are Gdi32 objects, like device contexts, fonts, bitmaps, cursors, icons, brushes, pens, regions, palettes, metafiles, paths.

There is very little point in actually using GetGuiResources() in a program, these values are readily visible in Task Manager. View + Select Columns and tick USER Objects and GDI Objects. There ought to be a ton of web pages that talk about these counters.

The default 10,000 handle quota is per-process. There's a limit on the total number of handles created by all processes in a session, a backgrounder can be seen in article "Pushing the Limits of Windows: USER and GDI Objects – Part 1".

Codeguard
  • 7,787
  • 2
  • 38
  • 41
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Thanks for your answer.. I am trying to figure out a GDI leak in my application and using the GetGuiResources to monitor the usage.. Had one more related question..Does graphic driver anything to do with the GDI leaks? i.e. can a faulty driver cause GDI leaks in my application? – Naveen Jun 29 '14 at 18:36
  • No, the device driver is never at fault. A GDI leak is a pure programming bug. Very common, short from forgetting to release the handle with the appropriate release function (there is more than one), a standard bug is to forget to restore the device context before destroying it. Never ignore the return value of a SelectObject() call, another SelectObject() call is required afterwards to restore the DC. – Hans Passant Jul 07 '14 at 09:58
  • Finally figured out the leak. It was caused by not deleting the bitmap handles returned from `GetIconInfo()` call. – Naveen Jul 16 '14 at 08:22