void AfxMessageBoxFormatted(LPCTSTR pFormatString, ...)
{
    va_list vl;
    va_start(vl, pFormatString);<br>
    CString strFormat;
    strFormat.FormatV(pFormatString, vl); // This Line is important!<br>
    // Display message box.
    AfxMessageBox(strFormat);
}

void MessageBoxFormatted(HWND hWnd, LPCTSTR pCaption, LPCTSTR pFormatString, ...)
{
    va_list vl;
    va_start(vl, pFormatString);<br>   
    TCHAR strFormat[1024]; // Must ensure size!<br>

    // Generic version of vsprintf, works for both MBCS and Unicode builds
    _vstprintf(strFormat, pFormatString, vl);<br>
    // Or use following for more secure code
    // _vstprintf_s(strFormat, sizeof(strFormat), pFormatString, vl)<br>
    ::MessageBox(hWnd, strFormat, pCaption,MB_ICONINFORMATION);
}