使用 MSXML 加载 XML 时如何获得英文错误消息
How can I get English error messages when loading XML using MSXML
当我使用 MSXML DOM 解析器加载 XML 数据时出现错误 IXMLDOMDocument.parseError
包含错误代码和错误消息。错误消息已本地化(即德语 Windows 安装上的德语)。
无论 OS 安装语言如何,都可以获得非本地化的英文消息吗?也许通过使用某些 COM API 函数手动将错误代码转换为字符串,或者将某些应用程序范围的语言模式设置为 English/US?
找到一些允许我将错误代码转换为中性(英语)错误消息的解决方案。显然,这些字符串作为消息 table 资源存储在 C:\Windows\System32
路径下某些语言相关子文件夹中的 msxml6r.dll.mui
文件中。因此,我将文件从具有英语本地化版本的计算机复制到我的应用程序文件夹中,并使用以下函数查找给定错误代码的错误消息:
function GetMsXmlErrorStr( const ErrorCode : Integer ) : WideString;
var
Module : tHandle;
MsgBuf : pWideChar;
MsgLen : Integer;
begin
Module := LoadLibrary('msxml6r.dll.mui');
if ( Module <> 0 ) then
begin
MsgBuf := nil;
MsgLen := FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_HMODULE,
Pointer(Module), ErrorCode, 0, @MsgBuf, 0, nil);
if ( MsgLen > 0 ) then
SetString(result, MsgBuf, MsgLen);
LocalFree(HLocal(MsgBuf));
FreeLibrary(Module);
end;
end;
当我使用 MSXML DOM 解析器加载 XML 数据时出现错误 IXMLDOMDocument.parseError
包含错误代码和错误消息。错误消息已本地化(即德语 Windows 安装上的德语)。
无论 OS 安装语言如何,都可以获得非本地化的英文消息吗?也许通过使用某些 COM API 函数手动将错误代码转换为字符串,或者将某些应用程序范围的语言模式设置为 English/US?
找到一些允许我将错误代码转换为中性(英语)错误消息的解决方案。显然,这些字符串作为消息 table 资源存储在 C:\Windows\System32
路径下某些语言相关子文件夹中的 msxml6r.dll.mui
文件中。因此,我将文件从具有英语本地化版本的计算机复制到我的应用程序文件夹中,并使用以下函数查找给定错误代码的错误消息:
function GetMsXmlErrorStr( const ErrorCode : Integer ) : WideString;
var
Module : tHandle;
MsgBuf : pWideChar;
MsgLen : Integer;
begin
Module := LoadLibrary('msxml6r.dll.mui');
if ( Module <> 0 ) then
begin
MsgBuf := nil;
MsgLen := FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER or FORMAT_MESSAGE_FROM_HMODULE,
Pointer(Module), ErrorCode, 0, @MsgBuf, 0, nil);
if ( MsgLen > 0 ) then
SetString(result, MsgBuf, MsgLen);
LocalFree(HLocal(MsgBuf));
FreeLibrary(Module);
end;
end;