/************************************************************************* * wnsprintfA (SHLWAPI.@) * * Print formatted output to a string, up to a maximum number of chars. * * PARAMS * lpOut [O] Destination for output string * cchLimitIn [I] Maximum number of characters to write * lpFmt [I] Format string * * RETURNS * Success: The number of characters written. * Failure: -1. */ int WINAPIV wnsprintfA(LPSTR lpOut, int cchLimitIn, LPCSTR lpFmt, ...) { __ms_va_list valist; INT res; __ms_va_start( valist, lpFmt ); res = wvnsprintfA( lpOut, cchLimitIn, lpFmt, valist ); __ms_va_end( valist ); return res; }
std::string str_vformat( const char* format, va_list ap ) { std::string s; for( int len = 64; ; len *= 2 ) { s.resize( len ); int n = wvnsprintfA( &s[0], len, format, ap ); if( n >= 0 && n < len - 1 ) { s.resize( n ); break; } } return s; }