Exemple #1
0
    // -------------------------------------------------------------------------
    bool Logger::IsFailureLog(HRESULT hr, const wchar_t * fmt, ...)
    {

        if (SUCCEEDED(hr))
            return false;

        LPWSTR wstr;
        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
				FORMAT_MESSAGE_IGNORE_INSERTS 	 |
				FORMAT_MESSAGE_ALLOCATE_BUFFER,
				NULL,
				hr,
				MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
				(LPTSTR) &wstr,
				0,
				NULL);

       
        if (!fmt)
        {
            Log(OutputMessageType::Error, L"HRESULT: '%s'\n", wstr);
        }
        else
        {
            wchar_t wbuffer[c_bufferSize];
            va_list args;
            va_start(args, fmt);
            _vsnwprintf_s(wbuffer, c_bufferSize, _TRUNCATE, fmt, args);           
            Log(OutputMessageType::Error, L"HRESULT: '%s' in context '%s'\n", wstr, wbuffer);
            va_end(args);
        }

        return true;
    }
Exemple #2
0
void CDX10Renderer::PrintAllignedTextF(std::string _strMessage, const TRect& _rRect, unsigned int _uiHorizAllignment, unsigned int _uVertAllignment, ...)
{
	if(_strMessage.size() == 0)
		return;

	std::wstring wstrTo;
    wchar_t *wszTo = new wchar_t[_strMessage.length() + 1];
    wszTo[_strMessage.size()] = L'\0';
    MultiByteToWideChar(CP_ACP, 0, _strMessage.c_str(), -1, wszTo, (int)_strMessage.length());
    wstrTo = wszTo;

	va_list arg;
	va_start(arg, _uVertAllignment);
	_vsnwprintf_s(m_pBufferW, m_uBufferSize, m_uBufferSize, wszTo, arg);
	va_end(arg);

	delete[] wszTo;

	RECT rect;
	rect.left = static_cast<long>(_rRect.x1);
	rect.right = static_cast<long>(_rRect.x2);
	rect.top = static_cast<long>(_rRect.y1);
	rect.bottom = static_cast<long>(_rRect.y2);

	unsigned int uiFlags = _uiHorizAllignment | _uVertAllignment | DT_NOCLIP;

	m_pSprite->Begin(D3DX10_SPRITE_SAVE_STATE);
	m_pFont->DrawText(0, m_pBufferW, -1, &rect, uiFlags, m_uiPenColour);
	m_pSprite->End();
}
Exemple #3
0
void CDX10Renderer::PrintTextF(std::string _strMessage, const TVector2& _rv2Position, ...)
{
	if(_strMessage.size() == 0)
	return;
 
	std::wstring wstrTo;
    wchar_t *wszTo = new wchar_t[_strMessage.length() + 1];
    wszTo[_strMessage.size()] = L'\0';
    MultiByteToWideChar(CP_ACP, 0, _strMessage.c_str(), -1, wszTo, (int)_strMessage.length());
    wstrTo = wszTo;

	va_list arg;
	va_start(arg, _rv2Position);
	_vsnwprintf_s(m_pBufferW, m_uBufferSize, m_uBufferSize, wszTo, arg);
	va_end(arg);

	delete[] wszTo;
	
	RECT rect;
	rect.left = static_cast<long>(_rv2Position.x);
	rect.right = static_cast<long>(_rv2Position.x + 1000.0f);
	rect.top = static_cast<long>(_rv2Position.y);
	rect.bottom = static_cast<long>(_rv2Position.y + 1000.0f);

	m_pFont->DrawText(0, m_pBufferW, -1, &rect, DT_NOCLIP, m_uiPenColour);
}
Exemple #4
0
void OutputDebugInfo(const char *pFileName, const wchar_t *pFormat, ...)
{
	DWORD dwLastError = GetLastError();
	va_list ArgList;
	va_start(ArgList, pFormat);

	wchar_t Buffer[1024];
	int WideLen = _vsnwprintf_s(Buffer, 1024, _TRUNCATE, pFormat, ArgList);
	if (WideLen < 0)
	{
		Buffer[1023] = 0;
		WideLen = (int) wcslen(Buffer);
	}
	va_end(ArgList);

	char Buffer2[2048];
	int Length = WideCharToMultiByte(CP_ACP, 0, Buffer, WideLen, NULL, 0, NULL, NULL);
	_ASSERTE(Length < sizeof(Buffer2));
	WideCharToMultiByte(CP_ACP, 0, Buffer, WideLen, Buffer2, Length, NULL, NULL);
	Buffer2[Length] = 0;

	putLog(pFileName, Buffer2);

	SetLastError(dwLastError);
}
Exemple #5
0
void _vdebugPrintf(const wchar_t* format, va_list va) {
#ifdef _DEBUG
    wchar_t buf[c_bufferCount];
    _vsnwprintf_s(buf, _countof(buf), _TRUNCATE, format, va);
    OutputDebugStringW(buf);
#endif
}
Exemple #6
0
static void
error(int rc, wchar_t * format, ... )
{
    va_list va;
    wchar_t message[MSGSIZE];
    wchar_t win_message[MSGSIZE];
    int len;

    va_start(va, format);
    len = _vsnwprintf_s(message, MSGSIZE, _TRUNCATE, format, va);

    if (rc == 0) {  /* a Windows error */
        winerror(GetLastError(), win_message, MSGSIZE);
        if (len >= 0) {
            _snwprintf_s(&message[len], MSGSIZE - len, _TRUNCATE, L": %ls",
                         win_message);
        }
    }

#if !defined(_WINDOWS)
    fwprintf(stderr, L"%ls\n", message);
#else
    MessageBox(NULL, message, TEXT("Python Launcher is sorry to say ..."),
               MB_OK);
#endif
    exit(rc);
}
Exemple #7
0
WCHAR *FmtV(const WCHAR *fmt, va_list args)
{
    WCHAR   message[256];
    size_t  bufCchSize = dimof(message);
    WCHAR * buf = message;
    for (;;)
    {
        int count = _vsnwprintf_s(buf, bufCchSize, _TRUNCATE, fmt, args);
        if ((count >= 0) && ((size_t)count < bufCchSize))
            break;
        /* we have to make the buffer bigger. The algorithm used to calculate
           the new size is arbitrary (aka. educated guess) */
        if (buf != message)
            free(buf);
        if (bufCchSize < 4*1024)
            bufCchSize += bufCchSize;
        else
            bufCchSize += 1024;
        buf = AllocArray<WCHAR>(bufCchSize);
        if (!buf)
            break;
    }
    if (buf == message)
        buf = str::Dup(message);

    return buf;
}
Exemple #8
0
static int _outputvws_safe(wchar_t* buf, int cnt, const wchar_t* fmt, va_list ap)
{
	int ret;

#if defined(_MSC_VER)
	if (NULL == buf || 0 == cnt)
		return _vscwprintf(fmt, ap);
	#if _MSC_VER >= 1500
	ret = _vsnwprintf_s(buf, cnt, _TRUNCATE, fmt, ap);
	#else
	ret = _vsnwprintf(buf, cnt, fmt, ap);
	#endif
#else
	ret = vsnwprintf(buf, cnt, fmt, ap);
#endif
	
	if (NULL != buf && cnt > 0){
		if (ret < 0)
			buf[cnt-1] = 0;
		else if (ret >= cnt)
			ret = -1;
	}

	return ret;
}
Exemple #9
0
void __DEBUG_MSG__(const WCHAR* szFormat, va_list args)
{
    const size_t SIZE = 4096;   
    WCHAR szBuf[SIZE] = {0}; 
    _vsnwprintf_s(szBuf, SIZE, SIZE, szFormat, args);
    lstrcatW(szBuf, L"\n");
    DebugConsole::Printf(GetStdString(szBuf).c_str());
}
Exemple #10
0
wstring Format(wstring const &str, ...)
{
	va_list v;
	va_start(v, str);
	WCHAR buffer[8192];
	_vsnwprintf_s(buffer, ARRAYSIZE(buffer) - 1, str.c_str(), v);
	return buffer;
}
Exemple #11
0
wstring Format(WCHAR const *fmt, ...)
{
	va_list v;
	va_start(v, fmt);
	WCHAR buffer[8192];
	_vsnwprintf_s(buffer, ARRAYSIZE(buffer) - 1, fmt, v);
	return buffer;
}
Exemple #12
0
void TRACE(wstring const &format, ...)
{
	va_list v;
	va_start(v, format);
	WCHAR buffer[8192];
	_vsnwprintf_s(buffer, ARRAYSIZE(buffer) - 1, format.c_str(), v);
	OutputDebugStringW(buffer);
}
// vsprintfのUNICODE(std::wstring)版
int unicode_format_va( std::wstring& str,LPCWSTR format,va_list va )
{
	int len=_vscwprintf( format,va );
	str.resize( len );
	_vsnwprintf_s( const_cast<wchar_t*>(str.c_str()),_TRUNCATE,str.size(),format,va );

	return len;
}
Exemple #14
0
void _PezFatalErrorW(const wchar_t* pStr, va_list a)
{
    wchar_t msg[1024] = {0};
    _vsnwprintf_s(msg, _countof(msg), _TRUNCATE, pStr, a);
    OutputDebugStringW(msg);
    OutputDebugStringA("\n");
    exit(1);
}
Exemple #15
0
wstring Format(wstring const &str, ...)
{
	va_list v;
	va_start(v, str);
	WCHAR buffer[8192];
	_vsnwprintf_s(buffer, _TRUNCATE, str.c_str(), v);
	return buffer;
}
Exemple #16
0
wstring Format(WCHAR const *fmt, ...)
{
	va_list v;
	va_start(v, fmt);
	WCHAR buffer[8192];
	_vsnwprintf_s(buffer, _TRUNCATE, fmt, v);
	return buffer;
}
Exemple #17
0
inline void DebugStringL(const wchar_t* pStr, ...)
{
    va_list a;
    va_start(a, pStr);

    wchar_t msg[1024] = {0};
    int vsize = _vsnwprintf_s(msg, _countof(msg), _TRUNCATE, pStr, a);
    OutputDebugStringW(msg);
}
Exemple #18
0
 // -------------------------------------------------------------------------
 void Logger::LogVA(OutputMessageType::OutputMessageType type, const WCHAR * fmt, va_list args)
 {
     wchar_t wbuffer[c_bufferSize];
     _vsnwprintf_s(wbuffer, c_bufferSize, _TRUNCATE, fmt, args);           
     if(s_callback)
         s_callback((int)type, wbuffer);
     else
         wprintf(wbuffer);
 }
