LoadString, static library and executables

My project is configured in such a way that all code and framework modules are compiled into static .lib (let it be called framework.lib), and many test projects use framework.lib and are compiled into executable files.

To handle errors, I try to put resource strings in framework.rc(part of the project framework.lib) and load strings into executable files. However, it LoadString()just fails. Using GetLastError()/ FormatMessage(), I get the following message:

"The specified resource type cannot be found in the image file."

This is how I call LoadStringwhich returns 0:

char szString[256];  
int iNbOfChars = LoadStringA(GetModuleHandle(NULL), iStringID, szString, 256);

Should I be unsuccessful because the resource is not defined in the application, but in lib? If so, any suggestions so that I can have a centralized resource file?

+3
source share
5 answers

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 the DLL.

+3
source

You cannot put resources in .lib files. (I hope you could). You must store the .rc files and include them in the application's .rc file when you link to lib.

- , , .lib, . , , .rc . Microsoft.

, , (.res) .obj , . , , LoadString, , .res .

  • framework.rc
  • framework.res
  • framework.res framework.obj,

    const BYTE framework_res[]; const size_t framework_res_size;

  • MyLoadString(framework_res, framework_res_size, iStringId, sz, 256) LoadString .

, LoadString, , . LoadString .

LPCWSTR MyFindString(framework_res, framework_res_size, iStringId);

.rc /n, null .

+1

#include , lib.

(EXE) .Lib.

0

AFAIK - DLL , .

.rc .

0
source

An obvious way to centralize resources is to create a DLL containing resources. Then you can use LoadStringsuch as if the resource was in an executable file, with the exception of small details that you need to specify with the correct module descriptor instead of NULL.

0
source

Source: https://habr.com/ru/post/1730911/


All Articles