Software systems implemented in C++ are designed to be type-safe. That is, proper use of header files, make utilities, type declarations, classes and templates makes it difficult to pass data of the wrong type to functions, to assign data of the wrong type to variables, or to construct a program whose modules are inconsistent with one another. Thus a major source of programming errors is detected while the program is being built, before running it.
A program which uses resources must have a resource file which matches that program’s requirements. However, the resource file and the executable program are only loosely bound together: a variety of errors are possible when dealing with resources, which cannot be detected during the build process. Programmers should be aware of these and take appropriate measures to avoid them.
Additional sources of error include:
Having a program and resource file which do not correspond.
This can arise because the resource file formats were updated, or the program was updated, but the resource file was not updated. When the program is run, the resources it loads are in the wrong format.
The structures in the resource file may be of a different format from that expected by the C++ program.
If the C++ program expects a LONG
while a
WORD
is present in the resource file, then the C++ program will
read two extra bytes from the data item in the resource file. Any subsequent
data read from that resource will be in error.
This kind of error can only be avoided by C++ programs knowing which structs they are dealing with, knowing the data layouts of those structs in a resource file and writing code which works in that context.
Having resources of unexpected type.
The most likely reason for this to arise is because there is no
type safety in the resource compiler. Thus, it is possible for a programmer to
wrongly guess what kind of struct a particular resource should have.
Appropriate comments in the .rh
files and the documentation of the
resource file, will help to reduce this kind of error.
The resource compiler does provide some elementary safety features:
All resources are represented by a symbolic id. This ensures that the resource ids used by the C++ program and those expected by the compiler match, if the recommended build procedures are followed.
flag values, maximum length constants and some other values, may
be defined in a .hrh
file: this ensures that C++ programs deal
with the same numbers as resource files and that the meaning of these numbers
is clear, because they are specified symbolically.