LoadString, static library and executables

c++, localization, resources, visual-studio

Solution

Static libraries are just concatenations of .OBJ files - they don't have features like resources. To do this you need to put the resources in DLL.

Problem

My project is set up so all the framework code and modules are compiled to a static .lib (let's call it `framework.lib`), and many test projects use framework.lib and compile to executable files. For error handling, I'm trying to put the resource strings in `framework.rc` (part of the `framework.lib` project) and load the strings in the executable files. However, `LoadString()` just fails. Using `GetLastError()` / `FormatMessage()` I get the following message: "The specified resource type cannot be found in the image file." Here is how I call `LoadString`, which returns 0: ``` char szString[256]; int iNbOfChars = LoadStringA(GetModuleHandle(NULL), iStringID, szString, 256); ``` Should what I do be failing because the resource is not defined in the app, but in the lib? If so, any suggestions so I can have a centralized resource file?

Original source