Re: How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?
- From: Stefan Kuhr <kustt110@xxxxxx>
- Date: Sat, 16 Jul 2005 13:33:21 +0200
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
.
- Follow-Ups:
- Re: How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?
- From: Jochen Kalmbach [MVP]
- Re: How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?
- References:
- How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?
- From: Stefan Kuhr
- Re: How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?
- From: Jochen Kalmbach [MVP]
- Re: How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?
- From: Stefan Kuhr
- Re: How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?
- From: Jochen Kalmbach [MVP]
- How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?
- Prev by Date: share file handle between app and driver
- Next by Date: Re: How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?
- Previous by thread: Re: How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?
- Next by thread: Re: How does FormatMessage with FORMAT_MESSAGE_FROM_SYSTEM work internally?
- Index(es):
Relevant Pages
|