xml - 使用 MSXML 加载 XML 时如何获得英文错误消息

标签 xml delphi error-handling localization msxml

当我使用 MSXML 加载 XML 数据时DOM 解析器存在错误 IXMLDOMDocument.parseError 包含错误代码和错误消息。错误消息已本地化(即德语 Windows 安装上的德语)。

无论操作系统安装语言如何,是否都可以获得非本地化的英文消息?也许可以使用某些 COM API 函数手动将错误代码转换为字符串,或者将某些应用程序范围的语言模式设置为英语/美国?

最佳答案

找到了一些解决方案,可以让我将错误代码翻译成中性(英语)错误消息。显然,这些字符串作为消息表资源存储在 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;

关于xml - 使用 MSXML 加载 XML 时如何获得英文错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32881379/

相关文章:

Delphi TWebBrowser window.devicePixelRatio 属性

javascript - MongoDB插入多个文档,其中可能有重复的_id

PHP XSLTProcessor transformToXml 返回 null

delphi - 多部分/表单数据请求的 Indy MIME 解码返回尾随 CR/LF

android - 跨越 2 个 fragment 的按钮(xml 布局)

delphi - TVirtualStringTree 中的 GetText 被触发更多次

postgresql - PostgreSQL View 错误处理

error-handling - 如何捕捉原生 php 抛出的 Yii CConsoleApplication 警告?

c++ - 带for循环的递归函数: return value issue

java - C++ 套接字消息包含额外的 ASCII 0 字符