Is there a useful C ++ shell class for Windows resource loading strings?

We are working on the localization of our application and now we are dealing with the correction of all hard-coded strings in LoadString (), etc.

I quickly looked through this class , but I wonder if anyone has used any other good wrappers.

Some requirements / pleasant to use:

  • short replacements of hard-coded lines - we do not want to add lines or lines of code.
  • free and without royalty

EDIT A bit more information - hard-coded strings were all over the code. Sometimes they were converted by the compiler to CString, sometimes before std :: string, and sometimes just by the old char *.

We want to minimize changes in the code base (250k + lines of code) and we will not interfere much in places where all lines are used as different types.

Thus, a class / method must fulfill multiple responsibilities like wchar, CString, std :: string, etc.

+4
source share
3 answers

I think the class is superfluous for this. I use this one:

inline const wchar_t * LoadResourceString(UINT resourceId) { wchar_t * buff; int requiredLen = LoadStringW( GetModuleHandle(0), // Replace this with your HINSTANCE if // using a resource DLL of course :) resourceId, reinterpret_cast<LPWSTR>(&buff), 0); if (requiredLen == 0) { THROW_LAST_WINDOWS_ERROR(); } return buff; } 

EDIT: Of course, you would need to put HINSTANCE somewhere if you intended to use this in the resource DLL. This assumes that the resource strings are encoded as part of a single binary.

+4
source

Here is what I use:

 extern HINSTANCE GetResourceInstance(); //Define elsewhere, or use a global hInst template<int N> class LoadStringRes { TCHAR tszString[N+1]; public: LoadStringRes(int ID) { ::LoadString(GetResourceInstance(), ID, tszString, sizeof(tszString)/sizeof(tszString[0])); } operator const TCHAR*() const { return tszString; } }; 

Use this:

 MyFunctionThatNeedsAString(LoadStringRes<100>(IDS_HELLO)); 

It looks like a function call, but it really is an object construct / use / destruction / use.

The disadvantage is that you have to know the length of the row ball. This is the price of memory allocation in the auto / stack.

+1
source

Take a look at wxWidgets . It will enlarge your installation distribution file, but it is very powerful and provides many features (in addition to what you are looking for) in a very elegant and efficient way (yes, it is free and without royalty).

0
source

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


All Articles