2

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?

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
blerontin
  • 2,892
  • 5
  • 34
  • 60
  • I sure wouldn't trust auto-translating error messages which contain technical information - that's asking for mis-translations. As you also say, it returns the localized language of Windows - whatever current language pack is in effect. Your best best is to create your own translations and distribute them with your application, and let the user choose which language to use. The fact is - those error messages in the languages you want just don't exist in the localized Windows. If you have a German Windows, it should return German messages. – Jerry Dodge Oct 01 '15 at 07:17
  • I'm curious to understand why you'd want to do this. – David Heffernan Oct 01 '15 at 07:20
  • If your problem is error reporting from various clients so you can debug their issues, then, that's what the error codes are for. The error codes never change, and you can interpret what they mean in any language. – Jerry Dodge Oct 01 '15 at 07:22
  • Yes, I want to be able to ask the client for log output and interpret the error messages. Regarding logging error codes: how can I manually lookup the error code message on my development computer? Is there some API function for this? I tried using `FormatMessage` but it didn't work with MSXML error codes, only with codes returned by `GetLastError()`. – blerontin Oct 01 '15 at 07:46

1 Answers1

3

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;
blerontin
  • 2,892
  • 5
  • 34
  • 60