Search code examples
c++cwindowswinapimodern-ui

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


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?


Solution

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