Re: How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Jochen,

"Jochen Kalmbach [MVP]" wrote:
>
> > [...] However, I found another exception to the rule
> > that says that all system messages are in kernel32: wininet stuff (like
> > ERROR_INTERNET_OUT_OF_HANDLES) is not in kernel32 but instead in
> > wininet.dll.
>
> But this messages cannot be found with FORMAT_MESSAGE_FROM_SYSTEM (which
> was the original question).


Again, you are right, similar but orthogonal problems. However, such an
exception is even worse in that it adds an additional layer of
complexity to any generalized function that creates a string with the
error text in prose and that takes as an input a value that has been
retrieved via GetLastError() or has bubbled up as a DWORD return value.
I guess that everyone out there uses such a function and in my case for
such a function correctly retrieving the string for any error value, be
it a system or a custom error message, it makes things more complicated,
because with additional such exceptions, the code gets more complex.

This is how I do it: I first check if a value retrieved from a "last
error" has bit 29 set. If so, it is a custom last error and I walk the
list of my message table DLLs and try to extract it until I succeed or
the list is walked completely. If instead bit 29 is not set, I now first
have to check if it is in the range [INTERNET_ERROR_BASE,
INTERNET_ERROR_LAST]. If so, I have to load wininet.dll and do a
FormatMessage(FORMAT_MESSAGE_FROM_HMODULE.. with it. If not so, I can do
a FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM.. with it and let kernel32
load it from its table (or let it do the fallback to netmsg.dll).

As you see, for every exception to the rule (like wininet) I have to add
an additional range check for system messages, therefore it is vital for
me to also know about all such wininet-like exceptions. But you are
right, it was not my original question.

Anyway, thanks,

--
Stefan
.



Relevant Pages

  • Re: Migrating the Work Menu
    ... Sorry I can't answer your original question, Bill, because I'm not on Word ... But I can tell you that this newsgroup is, ... exception of Microsoft employees who are currently monitoring for problems ...
    (microsoft.public.mac.office.word)
  • Re: Exceptions and WinForms
    ... Stepping back and looking at your original question, actually, I'd say that ... Any exception handling should be done within a form ... > Hi Daniel. ... >> VS attached and see if the dialog stays up with no secondary exception. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: OT - Location
    ... Sheldon England wrote in ... I laughed when I saw Billy's original question but got depressed when ... telling my friends and family who, with only one exception, responded ...
    (comp.sys.ibm.pc.games.rpg)
  • Re: how to emulate goto.
    ... As an answer to the original question: ... process flow; i.e. the approach that divides as much as possible the ... "exception cases" from the "normal cases". ... >> of the loop. ...
    (comp.lang.java.programmer)
  • Re: I have a question on EnvDTE and I got NotImplementedException
    ... I finally succeed in retrieving the classes contained in the project. ... The exception seems to occur when CodeElement.IsCodeType returns false. ... Like these objects are COM wrapper, maybe the NotImplementedInterface means ... > and the bicycle has to *want* to change. ...
    (microsoft.public.dotnet.framework)