The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,708 other followers

Loading your MAINICON and VersionInfo through plain text .RC resource files.

Posted by jpluimers on 2016/10/19

I like repositories to have as much of the information in text format.

Delphi traditionally puts both the MAINICON and the VersionInfo resources in a binary .res file and also updates that file on almost every recompile.

There are quite a few posts explaining how to get them from text, but a version controlled example works best for me, so there is one at

The trick is to:

  1. put your resources in a text RC file that can be compiled through a resource compiler
  2. add these to your Delphi project via the project manager, so it generated RcCompile elements which instructs the build process to run the resource compiler first:

Here are the example files:

The MAINICON is based on the public domain Nuclear Atom Atomic / The Noun Project (National Park Service) / 128px / Icon Gallery.

Note that if you include 256×256 or larger 32-bit icons in your ICO file, you will most likely get an “allocate failed” error during compile. Somehow older Delphi versions (TODO: which ones <g>) don’t support these large icons.

The project in fact was to assist me researching the cause for .net – How to research what resources are leaked by which application (not a full ATOM table issue) – Stack Overflow.

The original source was only half there in the repository missing the most important piece and having seriously flawed logic. So I reconstructed a command-line application that now can:

  1. Scan for Global Atoms, global registered WindowsMessages
  2. Identify two kinds of Atoms: Delphi program related and “Special” (most likely leaked by Microsoft Test Manager)
  3. Reasonably successfully determine the Process Id for Delphi program related Atoms (to figure out of the process is still running)
  4. Release both the Delphi program related and “Special” atoms from memory

Enjoy (:

The Special Global Atoms it finds all have to do with MSAA and are formatted like:

The Delphi related Global Atoms and RegisterWindowsMessages it correspond to the below table:

Prefix Kind Id kind Unit
Delphi GlobalAddAtom Process Id Controls/Vcl.Controls
ControlOfs GlobalAddAtom + RegisterWindowMessage Thread Id Controls/Vcl.Controls
WndProcPtr GlobalAddAtom Thread Id Controls/Vcl.Controls
WideWndProcPtr GlobalAddAtom Thread Id ???
DlgInstancePtr GlobalAddAtom Thread Id Dialogs/Vcl.Dialogs

The RegisterWindowMessage of ControlOfs is supposed to be fixed in Delphi XE3 (version 17.0.4625.53395), but lots of people qre quite a few Delphi versions behind as RTL, VCL and IDE haven’t improved dramatically for them (very few clients use FMX as it has had a troublesome start).

Even though [WayBack] Resource leak caused by RM_GetObjectInstance message: QualityCentral indicates the atoms are released, I’ve empirically observed often they don’t. It looks like either the finalization section of the Controls unit or the DoneControls method isn’t always successfully called upon program termination or DLL unload.

It did fox the RegisterWindowMessage for XE3 and up, but not for lower versions. So Andy (Andreas Housladen) wrote Fix for QC 90511 (Atom leak) for Delphi 6 – XE which you can download through the VCL Fix Pack page.


PS: related background information

2 Responses to “Loading your MAINICON and VersionInfo through plain text .RC resource files.”

  1. kmorwath said

    Just two advices: uses the RC.exe compiler from the Windows SDK to compile resources – it will support features the BRCC32 compiled doesn’t. Resources can be localized, so ensure they contain the correct ones for the languages you support. AFAIK, your resource script is set for Netherlands (if there is only one resource Windows can use that anyway).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: