LoadLibraryExW is failing to load the localized MUI version of the program

When adapting applications for Windows localization, you need to provide your application:

  • C:\Program Files\Contoso\Grobber.exe

and include various dll files (with a .mui extension) in subfolders that contain localized resources:

  • C:\Program Files\Contoso\Grobber.exe
  • C:\Program Files\Contoso\en-US\Grobber.exe.mui
  • C:\Program Files\Contoso\en-CA\Grobber.exe.mui
  • C:\Program Files\Contoso\fr-CAca\Grobber.exe.mui
  • C:\Program Files\Contoso\fr-FR\Grobber.exe.mui
  • C:\Program Files\Contoso\es-US\Grobber.exe.mui
  • C:\Program Files\Contoso\fr-DE\Grobber.exe.mui

According to Microsoft's documentation on localizing an application, when running on Windows Vista or later, calling LoadLibrary should transparently select the appropriate file from the correct folder based on the system's current locale:

// 1. Basic application obtains access to the proper resource container 
    // LoadLibraryEx is the preferred alternative for resource modules as used below because it
    // provides increased security and performance over that of LoadLibrary
    HMODULE resContainer = LoadLibraryExW(HELLO_MODULE_CONTRIVED_FILE_PATH,NULL,LOAD_LIBRARY_AS_IMAGE_RESOURCE | LOAD_LIBRARY_AS_DATAFILE);
    if(!resContainer)
    {
        swprintf_s(displayBuffer,SUFFICIENTLY_LARGE_ERROR_BUFFER,L"FAILURE: Unable to load the resource container module, last error = %d.",GetLastError());
        MessageBoxW(NULL,displayBuffer,L"HelloMUI ERROR!",MB_OK | MB_ICONERROR);
        return 1; // exit
    }

However, when I run it, it only loads my base executable instead of:

  • C:\Program Files\Contoso\en-US\Grobber.exe.mui

In my pseudo-code:

HMODULE resContainer = LoadLibraryExW("C:\Program Files\Contoso\Grobber.exe", NULL, LOAD_LIBRARY_AS_IMAGE_RESOURCE | LOAD_LIBRARY_AS_DATAFILE);

int n = LoadStringW(resContainer, SInternalRequestsMUI, buffer, bufferLen);

MessageBox(0, "TestApp", buffer, MB_OK);

The returned string isunlocalized- the one in the Language Neutral (LN) file.

Note: It seems puzzling how Windows is expected to know to load a different library rather than the specified one, but that's what the documentation indicates.

What am I missing? It should be loading a different file from a language-COUNTRY folder based on the system's language. Why isn't it doing so?

Setting a custom language

Microsoft also mentions that in your Windows Vista or newer app, you can override the default system language and specify another language by calling SetThreadPreferredUILanguages:

MUI: Application-Specific Settings Sample (Windows Vista)

    // supported on Windows Vista and forward
    if(!SetThreadPreferredUILanguages(MUI_LANGUAGE_NAME,userLanguagesMultiString,&langCount) || langCount == 0)
    {
        swprintf_s(displayBuffer,SUFFICIENTLY_LARGE_ERROR_BUFFER,L"FAILURE: Unable to set the user defined, last error = %d.",GetLastError());
        MessageBoxW(NULL,displayBuffer,L"HelloMUI ERROR!",MB_OK | MB_ICONERROR);
        return 1; // exit
    }

They also mention that pre-Vista, the system wouldn't perform automatic searching for you, and you had to use an alternative to LoadLibrary called LoadMUILibrary for the searching work:

MUI: Application-Specific Settings Sample (Pre-Windows Vista)

 resContainer = LoadMUILibraryW(HELLO_MODULE_CONTRIVED_FILE_PATH,MUI_LANGUAGE_NAME,0);

These are insightful details. However, since I'm not using Windows XP or earlier, they may not be applicable. I'm mainly concerned with the default system language and not overriding it.

Answer №1

Unable to load the language-specific MUI version of the application using LoadLibraryExW

This cannot be done since LoadLibraryExW does not accept the Language ID as a parameter.

You will need to take note of this yourself

I find it puzzling that Windows is expected to intuitively know that I want to load a different library instead of the specified one, but according to the documentation, that's how it works.

The MUI dll is typically loaded during the call to FindResourceEx/LoadString - here is an example of the call graph:

https://i.stack.imgur.com/6cnck.png

We can also achieve this directly by calling the corresponding API from ntdll

EXTERN_C
NTSYSAPI
NTSTATUS
NTAPI
LdrLoadAlternateResourceModuleEx (
    _In_ HMODULE hModule,
    _In_ LANGID LangId,
    _Out_ HMODULE* pAltResourceDllHandle,
    _Out_ PSIZE_T ViewSize);

Answer №2

According to MSDN, files are associated using a checksum found in resource configuration data contained within all related files. The resource loader utilizes this checksum to confirm that the files contain the necessary resources of the same version. It also checks the language-specific file against its folder name for validation purposes. If the correct association is not established, the loader will not load the resource file.

Therefore, it is essential to pass the appropriate switches to the resource compiler or utilize the MUIRCT tool from the SDK in order to satisfy the MUI component of the loader.

When analyzing system files included with Windows using a resource editor, you may come across a mysterious MUI resource with contents that are not documented...

Answer №3

Have you successfully configured your LN File within the Grobber.exe application?
The LN File, also known as a .dll in the documentation, requires association with its language-specific files according to resource configuration guidelines. When it comes to Loading Language Resources, many resource loading functions now automatically retrieve resources from language-specific files, mimicking their presence within the LN file.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for creating rounded RaisedButton and TextField:

