How to call EnumSystemLocales in Delphi?

感情迁移 提交于 2019-12-04 02:48:07

try declarating the LocalesCallback function like this

function LocalesCallback(Name: PChar): Integer; stdcall;

check this sample

{$APPTYPE CONSOLE}

{$R *.res}

uses
  Windows,
  SysUtils;

function LocalesCallback(Name: PChar): Integer; stdcall;
begin
   Writeln(Name);
   Result := 1;
end;

begin
  try
    EnumSystemLocales(@LocalesCallback, LCID_SUPPORTED);
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
  Readln;
end.

This problem happens due WinAPI bug, observed in Windows version 5.1 WinNls EnumXXX function family (and, according to the comments, probably several others) is only recognizing exactly (BOOL)1 as (BOOL)TRUE and will stop enumeration if callback returns any other returnValue != (BOOL)FALSE.

Here is a most semantic workaround i figured out:

  LongWord(Result) := LongWord(True);     // WINBUG: WinNls functions will continue
                                          // enumeration only if exactly 1 was returned
                                          // from the callback

If you insist on using BOOL type for callback function result, use this:

function LocalesCallback(Name: PChar): BOOL; stdcall;
begin
   OutputDebugString(Name);
   LongWord(Result) := 1;
end;

because Bool(1) = $FFFFFFFF.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!