开发者

Why is EnumUILanguages returning only one language?

I'm using the Win API function EnumUILanguages on a Windows XP Embedded build that has Chinese and French shell language packs (MUI) installed, however the API call only returns one language code: 0409 (the base en-US installed language).

If I look in the registry under HKLM\SYSTEM\CurrentControlSet\Control\Nls\MUILanguages\ then I can see all of the available languages (0409, 040C, 0804). I'd prefer to use the API call over accessing the registry directly..开发者_开发百科.. any suggestions as to why this API call returns just the only language?

Thanks, Duncan


Update: A little code and information - I'm calling this from a form with a memo box and a button. Press the button, the WinAPI call is initiated and a pointer to the Strings property of the TMemoBox passed so the call back function can write to it.

// The Button handler
procedure TForm1.btnEnumLangsClick(Sender: TObject);
var
  dwFlags : DWORD;
  callback : TEnumUILanguagesProc;
begin
  dwFlags := 0; // Same as MUI_LANGUAGE_ID for WinXP compat

  EnumUILanguagesW( @EnumUILanguages_Callback,
    dwFlags,
    LParam(memoUILangs.Lines) // Pointer to Memo box text lines
  );

end;


// API Callback function:
function EnumUILanguages_Callback(lpUILanguageString: PWideChar;
  List: TStringList): BOOL; stdcall;
begin
  // Add language ID to the memo box
  List.Add(lpUILanguageString);
  // Return true so the callback continues to run
  Result := True;
end;


EnumUILanguages only calls the callback as long as you return true in the callback. Could it be that you return false right in the first callback and EnumUILanguages stops?


This is a rather old question but it is still unanswered. Because I came across the same problem and was able to solve it, I want to share my solution.

If you are developing under Delphi the problem is the return type of the callback function. Declare it as DWORD and write Result := 1. Delphi's True isn't recognized as TRUE by the calling code of EnumUILanguages.

Fortunately ;-) Delphi's unit Winapi.Windows.pas lacks (under XE2) of a declaration for EnumUILanguages and the function type of its callback function, so you can declare it by your own.


Setting the dwFlags to 0 means MUI_LANGUAGE_ID or MUI_LICENSED_LANGUAGES. This implies two things:

  • You are notting getting language names, you are getting 'hexidecimal language identifiers'. I'd assume they are proper PWideChars, but I wouldn't be 100% sure. Are you?
  • You are only getting licensed languages, which might explain the single result. Try using the MUI_ALL_INSTALLED_LANGUAGES flag.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