Is it possible to build resources into a static library and reuse them by simply linking with the library?
I'm primarily thinking about the case where you call a function in the library which in turn accesses resources.
It can be done, but it's quite painful: You can't do it by simply linking with the static library.
Consider this: resources are embedded in an EXE or DLL. When some code in the static library calls (e.g.) LoadIcon, it'll get the resources from the EXE or DLL that it's linked with.
So, if your static library requires resources to be available, you've got a couple of options:
CreateDialogIndirect
. See Raymond Chen's "Building a dialog template at run-time".char my_dialog_resource[] = { .... };
, and then use (e.g.) CreateDialogIndirect
. You'll probably need to find (or write) a utility that converts from .RES
files to .CPP
files..RC
file) and corresponding header file. You then #include
them as relevant. You'll need to reserve a range of resource IDs for the LIB to use, so that they don't collide with those of the main EXE or DLL. This is what MFC does when used as a static library. Or you can use string resource IDs (this doesn't work for STRINGTABLE
resources).