Win16 Memory Management
23 points by calvin
23 points by calvin
This was a cute read. I recently implemented .exe icon support in my opend program, and since I wanted to cross compile without external dependencies, I did this without using a resource compiler. Therefore, I did just enough of the resource binary format to make the icon work myself.
Anyway, the stuff talked about in this article was still relevant to me! See, my first thought was to take a .ico file, paste a resource file header to it, and call it done. Nope, doesn't work that way because of compatibility with the 16 bit segment memory management! Read more from Raymond Chen: https://devblogs.microsoft.com/oldnewthing/20120720-00/?p=7083
Short version is each version of the icon has a separate resource header so they could be loaded/discarded individually, instead of just being part of a single icon resource you'd then have to parse out the file to get the right version out of. Lets Windows lazy-load it easier. The resource icon format and the .ico file header are almost identical, but the file format has a 32 bit byte offset in the file and the resource format has a 16 bit identifier, so once you have one it isn't hard to convert to the other, but you can't just paste it in and expect it to work! Then, of course, the file bytes itself must be broken up with a separate segment header too. (what I ended up actually doing was just taking a list of .png files on the command line, then making a resource header for each one and then pasted in the png without converting it to ico bitmap format. Works fine since I think Windows Vista and simplified things for my users ever so slightly.)
There's also a 16 bit flags field in the resource header where you can set those segment things like discardable, movable, etc. I don't think it really matters what you put there, but I just copied what the real resource compiler did, but still a blast from the past still relevant today.