August 28th, 2013

The format of data and custom resources

Continuing the highly-sporadic series of Win32 resource formats, today we’ll look at the format of RT_DATA resources, which are declared in resource files as RCDATA. Also the format of custom resources, which are declared in resource files by just giving the custom resource name or ordinal as the second word on the declaration. The format is very simple: It’s just raw binary data. If you ask for a 16-bit integer followed by an ANSI string, then you get a 16-bit integer followed by an ANSI string. If you ask for the data to be inserted from a file, then the contents of the file become the resource data. No processing is done on the data. You get what you get. In particular (and this is what catches some people), if your file is a text file, the resource compiler will just treat your text file as binary data and dump it raw into the resources. It doesn’t know that it’s a text file; it’s just a file. This means that if you want a null terminator at the end of your text file, you need to put a null terminator at the end of the text file. Nobody’s going to magically do it for you.

(The Size­Of­Resource function may come in handy here.)

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.