The early versions of Windows 95, that is, the very first release, and subsequent ‘A’ and ‘B’ releases (but NOT the ‘C’ with IE 4.0 bundled!) have a peculiar behavior when it comes to an executable. The operating system refuses to detect an executable’s icon in explorer if you compiled it for /console mode, that is, as a command-line app. In order to work around this, you must compile the executable in /windows GUI mode, define a WinMain() [and not main()] and use AllocConsole() to immediately arrange a console window for the process.

Such is the workaround in case someone else was having trouble with this issue and thought it was a bug. It appears to be intentional behavior that was changed after Windows 95C. The rule is basically this: If the EXE is compiled for /windows GUI mode, then it will be scanned for icon resources and the first one will be used, as is normal… However, if it was compiled for /console mode, then it won’t bother, in fact, it will state the EXE has no icon resources if you try, for example, to create a shortcut and ask it to check for icons in said EXE. It simply defaults to fetching a generic command-line console icon from the system for every EXE that’s compiled as a console/command-line EXE regardless of what icons are or are not contained within…

I spent a few days trying to figure this out actually, I blamed the compiler, the linker, Microsoft VC++ 2005, other settings in the PE header of the executable… I tried PE editors to see if I could get different results… It really frustrated me not being able to figure it out… Finally, I compiled a blank project with VC++ 2005 which I had set to /windows GUI mode and after all my other tests failed, the EXE actually had its icon show up in Windows 95… Yeah, took quite a while…

Anyway, since I googled several times to see if somebody else encountered this problem with no luck, I made this entry in case this info might be useful to somebody else. I will in fact use the work around I mentioned. My EXE will be compiled with subsystem set to /windows GUI mode, a WinMainCRTStartup() function will be defined (the pre-WinMain function), with a subsequent call to AllocConsole() instead of creating a window. This shouldn’t be much of a big deal to all Windows operating systems thereafter, but I’ll have to test how this change behaves elsewhere.