1

I know the Error object http://msdn.microsoft.com/en-us/library/dww52sbt in Microsoft javascript.

Some errors come from an HRESULT and they have a valid number property (for example -2147023570 which maps to 0x8007052E, see for example "Making Sense of HRESULTS" by Eric Lippert http://blogs.msdn.com/b/ericlippert/archive/2003/10/22/53267.aspx ) but the message property (or description property) is empty (in my example the text is "Logon failure: unknown user name or bad password.")

I can wrap a FormatMessage call (or _com_error::ErrorMessage) in a COM object and then call it from my script (it is a script launched with cscript from the command line) but I would like to know whether it is possible to get the textual description without an external component but just relying on a "standard" Windows installation.

Alessandro Jacopson
  • 18,047
  • 15
  • 98
  • 153
  • The problem is that HRESULTs don't map 1-to-1 to certain error messages, moreover there is an `FACILITY_ITF` facility which explicitly defined for user-defined codes which overlap across modules/libraries. – Roman R. Oct 11 '11 at 07:40
  • @RomanR. Can't I just filter away the user defined errors? – Alessandro Jacopson Oct 11 '11 at 07:47
  • 1
    I don't think so, I think your idea of wrapping FormatMessage by your COM class is the thing to do. Note that you can additionally pass locale of your interest in attempt to get English messages (another question of yours here). – Roman R. Oct 12 '11 at 12:15
  • Just a couple duplicates: http://stackoverflow.com/questions/455434/how-should-i-use-formatmessage-properly-in-c, http://stackoverflow.com/questions/1843581/generate-diagnostic-message-for-hresult-codes, http://stackoverflow.com/questions/2914205/translate-hresult-to-a-readable-message, http://stackoverflow.com/questions/7008047/is-there-a-way-to-get-the-string-representation-of-hresult-value-using-win-api – tenfour Oct 12 '11 at 12:41
  • @RomanR. Thank you for your suggestion about using `dwLanguageId`. Unfortunately it does not work on my system (Windows XP) and I get `ERROR_RESOURCE_LANG_NOT_FOUND` as return value from `FormatMessage`. – Alessandro Jacopson Oct 12 '11 at 13:04
  • @uvts_cvs: It's possible that resources for this language are not available, but just to make sure: you should be using argument `MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)` and not just `LANG_ENGLISH`. – Roman R. Oct 12 '11 at 14:13
  • @RomanR. Yes, I did like you say. – Alessandro Jacopson Oct 12 '11 at 14:17

0 Answers0