// Format a message with a single parameter CString message; DWORD errorCode = 1234; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, errorCode, 0, message.GetBuffer(MAX_PATH), MAX_PATH, nullptr); message.ReleaseBuffer();
// Format a message with multiple parameters CString message; DWORD errorCode = 1234; TCHAR* errorMessage = _T("Some error occurred in %s. Error code: %d"); FormatMessage(FORMAT_MESSAGE_FROM_STRING | FORMAT_MESSAGE_IGNORE_INSERTS, errorMessage, 0, 0, message.GetBuffer(MAX_PATH), MAX_PATH, nullptr); message.ReleaseBuffer(); message.Format(message, _T("function xyz"), errorCode);In this example, we are formatting a custom error message with multiple parameters: the `errorMessage` variable contains the string message with two parameters: `%s` and `%d`. We are using the `FORMAT_MESSAGE_FROM_STRING` flag to indicate that we want to use a custom string message. After the call to `FormatMessage`, we use the `message.Format` function to fill the parameter placeholders in the `message` message. Package Library: `CString FormatMessage` function is defined in the `MFC` (`Microsoft Foundation Classes`) library which comes under the Microsoft Visual Studio package.