When I load XML data using MSXML DOM parser and there are errors IXMLDOMDocument.parseError
contains an error code and error message. The error message is localized (i.e. German on a German Windows installation).
Is it possible to get a non-localized English message regardless of the OS installation language? Maybe by converting the error code into string manually using some COM API function or by setting some application-wide language mode to English/US?
Found some solution that allows me to translate the error code into neutral (English) error messages. Apparently the strings are stored as a message table resource in the msxml6r.dll.mui
file within some language dependent subfolder below the C:\Windows\System32
path. So I copied the file from a computer with English localization into my application folder and use the following function to lookup the error message for a given error code:
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;