1

I need to use strings in my winapi C/C++ application from system resources which are located in windows/system32/ and have extension *.mui. F.e. winload.exe.mui.

"Resource hacker" program give me this:

1 MESSAGETABLE
{
0x40000001,     "Обновление системы... (%5!Iu!%%)%r%0\r\n"
0xC0000002,     "Ошибка %4!lX! при операции обновления %1!Iu! из %2!Iu! (%3)%r%0\r\n"
0xC0000003,     "Неустранимая ошибка %4!lX! при операции обновл. %1!Iu! из %2!Iu! (%3)%r%0\r\n"
}

How i can extract string with adress 0x40000001 and use in my winapi app?

Machavity
  • 30,841
  • 27
  • 92
  • 100
  • [FindResourceEx](https://msdn.microsoft.com/en-us/library/windows/desktop/ms648043.aspx). – IInspectable Oct 02 '15 at 21:25
  • Like this? HMODULE resContainer = LoadLibrary(L"C:\\Windows\\System32\\ru-RU\\poqexec.exe.mui"); HRSRC myResource= FindResource(resContainer, MAKEINTRESOURCE(0x40000001), RT_MESSAGETABLE); HGLOBAL myResourceData = LoadResource(resContainer, myResource) – Алексей Красюк Oct 03 '15 at 08:17

2 Answers2

1

You can use the LoadString function directly on the associated dll.

For the current UI language:

wchar_t text[1024];
HMODULE h = LoadLibraryEx(L"shell32.dll", NULL, LOAD_LIBRARY_AS_IMAGE_RESOURCE); // the dll I know the associated .mui has the id
LoadString(h, 12850, text, ARRAYSIZE(text));
FreeLibrary(h);

For another UI language (this language resources must be installed otherwise it will fallback to current language resources)

wchar_t text[1024];
HMODULE h = LoadLibraryEx(L"shell32.dll", NULL, LOAD_LIBRARY_AS_IMAGE_RESOURCE);

LANGID id = GetThreadUILanguage(); // save current language

// switch to language using LCID
SetThreadUILanguage(1036); // French
LoadString(h, 12850, text, ARRAYSIZE(text)); // use the ID you need

SetThreadUILanguage(id); // restore previous language

FreeLibrary(h);
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
0

Need to use FormatMessage

HMODULE resContainer = LoadLibrary(L"C:\\Windows\\System32\\ru-RU\\poqexec.exe.mui");

LPTSTR pBuffer;   // Buffer to hold the textual error description.
if (FormatMessage(
    FORMAT_MESSAGE_ALLOCATE_BUFFER | // Function will handle memory allocation.
    FORMAT_MESSAGE_FROM_HMODULE | // Using a module's message table.
    FORMAT_MESSAGE_IGNORE_INSERTS,
    resContainer, // Handle to the DLL.
    0x40000001, // Message identifier.
    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language.
    (LPTSTR)&pBuffer, // Buffer that will hold the text string.
    256, // Allocate at least this many chars for pBuffer.
    NULL // No insert values.
    )) 
{
    MessageBox(0, pBuffer, 0, 0);
    LocalFree(pBuffer);
}