我试图在Delphi中调用
>结果:= BOOL($FFFFFFFF);
>结果:= BOOL(1);
>结果:=真;
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;@H_404_4@问题是回调只被调用一次. @H_404_4@注意:EnumSystemLocales返回true,表示成功. @H_404_4@EnumSystemLocales的评论说我的回调必须返回true才能继续枚举(或者更准确地说,不能返回false以继续枚举):
@H_404_4@The function enumerates locales by passing locale identifiers,one at@H_404_4@在documentation of the callback function:
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.
BOOL CALLBACK EnumLocalesProc( __in LPTSTR lpLocaleString );@H_404_4@评论者遇到了“非虚假”定义的问题:
@H_404_4@This function must return 1,not (DWORD) -1 to continue processing@H_404_4@这让我觉得delphi的定义
True: BOOL;@H_404_4@与Window不同. (这就是为什么我尝试了BOOL(1)的返回值 – 它仍然失败了). @H_404_4@接下来我想知道它是不是应该是stdcall. @H_404_4@无论哪种方式,有人可以建议如何在Delpi中调用EnumSystemLocales吗? @H_404_4@编辑:还试过: @H_404_4@>结果:= BOOL(-1);
>结果:= BOOL($FFFFFFFF);
>结果:= BOOL(1);
>结果:=真;
解决方法
尝试像这样声明LocalesCallback函数
function LocalesCallback(Name: PChar): Integer; stdcall;@H_404_4@检查这个样本
{$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.