I am posting an answer because after some research I found a way. Using my method, an icon can be used as an integral part of a static library and such library can be used by any type of application, including a console one (which doesn't have any resource segment whatsoever).
1. Icon is converted to a static array of BYTE. bin2c
can be used for that.
2. Data is converted into a HICON handle. Here is how I have done that:
HICON hIcon = NULL;
offset = LookupIconIdFromDirectoryEx(s_byIconData, TRUE, 0, 0, LR_DEFAULTCOLOR);
if (offset != 0)
hIcon = CreateIconFromResourceEx(s_byIconData + offset, 0, TRUE, 0x00030000, 0, 0, LR_DEFAULTCOLOR | LR_DEFAULTSIZE);
3. GetIcon is used instead of LoadIcon.
Instead of calling:
m_hIcon = ::LoadIcon(hInstanceIcon, MAKEINTRESOURCE(pXMB->nIcon));
m_hIcon = GetIcon()
To test it, I created a Console application and a new static library. I added to the static library the XMessageBox - A reverse-engineered MessageBox()
] class which allows using a custom icon.
The Console application just calls a function located at the static library and the icon is displayed!