// 쓰고 싶은 Screen buffer에 쓰기 bool CConsoleManager::WriteScreenBuffer( BYTE /*in_*/byOrderOfScreenBuffer, LPTSTR /*in_*/lpszBuffer, ... ) { assert( lpszBuffer != NULL ); va_list pszVariableFactorList = NULL; bool bResult = false; TCHAR szTempBuffer[4096] = {0,}; // 현재 Screen 변수 재설정 SetCurrentConsole( byOrderOfScreenBuffer ); // 출력 내용 추출 va_start( pszVariableFactorList, lpszBuffer ); _vstprintf_s( szTempBuffer, 4096, lpszBuffer, pszVariableFactorList ); va_end( pszVariableFactorList ); // Screen buffer에 출력 if( IsCurrentHandleValid() ) bResult = CCommonConsole::WriteScreenBuffer( *m_phCurrentConsole, szTempBuffer ); else { g_Log.WriteLog( false, LOG_CLASS_WARNING, TEXT( "%s | Unable to write to the screen buffer.\n" ), TEXT( __FUNCTION__ ) ); bResult = false; } return bResult; }
const TCHAR * FormatStringVA(const TCHAR * format, va_list arglist) { if (!g_bFormatStringCS) { InitializeCriticalSection(&g_kFormatStringCS); g_bFormatStringCS = true; } EnterCriticalSection(&g_kFormatStringCS); static TCHAR buffer[FORMAT_STRING_BUFFER_COUNT]; static int iterator = 0; if (iterator > (FORMAT_STRING_BUFFER_COUNT/4)) iterator = 0; TCHAR * actual = buffer + iterator; int size = FORMAT_STRING_BUFFER_COUNT - iterator; int ret = _vstprintf_s(actual, size, format, arglist); iterator += ret >= 0 ? ret + 1 : size; buffer[iterator-1] = 0; LeaveCriticalSection(&g_kFormatStringCS); return actual; }
void RichEditEventLogger::AddToLog(LogLevel level, const TCHAR * msg, ...) { TCHAR * pLogMsg = logMsgBuffer; time_t rawtime; struct tm timeinfo; va_list argptr; if ((m_Logger == NULL) || (level < m_LogLevel)) { return; } time(&rawtime); localtime_s(&timeinfo, &rawtime); _tcsftime(pLogMsg, MAX_LOG_MSG_LENGTH, _T("%d-%m-%Y %I:%M:%S: "), &timeinfo); pLogMsg += _tcslen(logMsgBuffer); va_start(argptr, msg); _vstprintf_s(pLogMsg, MAX_LOG_MSG_LENGTH - _tcslen(logMsgBuffer), msg, argptr); va_end(argptr); m_Logger->SetSel(-1, -1); m_Logger->ReplaceSel(logMsgBuffer); m_Logger->PostMessage(WM_VSCROLL, SB_BOTTOM, NULL); }
int _cdecl DPrintf(CONST TCHAR *format, ...) { va_list arglist; TCHAR tchDebugString[DEBUG_STRING_MAX_LENGTH]; int nBufLen = -1; ZeroMemory(tchDebugString, DEBUG_STRING_MAX_LENGTH*sizeof(TCHAR)); if (format == NULL) { OutputDebugString(_T("DebugPrintf() FAILED: Format is null pointer!\r\n")); return nBufLen; } va_start(arglist, format); nBufLen = _vstprintf_s((TCHAR *)tchDebugString, DEBUG_STRING_MAX_LENGTH, format, arglist); if (nBufLen == -1) { OutputDebugString(_T("DebugPrintf() FAILED: String is too long!\r\n")); return nBufLen; } //OutputDebugString(_T("DebugPrintf:")); OutputDebugString(tchDebugString); return nBufLen; };
void DriverLog::WriteLine(LPCTSTR message, ...) { if (!Active() || message == 0) return; m_cs.Enter(); static TCHAR lineStart[512]; int lineStartSize = _stprintf_s(lineStart, 512, _T("[%4d][%6d]"), ::GetCurrentThreadId(), ::GetTickCount() - startTick); WriteFileLog(lineStart, lineStartSize); va_list args; va_start( args, message ); int characters = _vsctprintf(message, args); if (characters != -1) { DynamicArray<TCHAR> buffer(characters + 5); if(-1 != _vstprintf_s(buffer, characters + 5, message, args)) { WritePipeLog(buffer, characters); buffer[characters] = _T('\r'); buffer[characters + 1] = _T('\n'); WriteFileLog(buffer, characters + 2); } } m_cs.Leave(); }
// for debug void CUtils::Log(LPCTSTR fmt, ...) { va_list ap; va_start(ap, fmt); TCHAR log[1024]; _set_invalid_parameter_handler(invalid_parameter_handler); if (_vstprintf_s(log, fmt, ap) < 0) _tcscpy_s(log, _T("invalid format")); static int n = 0; TCHAR path[MAX_PATH]; if (GetTempPath(MAX_PATH, path)) { #ifndef _WIN64 _tmakepath_s(path, NULL, path, _T("xkeylog"), _T("txt")); #else _tmakepath_s(path, NULL, path, _T("xkeylog64"), _T("txt")); #endif } else _tcscpy_s(path, _T("c:\\xkeylog.txt")); FILE *fp; _tfopen_s(&fp, path, _T("a")); _ftprintf(fp, _T("%8d: %s\t%s\n"), n++, AppName::GetAppName(), log); fclose(fp); }
/** * Write data to file. * <br>write strings * * @param szData write strings data * @param ... vargs * * @return AT_OK : write success */ int ATFile::write(const TString &szData, ...) { if (ATStringUtl::isEmpty(szData)) { return AT_ERR_ARGUMENTS; } if (!isOpen()) { return AT_ERR_IOEXCEPTION; } /* variable args */ va_list vaList; TCHAR szBuff[_MAX_PATH] = {0}; const TCHAR *pSrc = szData.c_str(); va_start(vaList, pSrc); #ifdef PLATFORM_WINDOWS _vstprintf_s(szBuff, _MAX_PATH, pSrc, vaList); #else vsprintf(szBuff, pSrc, vaList); #endif va_end(vaList); /* Lock file */ if (ml_oLock.lock() != AT_OK) { return AT_ERR_IOEXCEPTION; } _ftprintf_s(ml_pFile, _T("%s"), szBuff); ml_oLock.unlock(); return AT_OK; }
EnumMessageBoxResult MsgboxPrompt(LPCTSTR format, ...) { TCHAR buffer[200]; va_list args; va_start(args, format); _vstprintf_s(buffer, sizeof(buffer)/sizeof(buffer[0]), format, args ); return (EnumMessageBoxResult)MessageBox(NULL, buffer, TEXT("Ìáʾ"), MB_OK | MB_ICONINFORMATION); }
EnumMessageBoxResult MsgboxConfirm(LPCTSTR format, ...) { TCHAR buffer[200]; va_list args; va_start(args, format); _vstprintf_s(buffer, sizeof(buffer)/sizeof(buffer[0]), format, args ); return (EnumMessageBoxResult)MessageBox(NULL, buffer, TEXT("È·ÈÏ"), MB_OKCANCEL | MB_ICONQUESTION); }
EnumMessageBoxResult MsgboxError(LPCTSTR format, ...) { TCHAR buffer[200]; va_list args; va_start(args, format); _vstprintf_s(buffer, sizeof(buffer)/sizeof(buffer[0]), format, args ); return (EnumMessageBoxResult)MessageBox(NULL, buffer, TEXT("´íÎó"), MB_OK | MB_ICONERROR); }
void XDlgConsole::Message( LPCTSTR sz, ... ) { TCHAR buff[1024]; va_list vl; va_start( vl, sz ); _vstprintf_s( buff, 512, sz, vl ); va_end( vl ); MessageString( buff ); }
Exception::Exception(LPCTSTR fmt, ...) { va_list args; va_start(args, fmt); int len = _vsctprintf(fmt, args) + 1; if(len > 0) { _vstprintf_s(m_msg.GetBufferSetLength(len), len, fmt, args); } va_end(args); }
VOID CLog::WriteLog( DWORD logLevel, TCHAR* logString, ... ) { va_list ap; TCHAR szLog[1024] = {0,}; va_start(ap, logString); _vstprintf_s(szLog, logString, ap); va_end(ap); OutputLog(logLevel, szLog); }
void Stream::ThrowError(LPCTSTR fmt, ...) { va_list args; va_start(args, fmt); int len = _vsctprintf(fmt, args) + 1; CString str; if(len > 0) _vstprintf_s(str.GetBufferSetLength(len), len, fmt, args); va_end(args); throw Exception(_T("Error (Ln %d Col %d): %s"), m_line + 1, m_col + 1, str); }
void AddText(HWND hWndLB, PCTSTR pszFormat, ...) { va_list argList; va_start(argList, pszFormat); TCHAR sz[20 * 1024]; _vstprintf_s(sz, _countof(sz), pszFormat, argList); ListBox_SetCurSel(hWndLB, ListBox_AddString(hWndLB, sz)); va_end(argList); }
VOID CLog::WriteLog( TCHAR* logString, ... ) { va_list ap; TCHAR szLog[1024] = { 0, }; va_start(ap, logString); _vstprintf_s(szLog, logString, ap); va_end(ap); OutputLog(LOG_NORMAL, szLog); }
void logging(TCHAR* logString, ...) { va_list ap; TCHAR szLog[1024] = { 0, }; va_start(ap, logString); _vstprintf_s(szLog, logString, ap); va_end(ap); _tprintf_s(szLog); }
int _STPRINTF_S(TCHAR* buffer, size_t sizeOfBuffer, const TCHAR* format, ... ) { va_list args; va_start(args, format); #if _MSC_VER<1400 UNREFERENCED_PARAMETER(sizeOfBuffer); return _vstprintf(buffer, format, args); #else return _vstprintf_s(buffer, sizeOfBuffer, format, args); #endif }
void TRACE(LPCTSTR str, ...) { static TCHAR buf[20*1024]; va_list ap; va_start(ap, str); _vstprintf_s(buf, 20*1024, str, ap); OutputDebugString(buf); va_end(ap); };
void CVSOutputLogPrinter::PrintLogVL(int Level,DWORD Color,LPCTSTR Format,va_list vl) { #ifdef WIN32 TCHAR MsgBuff[4096]; _vstprintf_s( MsgBuff, 4096, Format, vl ); OutputDebugString(MsgBuff); OutputDebugString(_T("\r\n")); #else vprintf(Format,vl); printf(_T("\n")); #endif }
void AddMessage(PCTSTR pszFormat, ...) { va_list argList; va_start(argList, pszFormat); TCHAR szMsg[20 * 1024]; _vstprintf_s(szMsg, _countof(szMsg), pszFormat, argList); HWND hListBox = GetDlgItem(g_hDlg, IDC_LB_STATUS); ListBox_SetCurSel(hListBox, ListBox_AddString(hListBox, szMsg)); va_end(argList); }
BOOL ConsoleOutput::Output(LPCTSTR lpszFmt, ...) { const int kMaxLen = 1024; TCHAR szText[kMaxLen] = { 0 }; va_list arglist; va_start(arglist, lpszFmt); _vstprintf_s(szText, _countof(szText), lpszFmt, arglist); va_end(arglist); return ::WriteConsole(::GetStdHandle(STD_OUTPUT_HANDLE), szText, _tcslen(szText), NULL, NULL); }
// 비졀스튜디오 콘솔창에만 찍는 버전 void XTrace( LPCTSTR szFormat, ... ) { TCHAR szBuff[ 0xffff ]; va_list vl; va_start(vl, szFormat); _vstprintf_s(szBuff, szFormat, vl); va_end(vl); _tcscat_s( szBuff, _T("\n") ); ::OutputDebugString( szBuff ); }
// Add a string to an edit control void AddText(HWND hwnd, PCTSTR pszFormat, ...) { va_list argList; va_start(argList, pszFormat); TCHAR sz[20 * 1024]; Edit_GetText(hwnd, sz, _countof(sz)); _vstprintf_s(_tcschr(sz, TEXT('\0')), _countof(sz) - _tcslen(sz), pszFormat, argList); Edit_SetText(hwnd, sz); va_end(argList); }
// helper to do print traces void _cdecl Trace(LPCTSTR lpszFormat, ...) { va_list args; va_start(args, lpszFormat); TCHAR szBuffer[512]; _vstprintf_s(szBuffer, 512, lpszFormat, args); _tprintf(szBuffer); OutputDebugString(szBuffer); va_end(args); }
/*! */ _tstring strutils::format(LPCTSTR fmt, ...) { va_list args; va_start(args, fmt); _tstring resstr; resstr.resize(_vsctprintf(fmt, args) + 1); _vstprintf_s(&resstr[0], resstr.size(), fmt, args); va_end(args); return resstr; }
void XDlgConsole::Message( LPCTSTR sz, ... ) { TCHAR buff[1024]; va_list vl; va_start(vl, sz); _vstprintf_s(buff, 512, sz, vl); va_end(vl); MessageString( buff ); // CString s; // s.Format( _T("%s\r\n"), buff ); }
void ErrMsg(char frmt[], ...) { DWORD written; char buf[5000]; va_list val; va_start(val, frmt); // wvsprintf(buf, frmt, val); // C4995 warning, function marked as deprecated once _vstprintf_s(buf, frmt, val); // Save replacement const COORD _80x50 = {80,50}; static BOOL startup = (AllocConsole(), SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), _80x50)); WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), buf, lstrlen(buf), &written, 0); }
void ODS(TCHAR type ,const TCHAR* sender,const TCHAR * fmt,...) { va_list argptr; TCHAR text[1024]; va_start (argptr, fmt); #if defined(_MSC_VER) _vstprintf_s(text,1023, fmt, argptr); #else _vsntprintf(text,1023, fmt, argptr); #endif va_end (argptr); ODS(_T("#%c#%s#%s"),type,sender,text); }
void ODS(const TCHAR * fmt,...) { va_list argptr; TCHAR text[1024]; va_start (argptr, fmt); #if defined(_MSC_VER) _vstprintf_s(text,1023, fmt, argptr); #else _vsntprintf(text,1023, fmt, argptr); #endif va_end (argptr); add_log(text); }