Share via


CStringT::FormatMessage

Formats a message string.

void __cdecl FormatMessage(
   UINT nFormatID,
   [, argument]...
);
void __cdecl FormatMessage(
   PCXSTR pszFormat,
   [, argument]...
);

Parameters

  • nFormatID
    The string resource identifier that contains the unformatted message text.

  • pszFormat
    Points to the format-control string. It will be scanned for inserts and formatted accordingly. The format string is similar to run-time function printf-style format strings, except it allows for the parameters to be inserted in an arbitrary order.

  • argument
    Optional arguments.

Remarks

The function requires a message definition as input. The message definition is determined by pszFormat or from the string resource identified by nFormatID. The function copies the formatted message text to the CStringT object, processing any embedded insert sequences if requested.

Note

FormatMessage attempts to allocate system memory for the newly formatted string. If this attempt fails, a memory exception is automatically thrown.

Each insert must have a corresponding parameter following the pszFormat or nFormatID parameter. Within the message text, several escape sequences are supported for dynamically formatting the message. For more information, see the Windows FormatMessage function in the Windows SDK.

Example

// typedef CStringT<TCHAR, StrTraitATL<TCHAR, ChTraitsCRT<TCHAR>>> CAtlString;

CAtlString str;
int nAsked = 5;
int nAgree = 4;

str.FormatMessage(_T("%1!d! of %2!d! writers agree: Soccer is %3%!"), 
   nAgree, nAsked, _T("Best"));
ASSERT(str == _T("4 of 5 writers agree: Soccer is Best!"));   

Requirements

Header: cstringt.h

See Also

Reference

CStringT Class

CStringT::FormatMessageV

Other Resources

CStringT Members