Exemple #19
0
std::wstring Format(wchar const *fmt, ...)
{
	wchar buffer[512];

	va_list v;
	va_start(v, fmt);
	_vsnwprintf_s(buffer, 512, fmt, v);
	return std::wstring(buffer);
}
Exemple #20
0
void TRACE(wchar const *strMsg, ...)
{
	wchar strBuffer[512];
	va_list args;
	va_start(args, strMsg);
	_vsnwprintf_s(strBuffer, 512, strMsg, args);
	va_end(args);
	OutputDebugStringW(strBuffer);
}
Exemple #21
0
String Format(const wchar_t* fmt, ...)
{
	wchar_t buf[8192];
	va_list args;
	va_start(args, fmt);
	_vsnwprintf_s(buf, 8192, fmt, args);
	va_end(args);
	return buf;
}
Exemple #22
0
std::wstring wstrFormat(const std::wstring strFmt, ...)
{
	WCHAR buff[4096] = {0};
	va_list vl;
	va_start (vl, strFmt);
	_vsnwprintf_s (buff, 10240, strFmt.c_str(), vl);
	va_end (vl);
	return buff;
}
Exemple #23
0
	int shared_snprintf(wchar_t* pszwDst, uint32 uDstLength, const wchar_t* pszwFormat, ...)
	{
		va_list args;
		va_start(args, pszwFormat);
		int nRet = _vsnwprintf_s(pszwDst, _TRUNCATE, uDstLength-1, pszwFormat, args);
		va_end(args);

		return nRet;
	}