Despite my efforts to add style to RaisedButton, I have been unsuccessful. Here is the code snippet I used: <RaisedButton type="submit" label="Submit" style={{container:{borderRadius: "5px"}}} primary/> I also referred to this question, but it did ...

Trouble arises when extending an MUI component due to a TypeScript error indicating a missing 'css' property

We have enhanced the SnackbarContent component by creating our own custom one called MySnackbarContent: export interface MySnackbarContentProps extends Omit<SnackbarContentProps, 'variant'> { variant?: MyCustomVariant; type?: MyCustomTy ...

Encountering a Typescript issue when trying to access props.classes in conjunction with material-ui, react-router-dom

I could really use some help with integrating material-ui's theming with react-router-dom in a Typescript environment. I'm running into an issue where when trying to access classes.root in the render() method, I keep getting a TypeError saying &a ...

Does the onChange event fire when the value is modified by the parent element?

let [number, set_number] = useState({x: 1}); <ChildComponent number={number} onUpdate={onUpdateFunction} </ChildComponent> set_number({x: 2}) After running set_number({x: 2}), will this action prompt the execution of onUpdateFunction refere ...

Having trouble importing Svg icons in material-ui@next?

After updating to material ui version v1.0.0-beta.26, I encountered a "module not found" issue when trying to import ActionCircle or any icon using the following code snippet. Eg: import AccountCircle from 'material-ui-icons/AccountCircle'; ...

Guide to making a Grid element interactive using the Link component

PostsList component is responsible for rendering a list of posts. The goal is to enable users to click on a post item and be redirected to the specific post's link. const PostsListView = ({ posts, setError, isloggedin }) => { const [redirectCre ...

"Personalizing Your MUI V5 TextField: A Step-by-Step

I'm currently working on customizing my theme for material v5 and I'm wondering how I can remove the black border that appears when hovering over the textfield component. This is the code snippet from my customized theme: MuiTextField: { s ...

The functionality of the Material UI Icon is not meeting expectations

I have been exploring Material UI and came across an interesting discrepancy. The documentation suggests using the following code snippet: import Icon from "@material-ui/core/Icon"; ... <Button variant="contained" color="primary" className={class ...

As I tried running both `npm install --force` and `npm i`, an unexpected error occurred

npm WARN using --force Recommended protections disabled. npm WARN ERESOLVE overriding peer dependency npm WARN While resolving: @material-ui/[email protected] npm WARN Found: [email protected] npm WARN node_modules/react npm WARN react@"^18.2.0" fro ...

Guide to integrating react-phone-number-input into material-ui TextField

Would it be possible for me to use a Material UI TextField component as the inputComponent prop for the PhoneInput component from react-phone-number-input? I am facing an issue where I am unable to apply the ref successfully. Even though I can see the Mat ...

MUI Autocomplete causing a never-ending cycle of requests

One of the challenges I'm facing involves an Autocomplete component in my code. Here's a snippet of the code: <Autocomplete filterOptions={(x) => x} options={items} getOptionLabel= ...

How to Align the Button Vertically with the TextField in React Material-UI

Utilizing the Material-UI library for React, I have been working on creating a simple form with the following design: https://i.stack.imgur.com/LY3ZN.png My challenge lies in aligning the button with the TextField element. Adjusting the margin-top proper ...

What is the best way to centrally align a Card while keeping the text left-aligned?

New to coding and need some guidance. I'm attempting to create a card that is not the full width of the window. I have specified a cardStyle as shown below. cardStyle:{ width: '95vw' align? : 'center?' textAlign? : &a ...

Implementing a custom focus effect for MuiLink

I am looking to customize the appearance of the focusVisible property for all the (material ui) Links in my application. I am aware that I can achieve this by: const useStyles = makeStyles(() => ({ focus: { backgroundColor: 'yellow', ...

Customize the color of badges in React using Material-UI components

Is there a way to customize the colors of badges in React MUI v5, specifically overriding the default primary and secondary colors? I attempted to use the createTheme method as shown below: const CustomTheme = createTheme({ palette: { type: 'da ...

Unlocking the Power of ReactJS: Passing Values in Material UI for Advanced JSON Structures

How can I access complex objects in the GRID component of material UI? Specifically, I am trying to access the ami_info.account, but it only displays Undefined in the UI. var columns = [ { field: 'id', headerName: 'ID', width: 90, ...

Leveraging createMuiTheme to customize default styles for divs, paragraphs, and the body element

Seeking guidance on customizing a Material UI Theme I aim to modify the default styles for elements like <body>. Currently, at the root of my React tree: import theme from './mui-theme' ReactDOM.render( <Router> <ThemePr ...

What is the best way to determine the correct version of Material UI to incorporate into my React application?

On the React starter kit I'm using, I have react and react-dom 15.4.2 installed. I've been attempting to install material-ui but npm is informing me that the latest version requires a higher version of React (16.0). Is there a way for me to inst ...

Tips for enabling button clickability while MuI Dropdown is displayed

I'm new to using MUI and I recently utilized a code snippet like this: <Select name="premiumUser" value={1} displayEmpty={true} fullWidth> <MenuItem value={1}>True</MenuItem> <MenuItem value={2}>False</Menu ...

Setting the value of a Textarea component in @material-ui/core

As a new user of this plugin, I have not been able to find any documentation that addresses my specific question. My goal is to assign a value to the textarea. Initially, I tried giving it an id, but there are multiple HTML components within this textarea ...