加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在Delphi中调用EnumSystemLocales?

发布时间:2020-12-15 04:02:14 所属栏目:大数据 来源:网络整理
导读:我试图在Delphi中调用 EnumSystemLocales . For example: { Called for each supported locale. }function LocalesCallback(Name: PChar): BOOL; stdcall;begin OutputDebugString(Name); Result := Bool(1); //Trueend;procedure TForm1.Button1Click(Sende
我试图在Delphi中调用 EnumSystemLocales. For example:
{ Called for each supported locale. }
function LocalesCallback(Name: PChar): BOOL; stdcall;
begin
   OutputDebugString(Name);
   Result := Bool(1); //True
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
   EnumSystemLocales(@LocalesCallback,LCID_SUPPORTED);
end;

问题是回调只被调用一次.

注意:EnumSystemLocales返回true,表示成功.

EnumSystemLocales的评论说我的回调必须返回true才能继续枚举(或者更准确地说,不能返回false以继续枚举):

The function enumerates locales by passing locale identifiers,one at
a time,to the specified application-defined callback function. This
continues until all of the installed or supported locale identifiers
have been passed to the callback function or the callback function
returns FALSE.

在documentation of the callback function:

BOOL CALLBACK EnumLocalesProc(
  __in  LPTSTR lpLocaleString
);

评论者遇到了“非虚假”定义的问题:

This function must return 1,not (DWORD) -1 to continue processing

这让我觉得delphi的定义

True: BOOL;

与Window不同. (这就是为什么我尝试了BOOL(1)的返回值 – 它仍然失败了).

接下来我想知道它是不是应该是stdcall.

无论哪种方式,有人可以建议如何在Delpi中调用EnumSystemLocales吗?

编辑:还试过:

>结果:= BOOL(-1);
>结果:= BOOL($FFFFFFFF);
>结果:= BOOL(1);
>结果:=真;

解决方法

尝试像这样声明LocalesCallback函数
function LocalesCallback(Name: PChar): Integer; stdcall;

检查这个样本

{$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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读