How should I use FormatMessage() properly in C++?

Here’s the proper way to get an error message back from the system for an HRESULT (named hresult in this case, or you can replace it with GetLastError()): LPTSTR errorText = NULL; FormatMessage( // use system message tables to retrieve error text FORMAT_MESSAGE_FROM_SYSTEM // allocate buffer on local heap for error text |FORMAT_MESSAGE_ALLOCATE_BUFFER // Important! … Read more