I need to use FormatMessage() for a project, but I don't like its scary interface. Does anyone know of a facade that tidies it up while still allowing for the replacement parameters?
I just read the second part of the FastFormat introduction, and am considering writing an extension for FormatMessage() (or asking the FastFormat project team if they've got one in the works), but I'm keen to get something asap, so if there's anything else decent out there I'd probably grab that instead.
What I want is to be able to write code such as:
HINSTANCE netevent = ::LoadLibrary("netevent.dll");
std::string msg = LookupError(netevent, EVENT_SERVICE_START_FAILED_II,
"child-svr", "parent-svr", "ship happens");
::puts(msg.c_str());
Which would give the result:
The child-svr service depends on the parent-svr service which failed to start be cause of the following error:
ship happens
The current wrapper I've built has the interface:
std::string LookupError(HINSTANCE hinst, DWORD id, ...);
There are two problems with this:
- It's not type-safe, since it's easy to pass any type -
int
,std::string
,void*
- that is notconst char*
- It's easy to mismatch the number of arguments with the number required by the format string representing the error
Given the abilities of FastFormat in terms of type-safety, I want to know if there's a way to follow its mechanisms to deal with FormatMessage().