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:
- You can have the library build them on the fly, and then use (e.g.)
CreateDialogIndirect
. See Raymond Chen's "Building a dialog template at run-time".
- You can have them embedded in the library as simple arrays (i.e.)
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.
- You can ship the LIB file with a resource script (
.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).
- Your static library can ship with a separate resource DLL.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…