Exemple #24
0
// Call OutputDebugString with a format string and some printf-style arguments.
void debugPrintf(_Printf_format_string_ const wchar_t* pFormat, ...)
{
	va_list args;
	va_start(args, pFormat);
	// 1 K maximum is imposed by OutputDebugString.
	wchar_t buffer[1024];
	_vsnwprintf_s(buffer, _TRUNCATE, pFormat, args);
	va_end(args);
	OutputDebugString(buffer);
}
Exemple #25
0
// Return a string from a format string and some printf-style arguments.
std::wstring stringPrintf(_Printf_format_string_ const wchar_t* pFormat, ...)
{
	va_list args;
	va_start(args, pFormat);
	// 4 K should be enough for anyone and it keeps this function simple.
	wchar_t buffer[4096];
	_vsnwprintf_s(buffer, _TRUNCATE, pFormat, args);
	va_end(args);
	return buffer;
}
Exemple #26
0
void PezDebugStringW(const wchar_t* pStr, ...)
{
    wchar_t msg[1024] = {0};

    va_list a;
    va_start(a, pStr);

    _vsnwprintf_s(msg, _countof(msg), _TRUNCATE, pStr, a);
    OutputDebugStringW(msg);
}
Exemple #27
0
xstring xformat(const wchar_t* fmt, ...)
{
	static const size_t kBuffSize = 4096 * 4096;
	std::vector<wchar_t> buff(kBuffSize, '\0');
	va_list v;
	va_start(v, fmt);
	_vsnwprintf_s(&buff[0], kBuffSize, _TRUNCATE, fmt, v);
	va_end(v);
	return xstring(&buff[0]);
}
std::wstring StringUtilities::Format(const wchar_t* format, ...) {
  va_list args;
  va_start(args, format);
  size_t buffer_size = _vscwprintf(format, args);
  std::vector<wchar_t> buffer(buffer_size + 1);
  _vsnwprintf_s(&buffer[0], buffer.size(), buffer_size + 1, format, args);
  va_end(args);
  std::wstring formatted = &buffer[0];
  return formatted;
}
Exemple #29
0
void strprintf(std::wstring& sOut, const wchar_t* fmt, ...)
{
    if (sOut.size() < maxFormatString)
    {
        sOut.resize(maxFormatString);
    }
    va_list args;
    va_start(args, fmt);
    _vsnwprintf_s((wchar_t*)sOut.data(), sOut.size(), maxFormatString, fmt, args);
    va_end(args);
}
Exemple #30
0
void DBG(const wchar_t * format, ...)
{
	wchar_t buffer[256];

	va_list ap;
	va_start(ap, format);
	_vsnwprintf_s(buffer, 256, _TRUNCATE, format, ap);
	va_end(ap);	

	OutputDebugString(buffer);
}