VOID cdecl CPSUIDbgPrint ( LPCSTR pszFormat, ... ) /*++ Routine Description: This fucntion output the debug informat to the debugger Arguments: pszFormat - format string ... - variable data Return Value: VOID --*/ { va_list vaList; static TCHAR OutBuf[768]; #ifdef UNICODE static WCHAR FormatBuf[256]; #endif // // We assume that UNICODE flag is turn on for the compilation, bug the // format string passed to here is ASCII version, so we need to convert // it to LPWSTR before the wvsprintf() // va_start(vaList, pszFormat); #ifdef UNICODE MultiByteToWideChar(CP_ACP, 0, pszFormat, -1, FormatBuf, COUNT_ARRAY(FormatBuf)); StringCchVPrintf(OutBuf, COUNT_ARRAY(OutBuf), FormatBuf, vaList); #else StringCchVPrintf(OutBuf, COUNT_ARRAY(OutBuf), pszFormat, vaList); #endif va_end(vaList); OutputDebugString((LPTSTR)OutBuf); OutputDebugString(TEXT("\n")); }
void RTrace(TCHAR* szFormat, ...) { #ifdef MESSAGE_TRACE TCHAR szTempBuf[2048] ; va_list vlMarker ; va_start(vlMarker,szFormat) ; StringCchVPrintf(szTempBuf, 2048, szFormat, vlMarker) ; va_end(vlMarker) ; #ifdef LOG_FILE_DEBUG USES_CONVERSION; char des[2048]; CFile logFile; int z = (int)wcslen(szTempBuf); wcstombs(des, szTempBuf, z); des[z - 1] = 0x0d; des[z] = 0x0a; logFile.Open(L"C:\\Earzone\\EzCam\\EzCamLog.txt", CFile::modeCreate | CFile::modeWrite | CFile::modeNoTruncate); logFile.SeekToEnd(); logFile.Write(des, z + 1); logFile.Close(); #endif // CODEC DEBUG OutputDebugString(szTempBuf) ; #endif // MESSAGE_TRACE }
/// Function name : appendStringToTextStreamf // Description : Appends a formatted string to a TextStream object /// NB: New strings are limited to an expanded size of MAX_STRING characters // // TEXT_STREAM* pTextStream : [in/out] TextStream to append // CONST TCHAR* szFormat : [in] Printf-style formatting string // ... ... : [in][optional] Arguments // BearScriptAPI VOID appendStringToTextStreamf(TEXT_STREAM* pTextStream, CONST TCHAR* szFormat, ...) { va_list pArguments; // Variable argument pointer // Prepare pArguments = utilGetFirstVariableArgument(&szFormat); /// Assemble input text StringCchVPrintf(pTextStream->szAssembledText, MAX_STRING, szFormat, pArguments); // [CHECK] Extend buffer if necessary //if (pTextStream->iBufferUsed > utilCalculatePercentage(pTextStream->iBufferSize, 85)) // Extend stream if buffer more than 85% full if (pTextStream->iBufferUsed + lstrlen(pTextStream->szAssembledText) >= pTextStream->iBufferSize) { pTextStream->iBufferSize *= 2; pTextStream->szBuffer = utilExtendString(pTextStream->szBuffer, pTextStream->iBufferUsed, pTextStream->iBufferSize); } /// Append input text to existing buffer StringCchCopy(getTextStreamBuffer(pTextStream), pTextStream->iBufferSize - pTextStream->iBufferUsed, pTextStream->szAssembledText); // Increment current position pTextStream->iBufferUsed += lstrlen(pTextStream->szAssembledText); }
BOOL WINAPIV LSLogPrintf(int nLevel, LPCSTR pszModule, LPCSTR pszFormat, ...) { #if defined(LS_COMPAT_LOGGING) if (!pszModule || !pszFormat) { return FALSE; } BOOL bReturn = FALSE; char szMessage[MAX_LINE_LENGTH]; va_list argList; va_start(argList, pszFormat); if (SUCCEEDED(StringCchVPrintf(szMessage, MAX_LINE_LENGTH, pszFormat, argList))) { bReturn = LSLog(nLevel, pszModule, szMessage); } va_end(argList); return bReturn; #else return TRUE; #endif // LS_COMPAT_LOGGING }
extern void _tMyPrintf(IN LPCTSTR tracemsg, ...) { TCHAR buf[MAX_PATH + 2048] = { 0 }; HRESULT ret; __try { va_list ptr; va_start(ptr, tracemsg); ret = StringCchVPrintf( buf, MAX_PATH + 2048, tracemsg, ptr ); if (ret == S_OK) { DWORD ws; WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), buf, (DWORD)_tcslen(buf), &ws, NULL); } } __finally { ; } return; }
void WINAPI DbgBreakPoint(LPCTSTR pFileName,INT iLine,__format_string LPCTSTR szFormatString,...) { // A debug break point message can have at most 2000 characters if // ANSI or UNICODE characters are being used. A debug break point message // can have between 1000 and 2000 double byte characters in it. If a // particular message needs more characters, then the value of this constant // should be increased. const DWORD MAX_BREAK_POINT_MESSAGE_SIZE = 2000; TCHAR szBreakPointMessage[MAX_BREAK_POINT_MESSAGE_SIZE]; va_list va; va_start( va, szFormatString ); HRESULT hr = StringCchVPrintf( szBreakPointMessage, NUMELMS(szBreakPointMessage), szFormatString, va ); va_end(va); if( FAILED(hr) ) { DbgBreak( "ERROR in DbgBreakPoint(). The variable length debug message could not be displayed because StringCchVPrintf() failed." ); return; } ::DbgBreakPoint( szBreakPointMessage, pFileName, iLine ); }
void AddSPASMErrorSessionAnnotation(int nSession, LPCTSTR lpszFormat, ...) { va_list valist; va_start(valist, lpszFormat); TCHAR szBuffer[256]; TCHAR szDescription[128] = _T("An error occurred"); StringCchVPrintf(szDescription, ARRAYSIZE(szDescription), lpszFormat, valist); StringCchPrintf(szBuffer, ARRAYSIZE(szBuffer), _T("%s:%d: %s"), curr_input_file, line_num, szDescription); va_end(valist); list_t *pList = (list_t *) g_ErrorList; while (pList != NULL) { LPERRORINSTANCE lpErr = (LPERRORINSTANCE) pList->data; if (lpErr->nSession >= nSession) { if (lpErr->lpszAnnotation != NULL) { free(lpErr->lpszAnnotation); } lpErr->lpszAnnotation = _tcsdup(szBuffer); } pList = pList->next; } }
HRESULT CRegisterExtension::RegSetKeyValueBinaryPrintf(HKEY hkey, PCWSTR pszKeyFormatString, PCWSTR pszValueName, PCSTR pszBase64, ...) const { va_list argList; va_start(argList, pszBase64); WCHAR szKeyName[512]; HRESULT hr = StringCchVPrintf(szKeyName, ARRAYSIZE(szKeyName), pszKeyFormatString, argList); if (SUCCEEDED(hr)) { DWORD dwDecodedImageSize, dwSkipChars, dwActualFormat; hr = CryptStringToBinaryA(pszBase64, NULL, CRYPT_STRING_BASE64, NULL, &dwDecodedImageSize, &dwSkipChars, &dwActualFormat) ? S_OK : E_FAIL; if (SUCCEEDED(hr)) { BYTE *pbDecodedImage = (BYTE*)LocalAlloc(LPTR, dwDecodedImageSize); hr = pbDecodedImage ? S_OK : E_OUTOFMEMORY; if (SUCCEEDED(hr)) { hr = CryptStringToBinaryA(pszBase64, lstrlenA(pszBase64), CRYPT_STRING_BASE64, pbDecodedImage, &dwDecodedImageSize, &dwSkipChars, &dwActualFormat) ? S_OK : E_FAIL; if (SUCCEEDED(hr)) { hr = HRESULT_FROM_WIN32(RegSetKeyValueW(hkey, szKeyName, pszValueName, REG_BINARY, pbDecodedImage, dwDecodedImageSize)); } } } } va_end(argList); _UpdateAssocChanged(hr, pszKeyFormatString); return hr; }
// // warning -- this function is implemented twice for ansi applications // linking to the unicode library // void WINAPI DbgLogInfo(DWORD Type,DWORD Level,LPCTSTR pFormat,...) { /* Check the current level for this type combination */ BOOL bAccept = DbgCheckModuleLevel(Type,Level); if (bAccept == FALSE) { return; } TCHAR szInfo[2000]; /* Format the variable length parameter list */ va_list va; va_start(va, pFormat); (void)StringCchPrintf(szInfo, NUMELMS(szInfo), TEXT("%s(tid %x) %8d : "), m_ModuleName, GetCurrentThreadId(), timeGetTime() - dwTimeOffset); (void)StringCchVPrintf(szInfo + lstrlen(szInfo), NUMELMS(szInfo) - lstrlen(szInfo), pFormat, va); (void)StringCchCat(szInfo, NUMELMS(szInfo), TEXT("\r\n")); DbgOutString(szInfo); va_end(va); }
void CControlsModule::WriteLog (LPCWSTR pfunction, int line, LPCWSTR pformat, ...) { LPWSTR pmessage = new WCHAR [256]; va_list args; va_start (args, pformat); StringCchVPrintf (pmessage, 256, pformat, args); Log (PB_LOG_WARNING, pmessage, pfunction, line); delete [] pmessage; }
void OutputFormattedDebugString(PCWSTR pszFormat, ...) { TCHAR szBuffer[1024]; va_list pArgPtr; va_start(pArgPtr, pszFormat); StringCchVPrintf(szBuffer, ARRAYSIZE(szBuffer), pszFormat, pArgPtr); va_end(pArgPtr); OutputDebugString(szBuffer); }
BOOL PRINT_ERRMSG(LPCTSTR szError,...) { static TCHAR szBuff[128] = PREFIX; va_list vl; va_start(vl, szError); StringCchVPrintf(szBuff + PREFIX_LEN, (128-PREFIX_LEN), szError, vl); OutputDebugString(szBuff); va_end(vl); return FALSE; }
int MCDECL wsprtf( PTSTR pf, ... ) { static WCHAR _s_sprtfwbuf[1024]; PWSTR pb = _s_sprtfwbuf; int i = 1; va_list arglist; va_start(arglist, pf); *pb = 0; StringCchVPrintf(pb,1024,pf,arglist); va_end(arglist); wprt(pb); return i; }
void AppState::LogInfo(const TCHAR *pszFormat, ...) { if (_logFile.m_hFile != INVALID_HANDLE_VALUE) { TCHAR szMessage[MAX_PATH]; va_list argList; va_start(argList, pszFormat); StringCchVPrintf(szMessage, ARRAYSIZE(szMessage), pszFormat, argList); StringCchCat(szMessage, ARRAYSIZE(szMessage), TEXT("\n")); _logFile.Write(szMessage, lstrlen(szMessage) * sizeof(TCHAR)); va_end(argList); } }
// // OutputTraceString // // multiple argument front-end to OutputDebugString // void OutputTraceString(LPTSTR lpszFormatString, ...) { const DWORD MAX_DEBUGSTR = 256; // max string for ouput va_list arglist; // variable argument list TCHAR szOutputString[MAX_DEBUGSTR]; // the string to print - limited // create the new string limited to the char count as indicated va_start(arglist, lpszFormatString); StringCchVPrintf(szOutputString, CELEMS( szOutputString ), lpszFormatString, arglist); va_end(arglist); // send it out OutputDebugString(szOutputString); }
// // GetResStrEx // void GetResStrEx(HINSTANCE hInstance, UINT uIDText, LPSTR pszText, size_t cchText, LPCSTR pszDefText, ...) { char szFormat[MAX_LINE_LENGTH]; va_list vargs; if (pszText != NULL && cchText > 0) { GetResStr(hInstance, uIDText, szFormat, MAX_LINE_LENGTH, pszDefText); va_start(vargs, pszDefText); StringCchVPrintf(pszText, cchText, szFormat, vargs); va_end(vargs); } }
static void SetLastSPASMProblem(DWORD dwErrorCode, bool fIsWarning, va_list valist) { if (dwErrorCode == SPASM_ERR_SUCCESS) { return; } LPERRORINSTANCE lpErr = AllocErrorInstance(); lpErr->dwErrorCode = dwErrorCode; lpErr->line_num = line_num; lpErr->lpszFileName = _strdup(curr_input_file); //lpErr->fSuppressErrors = suppress_errors; lpErr->fIsWarning = fIsWarning; TCHAR szBuffer[256]; TCHAR szDescription[128] = _T("An error occurred"); for (int i = 0; i < ARRAYSIZE(g_ErrorCodes); i++) { if (g_ErrorCodes[i].dwCode == lpErr->dwErrorCode) { StringCchVPrintf(szDescription, ARRAYSIZE(szDescription), g_ErrorCodes[i].lpszDescription, valist); break; } } LPCTSTR lpszProblemType = (fIsWarning) ? _T("warning") : _T("error"); LPCTSTR lpszProblemCode = (fIsWarning) ? _T("SW") : _T("SE"); if (lpErr->line_num != -1) { StringCchPrintf(szBuffer, ARRAYSIZE(szBuffer), _T("%s:%d: %s %s%03X: %s"), lpErr->lpszFileName, lpErr->line_num, lpszProblemType, lpszProblemCode, lpErr->dwErrorCode, szDescription); } else { StringCchPrintf(szBuffer, ARRAYSIZE(szBuffer), _T("%s: %s %s%03X: %s"), lpErr->lpszFileName, lpszProblemType, lpszProblemCode, lpErr->dwErrorCode, szDescription); } lpErr->lpszErrorText = _strdup(szBuffer); g_ErrorList = (errorlist_t *) list_prepend((list_t *) g_ErrorList, (LPVOID) lpErr); //if (suppress_errors == false) //{ //PrintSPASMError(lpErr); //} }
void __logHelper(PCWSTR pszFmt, ...) { if (g_hStdOut == NULL) { return; } va_list arg; va_start(arg, pszFmt); HRESULT hr = StringCchVPrintf(s_szBuffer, ARRAYSIZE(s_szBuffer), pszFmt, arg); if (SUCCEEDED(hr) || (hr == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER))) { WriteConsole(g_hStdOut, s_szBuffer, wcslen(s_szBuffer), NULL, NULL); } }
void Debug(LPCTSTR szFormat, ...) { static TCHAR szHeader[] = TEXT("TUXTest: "); TCHAR szBuffer[1024]; va_list pArgs; va_start(pArgs, szFormat); wcscpy_s(szBuffer,_countof(szBuffer),szHeader); VERIFY(SUCCEEDED(StringCchVPrintf((szBuffer + wcslen(szHeader)), (_countof(szBuffer)-wcslen(szHeader)) , szFormat,pArgs))); va_end(pArgs); _tcscat_s(szBuffer, _countof(szBuffer),TEXT("\r\n")); OutputDebugString(szBuffer); }
HRESULT IStream_CchPrintfAsUTF8(IStream *pstm, PCWSTR pszKeyFormatString, ...) { va_list argList; va_start(argList, pszKeyFormatString); WCHAR szBuffer[2048]; HRESULT hr = StringCchVPrintf(szBuffer, ARRAYSIZE(szBuffer), pszKeyFormatString, argList); if (SUCCEEDED(hr)) { hr = IStream_WriteStringAsUTF8(pstm, szBuffer); } va_end(argList); return hr; }
// error conditions static void MessageBoxError ( IN TCHAR * title, IN TCHAR * szfmt, ... ) { TCHAR achbuffer [512] ; va_list va ; va_start (va, szfmt) ; StringCchVPrintf (achbuffer, NUMELMS(achbuffer), szfmt, va) ; MessageBox (NULL, achbuffer, title, MB_OK | MB_ICONEXCLAMATION) ; }
HRESULT CRegisterExtension::RegSetKeyValuePrintf(HKEY hkey, PCWSTR pszKeyFormatString, PCWSTR pszValueName, const unsigned char pc[], DWORD dwSize, ...) const { va_list argList; va_start(argList, pc); WCHAR szKeyName[512]; HRESULT hr = StringCchVPrintf(szKeyName, ARRAYSIZE(szKeyName), pszKeyFormatString, argList); if (SUCCEEDED(hr)) { hr = HRESULT_FROM_WIN32(RegSetKeyValueW(hkey, szKeyName, pszValueName, REG_BINARY, pc, dwSize)); } va_end(argList); _UpdateAssocChanged(hr, pszKeyFormatString); return hr; }
VOID DebugTraceW( IN PWSTR Format, IN ... ) { WCHAR Buffer [0x200]; va_list Arguments; va_start(Arguments, Format); StringCchVPrintf(Buffer, sizeof(Buffer), Format, Arguments); OutputDebugStringW(Buffer); OutputDebugStringW(L"\n"); va_end(Arguments); }
HRESULT CRegisterExtension::RegDeleteKeyValuePrintf(HKEY hkey, PCWSTR pszKeyFormatString, PCWSTR pszValue, ...) const { va_list argList; va_start(argList, pszKeyFormatString); WCHAR szKeyName[512]; HRESULT hr = StringCchVPrintf(szKeyName, ARRAYSIZE(szKeyName), pszKeyFormatString, argList); if (SUCCEEDED(hr)) { hr = HRESULT_FROM_WIN32(RegDeleteKeyValueW(hkey, szKeyName, pszValue)); } va_end(argList); _UpdateAssocChanged(hr, pszKeyFormatString); return MapNotFoundToSuccess(hr); }
HRESULT CRegisterExtension::RegSetKeyValuePrintf(HKEY hkey, PCWSTR pszKeyFormatString, PCWSTR pszValueName, PCWSTR pszValue, ...) const { va_list argList; va_start(argList, pszValue); WCHAR szKeyName[512]; HRESULT hr = StringCchVPrintf(szKeyName, ARRAYSIZE(szKeyName), pszKeyFormatString, argList); if (SUCCEEDED(hr)) { hr = HRESULT_FROM_WIN32(RegSetKeyValueW(hkey, szKeyName, pszValueName, REG_SZ, pszValue, lstrlen(pszValue) * sizeof(*pszValue))); } va_end(argList); _UpdateAssocChanged(hr, pszKeyFormatString); return hr; }
//---------------------------------------------------------------------------- // Função privada que sabe mostrar um erro // void DisplayError(int errorn, const TCHAR * fmtStr, va_list args) { LPVOID errorBuf; TCHAR msgBuffer[MAX_CH_ERROR_MESSAGE]; TCHAR title[MAX_CH_ERROR_TITLE] = TEXT(""); TCHAR * progName; if ( GetConsoleTitle(title, MAX_CH_ERROR_TITLE) ) { progName = _tcsrchr(title, '\\'); if ( progName != NULL ) { if ( progName[ _tcslen(progName)-1 ] == '"') progName[ _tcslen(progName)-1 ] = '\0'; //_stprintf(title, TEXT("Error on %s"), ++progName); StringCchPrintf(title, MAX_CH_ERROR_TITLE, TEXT("Error on %s"), ++progName); } } DWORD res = FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, errorn, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Linguagem por omissão do sistema (LPTSTR) &errorBuf, 0, NULL ); //_vstprintf( msgBuffer, fmtStr, args ); StringCchVPrintf(msgBuffer, MAX_CH_ERROR_MESSAGE, fmtStr, args ); //_stprintf( msgBuffer + _tcsclen(msgBuffer), TEXT(": (%d) %s"), errorn, (res ? errorBuf : "") ); size_t dimMsg = _tcsclen(msgBuffer); StringCchPrintf(msgBuffer + dimMsg, MAX_CH_ERROR_MESSAGE - dimMsg, TEXT(": (%d) %s"), errorn, (res ? errorBuf : TEXT("")) ); MessageBox( NULL, (LPCTSTR)msgBuffer, title, MB_OK | MB_ICONERROR | MB_SETFOREGROUND); // Libertar memória referenciada por lpMsgBuf alocada pela função FormatMessage LocalFree( errorBuf ); } // DisplayError
int print(const char *format, ... ) { char buffer[512]; ZeroMemory(buffer, sizeof(buffer)); va_list list; va_start(list, format); int ret = StringCchVPrintf(buffer, 512, format, list); int len = lstrlen(format); if(ret >= len || GetLastError() == 0) { HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); if(h != INVALID_HANDLE_VALUE) WriteConsole(h, buffer, lstrlen(buffer), (LPDWORD)&len, 0); } return len; }
void Msg(TCHAR *szFormat, ...) { TCHAR szBuffer[1024]; // Large buffer for long filenames or URLs const size_t NUMCHARS = sizeof(szBuffer) / sizeof(szBuffer[0]); const int LASTCHAR = NUMCHARS - 1; // Format the input string va_list pArgs; va_start(pArgs, szFormat); // Use a bounded buffer size to prevent buffer overruns. Limit count to // character size minus one to allow for a NULL terminating character. (void)StringCchVPrintf(szBuffer, NUMCHARS - 1, szFormat, pArgs); va_end(pArgs); // Ensure that the formatted string is NULL-terminated szBuffer[LASTCHAR] = TEXT('\0'); MessageBox(NULL, szBuffer, TEXT("PlayCap Message"), MB_OK | MB_ICONERROR); }
static VOID #pragma prefast(suppress:6262) // Function uses '1036' bytes of stack: exceeds /analyze:stacksize'1024' __Log( IN const CHAR *Format, IN ... ) { TCHAR Buffer[MAXIMUM_BUFFER_SIZE]; va_list Arguments; size_t Length; SP_LOG_TOKEN LogToken; DWORD Category; DWORD Flags; HRESULT Result; va_start(Arguments, Format); Result = StringCchVPrintf(Buffer, MAXIMUM_BUFFER_SIZE, Format, Arguments); va_end(Arguments); if (Result != S_OK && Result != STRSAFE_E_INSUFFICIENT_BUFFER) return; Result = StringCchLength(Buffer, MAXIMUM_BUFFER_SIZE, &Length); if (Result != S_OK) return; LogToken = SetupGetThreadLogToken(); Category = TXTLOG_VENDOR; Flags = TXTLOG_WARNING; SetupWriteTextLog(LogToken, Category, Flags, Buffer); Length = __min(MAXIMUM_BUFFER_SIZE - 1, Length + 2); __analysis_assume(Length < MAXIMUM_BUFFER_SIZE); __analysis_assume(Length >= 2); Buffer[Length] = '\0'; Buffer[Length - 1] = '\n'; Buffer[Length - 2] = '\r'; OutputDebugString(Buffer); }
void SPMessageHelper::Msg( std::string msg, ... ) { TCHAR szBuffer[1024]; // Large buffer for long filenames or URLs const size_t NUMCHARS = sizeof(szBuffer) / sizeof(szBuffer[0]); const int LASTCHAR = NUMCHARS - 1; // Format the input string va_list pArgs; va_start(pArgs, msg); // Use a bounded buffer size to prevent buffer overruns. Limit count to // character size minus one to allow for a NULL terminating character. (void)StringCchVPrintf(szBuffer, NUMCHARS - 1, SPStringHelper::MultiByteCStringToWideChar(msg.c_str()), pArgs); va_end(pArgs); // Ensure that the formatted string is NULL-terminated szBuffer[LASTCHAR] = TEXT('\0'); MessageBox(NULL, szBuffer, TEXT("SPEngine"), MB_OK | MB_ICONERROR); }