如何在winapi C/C++中使用系统mui资源?

How to use system mui resources in winapi C/C++?

我需要在我的 winapi C/C++ 应用程序中使用位于 windows/system32/ 且扩展名为 *.mui 的系统资源中的字符串。 F.e。 winload.exe.mui.

"Resource hacker" 程序给我这个:

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"
}

我如何提取地址为 0x40000001 的字符串并在我的 winapi 应用程序中使用?

需要使用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);
}

您可以直接在关联的 dll 上使用 LoadString function

当前 UI 语言:

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);

另一种UI语言(必须安装此语言资源,否则将回退到当前语言资源)

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);