当我使用MSXML DOM解析器加载XML数据时,有错误IXMLDOMDocument.parseError
包含错误代码和错误消息。错误消息已本地化(即德语Windows安装上的德语)。
无论操作系统安装语言如何,都可以获取非本地化的英文消息吗?也许通过使用某些COM API函数或通过将某些应用程序范围的语言模式设置为英语/美国来手动将错误代码转换为字符串?
答案 0 :(得分:3)
找到一些解决方案,允许我将错误代码转换为中性(英语)错误消息。显然,字符串作为消息表资源存储在msxml6r.dll.mui
文件中C:\Windows\System32
路径下面的某个语言相关子文件夹中。所以我将文件从具有英语本地化的计算机复制到我的应用程序文件夹中,并使用以下函数查找给定错误代码的错误消息:
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;