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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.RESfiles to.CPPfiles..RCfile) and corresponding header file. You then#includethem 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 forSTRINGTABLEresources).