Well this time I said I would tell you how icon's are added to executables. It's not obvious you know. That icon you smack add to that EXE is diplayed by windows. None of your code is executed, but somehow windows knows where in the file that icon is and displays it. So it's not like you can just add some code, cause your code is never read.

So how is the icon added?

Well, if you're being hardcore, then you should know a bit about compilers and linkers. In LCC or BCC you can "manually" tell the command-line based compiler which code files to compile. The compiler will then convert those code files into object files which is just a hair away from being EXE material in itself. You then use a linker to combine those object files into a single EXE. It is the LINKER that ALSO includes the icon in such a way to be readable by windows. Here's how it's done.

First of all, you need to make a .rc file. It's a ASCII resource file which you may edit and specify a few resources to be included in your EXE. Your EXE icon for instance is a resource to be included. Here's a very short example:

#define IDAPPLICON 710
IDAPPLICON ICON c:\lcc\projects\Houdini\Houdini.ico

Here I define IDAPPLICON to 710 - the code indicating that the resource is a application icon. The last argument is the location of that icon. Now I pass the code and resource file into the compiler to be processed.

The compiler will then produce its object files like usual, but ALSO a .res file which is a compiled resource file containing your specially formatted icon. Now you pass the .res and .obj files into the linker and it will know exactly what to do with that .res file and include it properly within your EXE.

That's it! I may add more to this series, but I haven't thought of any topics yet. I may start another series called "Windows - Behind the Scenes".

Domain Registration, Hosting, Management