Why can't I get FormatMessage to load my resource string?
A common mistake I see is people confusing message tables
with string resources.
This basically shows up in one place:
The folks who were designing Win32 decided that plain string resources weren’t fancy enough, so they invented message tables, which is just another way of storing strings in resources. Why string resources weren’t good enough I don’t know.
FormatMessage function accepts a message number,
which is looked up in a message table,
not in a string resource.
In other words, if you have something like this:
#define IDS_MYMESSAGE 100 STRINGTABLE BEGIN IDS_MYMESSAGE "Hello, %1" END TCHAR szBuffer; FormatMessage(FORMAT_MESSAGE_FROM_HMODULE, g_hInstance, IDS_MYMESSAGE, 0, szBuffer, 256, Arguments);
the call to
FormatMessage will fail
because you passed in a string resource identifier, not a message
actually uses message tables,
you almost certainly want to pass the
TCHAR szMessage; LoadString(g_hInstance, IDS_MYMESSAGE, szMessage, 256); TCHAR szBuffer; FormatMessage(FORMAT_MESSAGE_FROM_STRING, szMessage, IDS_MYMESSAGE, 0, szBuffer, 256, Arguments);
The only place you will normally want to format a message from
a message table is when you want to access the system message table
to get the text associated with an error code.
don’t forget the