示例#1
0
void
Log(const wchar_t *fmt, ...)
{
#if !defined(SHOW_CONSOLE)
  DWORD dwRes = 0;
  if (!GetDWORDRegKey(cehDumpDebugStrings, dwRes) || !dwRes) {
    return;
  }
#endif
  va_list a = nullptr;
  wchar_t szDebugString[1024];
  if(!lstrlenW(fmt))
    return;
  va_start(a,fmt);
  vswprintf(szDebugString, 1024, fmt, a);
  va_end(a);
  if(!lstrlenW(szDebugString))
    return;

  DWORD len;
  WriteConsoleW(sCon, szDebugString, lstrlenW(szDebugString), &len, nullptr);
  WriteConsoleW(sCon, L"\n", 1, &len, nullptr);

  OutputDebugStringW(szDebugString);
  OutputDebugStringW(L"\n");
}
示例#2
0
void console_message_handlert::print(
  unsigned level,
  const std::string &message)
{
  if(verbosity<level)
    return;

  #ifdef _WIN32
  HANDLE out_handle=
    GetStdHandle((level>1)?STD_OUTPUT_HANDLE:STD_ERROR_HANDLE);

  // We use UTF16 when we write to the console,
  // but we write UTF8 otherwise.

  DWORD consoleMode;
  if(GetConsoleMode(out_handle, &consoleMode))
  {
    // writing to the console
    std::wstring wide_message=widen(message);

    DWORD number_written;

    WriteConsoleW(
      out_handle, wide_message.c_str(),
      (DWORD)wide_message.size(), &number_written, NULL);

    WriteConsoleW(out_handle, L"\r\n", 2, &number_written, NULL);
  }
  else
  {
    // writing to a file

    if(level>=4)
    {
      std::cout << message << '\n';

      if(level<=6)
        std::cout << std::flush;
    }
    else
      std::cerr << message << '\n' << std::flush;
  }
  #else
  // We flush after messages of level 6 or lower.
  // We don't for messages of level 7 or higher to improve performance,
  // in particular when writing to NFS.
  // Messages level 3 or lower go to cerr, messages level 4 or
  // above go to cout.

  if(level>=4)
  {
    std::cout << message << '\n';

    if(level<=6)
      std::cout << std::flush;
  }
  else
    std::cerr << message << '\n' << std::flush;
  #endif
}
示例#3
0
void
Log(const wchar_t *fmt, ...)
{
#if !defined(SHOW_CONSOLE)
  return;
#endif
  va_list a = nullptr;
  wchar_t szDebugString[1024];
  if(!lstrlenW(fmt))
    return;
  va_start(a,fmt);
  vswprintf(szDebugString, 1024, fmt, a);
  va_end(a);
  if(!lstrlenW(szDebugString))
    return;

  DWORD len;
  WriteConsoleW(sCon, szDebugString, lstrlenW(szDebugString), &len, nullptr);
  WriteConsoleW(sCon, L"\n", 1, &len, nullptr);

  if (IsDebuggerPresent()) {  
    OutputDebugStringW(szDebugString);
    OutputDebugStringW(L"\n");
  }
}
示例#4
0
文件: tui.c 项目: Moteesh/reactos
static BOOL
TUIDisplayStatusMessage(
    IN PGINA_CONTEXT pgContext,
    IN HDESK hDesktop,
    IN DWORD dwOptions,
    IN PWSTR pTitle,
    IN PWSTR pMessage)
{
    static LPCWSTR newLine = L"\n";
    DWORD result;

    TRACE("TUIDisplayStatusMessage(%ws)\n", pMessage);

    UNREFERENCED_PARAMETER(pgContext);
    UNREFERENCED_PARAMETER(hDesktop);
    UNREFERENCED_PARAMETER(dwOptions);
    UNREFERENCED_PARAMETER(pTitle);

    return
        WriteConsoleW(
            GetStdHandle(STD_OUTPUT_HANDLE),
            pMessage,
            wcslen(pMessage),
            &result,
            NULL) &&
        WriteConsoleW(
            GetStdHandle(STD_OUTPUT_HANDLE),
            newLine,
            wcslen(newLine),
            &result,
            NULL);
}
示例#5
0
文件: tui.c 项目: Moteesh/reactos
static BOOL
DisplayResourceText(
    IN UINT uIdResourceText,
    IN BOOL AddNewLine)
{
    WCHAR Prompt[256];
    static LPCWSTR newLine = L"\n";
    DWORD count;

    if (0 == LoadStringW(hDllInstance, uIdResourceText, Prompt, _countof(Prompt)))
        return FALSE;
    if (!WriteConsoleW(
        GetStdHandle(STD_OUTPUT_HANDLE),
        Prompt, wcslen(Prompt),
        &count, NULL))
    {
        return FALSE;
    }
    if (AddNewLine)
    {
        if (!WriteConsoleW(
            GetStdHandle(STD_OUTPUT_HANDLE),
            newLine, wcslen(newLine),
            &count, NULL))
        {
            return FALSE;
        }
    }
    return TRUE;
}
示例#6
0
文件: host.c 项目: AlexSteel/wine
static void print_string(const WCHAR *string)
{
    DWORD count, ret, len, lena;
    char *buf;

    if(wshInteractive) {
        static const WCHAR windows_script_hostW[] =
            {'W','i','n','d','o','w','s',' ','S','c','r','i','p','t',' ','H','o','s','t',0};
        MessageBoxW(NULL, string, windows_script_hostW, MB_OK);
        return;
    }

    len = strlenW(string);
    ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), string, len, &count, NULL);
    if(ret) {
        static const WCHAR crnlW[] = {'\r','\n'};
        WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), crnlW, sizeof(crnlW)/sizeof(*crnlW), &count, NULL);
        return;
    }

    lena = WideCharToMultiByte(GetConsoleOutputCP(), 0, string, len, NULL, 0, NULL, NULL);
    buf = heap_alloc(len);
    if(!buf)
        return;

    WideCharToMultiByte(GetConsoleOutputCP(), 0, string, len, buf, lena, NULL, NULL);
    WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), buf, lena, &count, FALSE);
    heap_free(buf);
    WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), "\r\n", 2, &count, FALSE);
}
示例#7
0
文件: editline.c 项目: alantsev/wine
static DWORD WCEL_WriteConsole(WCEL_Context* ctx, DWORD beg, DWORD len)
{
    DWORD i, last, dw, ret = 0;
    WCHAR tmp[2];

    for (i = last = 0; i < len; i++)
    {
        if (ctx->line[beg + i] < ' ')
        {
            if (last != i)
            {
                WriteConsoleW(ctx->hConOut, &ctx->line[beg + last], i - last, &dw, NULL);
                ret += dw;
            }
            tmp[0] = '^';
            tmp[1] = '@' + ctx->line[beg + i];
            WriteConsoleW(ctx->hConOut, tmp, 2, &dw, NULL);
            last = i + 1;
            ret += dw;
        }
    }
    if (last != len)
    {
        WriteConsoleW(ctx->hConOut, &ctx->line[beg + last], len - last, &dw, NULL);
        ret += dw;
    }
    return ret;
}
示例#8
0
void Cell::Draw() const
{ //this handles changing the color and shape based on its' members
	_CONSOLE_SCREEN_BUFFER_INFO t;
	HANDLE st = GetStdHandle(STD_OUTPUT_HANDLE);
	GetConsoleScreenBufferInfo(st, &t);

	if(m_touched)
		SetConsoleTextAttribute(st, m_color+1 | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
	else
	SetConsoleTextAttribute(st, m_color+1);

	if(m_shape==1 && m_color==1)//wild
	{
		SetConsoleTextAttribute(st, 15 | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
		wchar_t t[] = {223,0};
		DWORD x;
		WriteConsoleW(st, t, 1, &x, NULL);
	}
	else
	{
		if(m_shape)
		{
			wchar_t t[] = {m_shape+223,0};
			DWORD x;
			WriteConsoleW(st, t, 1, &x, NULL);
		}
		else
		{
			DWORD x;
			WriteConsoleW(st, " ", 1, &x, NULL);
		}
	}
	//change them back
	SetConsoleTextAttribute(st,t.wAttributes);
}
示例#9
0
void wrt_Wchr(WCHAR wc[]){
	IS_HANDLE_NULL;
	DWORD ws;
	WriteConsoleW(hConsole,wc,wcslen(wc),&ws,NULL);
	WCHAR enter[]=L"\r\n";
	WriteConsoleW(hConsole,enter,wcslen(enter),&ws,NULL);
}
示例#10
0
	// async_wait 调用到这里
	void operator()(boost::system::error_code ec)
	{
		DWORD r =0;
		INPUT_RECORD ir;
		ReadConsoleInputW(console_handle.native_handle(), &ir, 1, &r);
		if (ir.EventType == KEY_EVENT && ir.Event.KeyEvent.bKeyDown && ir.Event.KeyEvent.uChar.UnicodeChar)
		{
			WCHAR c = ir.Event.KeyEvent.uChar.UnicodeChar;
			if (c == L'\b')
			{
				// 退格键啊,应该删了
//				WriteConsoleOutputW();
				if (!readbuf.empty())
				{
					WCHAR lc = readbuf.back();
					
					readbuf.pop_back();
					
					if (lc >= 256)
					{
						WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\b \b \b", 5, &r, 0);
					}
					else
					{
						WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\b \b", 3, &r, 0);
					}
				}
			}
			else
			{
				readbuf.push_back(c);
			}

			if (iswprint(c))
			{
				WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), &c, 1, &r, 0);
			}
			// 判定 是不是读取到了 "\n"
			// 是的话就可以调用 handler 了
			if (c == L'\r')
			{
				// 读取到行尾啦!回调吧
				std::string thisline = wide_to_utf8(std::wstring(readbuf.data(), readbuf.size()));
				readbuf.clear();
				WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\n", 1, &r, 0);
				SetConsoleMode(console_handle.native_handle(), m_savedmode);
				m_handler(thisline);
				return;
			}
		}

		// 重复读取
		console_handle.async_wait(*this);
	}
示例#11
0
void WriteOutput(int channel, const char *str)
{
  wstring wstr = StringFormat::UTF82Wide(string(str));

  if(channel == OSUtility::Output_DebugMon)
    OutputDebugStringW(wstr.c_str());
  else if(channel == OSUtility::Output_StdOut)
    WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wstr.c_str(), DWORD(wstr.size()), NULL, NULL);
  else if(channel == OSUtility::Output_StdErr)
    WriteConsoleW(GetStdHandle(STD_ERROR_HANDLE), wstr.c_str(), DWORD(wstr.size()), NULL, NULL);
}
示例#12
0
文件: cui.c 项目: hfiref0x/SXSEXP
/*
* cuiPrintTextW
*
* Purpose:
*
* Output text to the console or file.
* UNICODE version.
*
*/
VOID cuiPrintTextW(
	_In_ LPWSTR lpText,
	_In_ BOOL UseReturn
	)
{
	SIZE_T consoleIO;
	DWORD bytesIO;
	LPWSTR Buffer;

	if (lpText == NULL)
		return;

	consoleIO = _strlen_w(lpText);
	if ((consoleIO == 0) || (consoleIO > MAX_PATH * 4))
		return;

	consoleIO = consoleIO * sizeof(WCHAR) + 4 + sizeof(UNICODE_NULL);
	Buffer = (LPWSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, consoleIO);
	if (Buffer) {

		_strcpy(Buffer, lpText);
		if (UseReturn) _strcat_w(Buffer, TEXT("\r\n"));

		consoleIO = _strlen_w(Buffer);

		if (g_ConsoleOutput != FALSE) {
			WriteConsoleW(g_ConOut, Buffer, (DWORD)consoleIO, &bytesIO, NULL);
		}
		else {
			WriteFile(g_ConOut, Buffer, (DWORD)(consoleIO * sizeof(WCHAR)), &bytesIO, NULL);
		}
		HeapFree(GetProcessHeap(), 0, Buffer);
	}
}
示例#13
0
int aa_fprintf(FILE *fp, const char *fmt, ...)
{
    va_list ap;
    int cnt;
    HANDLE fh = (HANDLE)_get_osfhandle(_fileno(fp));

    if (GetFileType(fh) != FILE_TYPE_CHAR) {
        va_start(ap, fmt);
        cnt = vfprintf(fp, fmt, ap);
        va_end(ap);
    } else {
        char *s;
        wchar_t *ws;
        DWORD nw;

        va_start(ap, fmt);
        cnt = _vscprintf(fmt, ap);
        va_end(ap);

        s = malloc(cnt + 1);
        
        va_start(ap, fmt);
        cnt = _vsnprintf(s, cnt + 1, fmt, ap);
        va_end(ap);

        codepage_decode_wchar(CP_UTF8, s, &ws);
        free(s);
        fflush(fp);
        WriteConsoleW(fh, ws, wcslen(ws), &nw, 0);
        free(ws);
    }
    return cnt;
}
示例#14
0
static void write_console_text(HANDLE wstream, char *buf)
{
    wchar_t *out = mp_from_utf8(NULL, buf);
    size_t out_len = wcslen(out);
    WriteConsoleW(wstream, out, out_len, NULL, NULL);
    talloc_free(out);
}
void WindowsConsoleLogger::write()
{
	if (this->stdOut != NULL) {
		DWORD check;
		WriteConsoleW(this->stdOut, (void*)this->buffer, this->size, &check, NULL);
	}
}
示例#16
0
文件: osdep.c 项目: 0x0B501E7E/x264
int x264_vfprintf( FILE *stream, const char *format, va_list arg )
{
    HANDLE console = NULL;
    DWORD mode;

    if( stream == stdout )
        console = GetStdHandle( STD_OUTPUT_HANDLE );
    else if( stream == stderr )
        console = GetStdHandle( STD_ERROR_HANDLE );

    /* Only attempt to convert to UTF-16 when writing to a non-redirected console screen buffer. */
    if( GetConsoleMode( console, &mode ) )
    {
        char buf[4096];
        wchar_t buf_utf16[4096];
        va_list arg2;

        va_copy( arg2, arg );
        int length = vsnprintf( buf, sizeof(buf), format, arg2 );
        va_end( arg2 );

        if( length > 0 && length < sizeof(buf) )
        {
            /* WriteConsoleW is the most reliable way to output Unicode to a console. */
            int length_utf16 = MultiByteToWideChar( CP_UTF8, 0, buf, length, buf_utf16, sizeof(buf_utf16)/sizeof(wchar_t) );
            DWORD written;
            WriteConsoleW( console, buf_utf16, length_utf16, &written, NULL );
            return length;
        }
    }
    return vfprintf( stream, format, arg );
}
示例#17
0
void _wprintf(LPCWSTR asBuffer)
{
	if (!asBuffer) return;

	int nAllLen = lstrlenW(asBuffer);
	HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
	DWORD dwWritten = 0;

	if (!IsOutputRedirected())
	{
		WriteConsoleW(hOut, asBuffer, nAllLen, &dwWritten, 0);
	}
	else
	{
		UINT  cp = GetConsoleOutputCP();
		int cchMax = WideCharToMultiByte(cp, 0, asBuffer, -1, NULL, 0, NULL, NULL) + 1;
		char* pszOem = (cchMax > 1) ? (char*)malloc(cchMax) : NULL;
		if (pszOem)
		{
			int nWrite = WideCharToMultiByte(cp, 0, asBuffer, -1, pszOem, cchMax, NULL, NULL);
			if (nWrite > 1)
			{
				// Don't write terminating '\0' to redirected output
				WriteFile(hOut, pszOem, nWrite-1, &dwWritten, 0);
			}
			free(pszOem);
		}
	}
}
示例#18
0
 int write(char const *p,int n)
 {
     namespace uf = boost::locale::utf;
     char const *b = p;
     char const *e = p+n;
     if(!isatty_) {
         DWORD size=0;
         if(!WriteFile(handle_,p,n,&size,0) || static_cast<int>(size) != n)
             return -1;
         return n;
     }
     if(n > buffer_size)
         return -1;
     wchar_t *out = wbuffer_;
     uf::code_point c;
     size_t decoded = 0;
     while(p < e && (c = uf::utf_traits<char>::decode(p,e))!=uf::illegal && c!=uf::incomplete) {
         out = uf::utf_traits<wchar_t>::encode(c,out);
         decoded = p-b;
     }
     if(c==uf::illegal)
         return -1;
     if(!WriteConsoleW(handle_,wbuffer_,out - wbuffer_,0,0))
         return -1;
     return decoded;
 }
示例#19
0
static int hostname_vprintfW(const WCHAR *msg, va_list va_args)
{
    int wlen;
    DWORD count, ret;
    WCHAR msg_buffer[8192];

    wlen = vsprintfW(msg_buffer, msg, va_args);

    ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), msg_buffer, wlen, &count, NULL);
    if (!ret)
    {
        DWORD len;
        char *msgA;

        len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen,
            NULL, 0, NULL, NULL);
        msgA = HeapAlloc(GetProcessHeap(), 0, len);
        if (!msgA)
            return 0;

        WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, msgA, len,
            NULL, NULL);
        WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
        HeapFree(GetProcessHeap(), 0, msgA);
    }

    return count;
}
示例#20
0
文件: net.c 项目: aragaer/wine
static int output_write(const WCHAR* str, int len)
{
    DWORD ret, count;
    ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, len, &count, NULL);
    if (!ret)
    {
        DWORD lenA;
        char* strA;

        /* On Windows WriteConsoleW() fails if the output is redirected. So fall
         * back to WriteFile(), assuming the console encoding is still the right
         * one in that case.
         */
        lenA = WideCharToMultiByte(GetConsoleOutputCP(), 0, str, len,
                                   NULL, 0, NULL, NULL);
        strA = HeapAlloc(GetProcessHeap(), 0, lenA);
        if (!strA)
            return 0;

        WideCharToMultiByte(GetConsoleOutputCP(), 0, str, len, strA, lenA,
                            NULL, NULL);
        WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), strA, len, &count, FALSE);
        HeapFree(GetProcessHeap(), 0, strA);
    }
    return count;
}
示例#21
0
文件: start.c 项目: bilboed/wine
/**
 Output given message to stdout without formatting.
*/
static void output(const WCHAR *message)
{
	DWORD count;
	DWORD   res;
	int    wlen = strlenW(message);

	if (!wlen) return;

	res = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), message, wlen, &count, NULL);

	/* If writing to console fails, assume its file
	i/o so convert to OEM codepage and output                  */
	if (!res)
	{
		DWORD len;
		char  *mesA;
		/* Convert to OEM, then output */
		len = WideCharToMultiByte( GetConsoleOutputCP(), 0, message, wlen, NULL, 0, NULL, NULL );
		mesA = HeapAlloc(GetProcessHeap(), 0, len*sizeof(char));
		if (!mesA) return;
		WideCharToMultiByte( GetConsoleOutputCP(), 0, message, wlen, mesA, len, NULL, NULL );
		WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), mesA, len, &count, FALSE);
		HeapFree(GetProcessHeap(), 0, mesA);
	}
}
示例#22
0
size_t
mm_stdio_c::_write(const void *buffer,
                   size_t size) {
  HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
  if (INVALID_HANDLE_VALUE == h_stdout)
    return 0;

  DWORD file_type = GetFileType(h_stdout);
  bool is_console = false;
  if ((FILE_TYPE_UNKNOWN != file_type) && ((file_type & ~FILE_TYPE_REMOTE) == FILE_TYPE_CHAR)) {
    DWORD dummy;
    is_console = GetConsoleMode(h_stdout, &dummy);
  }

  if (is_console) {
    const std::wstring &w = to_wide(g_cc_stdio->utf8(std::string(static_cast<const char *>(buffer), size)));
    DWORD bytes_written   = 0;

    WriteConsoleW(h_stdout, w.c_str(), w.length(), &bytes_written, NULL);

    return bytes_written;
  }

  size_t bytes_written = fwrite(buffer, 1, size, stdout);
  fflush(stdout);

  m_cached_size = -1;

  return bytes_written;
}
示例#23
0
void TestWriteConsole::test1()
{
    //㘵
    HANDLE std_output = GetStdHandle( STD_OUTPUT_HANDLE );
    std::wstring ws = L"㘵中华人民共和国abc\n";
    WriteConsoleW( std_output, ws.c_str(), ws.size(), NULL, NULL );
}
示例#24
0
static int
flush_ansi(ansi_stream *as)
{ size_t written = 0;

  while ( written < as->buffered )
  { BOOL rc;
    DWORD done;

    rc = WriteConsoleW(as->hConsole,
		       &as->buffer[written],
		       (DWORD)(as->buffered-written),
		       &done,
		       NULL);

    if ( rc )
    { written += done;
    } else
    { as->buffered = 0;
      return -1;
    }
  }

  as->buffered = 0;
  return 0;
}
示例#25
0
		virtual int_type overflow(int_type ch)
		{
			DWORD n;
			char_type _ch = (char_type)ch;
			WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), &_ch, 1, &n, NULL);
			return 0;
		}
示例#26
0
文件: knj.c 项目: ahnan4arch/ptex-ng
/*
  fopen by file system codepage
*/
FILE *
fsyscp_fopen (const char *filename, const char *mode)
{
    FILE *f;
    wchar_t *fnamew, modew[4];
    int i;
#if defined (KPSE_COMPAT_API)
    kpathsea kpse;
#endif
    assert(filename && mode);

    fnamew = get_wstring_from_fsyscp(filename, fnamew=NULL);
    for(i=0; (modew[i]=(wchar_t)mode[i]); i++) {} /* mode[i] must be ASCII */
    f = _wfopen(fnamew, modew);
#if defined (KPSE_COMPAT_API)
    if (f != NULL) {
        kpse = kpse_def;
        if (KPATHSEA_DEBUG_P (KPSE_DEBUG_FOPEN)) {
            DEBUGF_START ();
            fprintf (stderr, "fsyscp_fopen(%s [", filename);
            WriteConsoleW( GetStdHandle( STD_ERROR_HANDLE ), fnamew, wcslen( fnamew ), NULL, NULL );
#if defined(_WIN64)
            fprintf (stderr, "], %s) => 0x%I64x\n", mode, (unsigned __int64) f);
#else
            fprintf (stderr, "], %s) => 0x%lx\n", mode, (unsigned long) f);
#endif
            DEBUGF_END ();
        }
    }
#endif
    free(fnamew);

    return f;
}
示例#27
0
static int reg_printfW(const WCHAR *msg, ...)
{
    va_list va_args;
    int wlen;
    DWORD count, ret;
    WCHAR msg_buffer[8192];

    va_start(va_args, msg);
    vsprintfW(msg_buffer, msg, va_args);
    va_end(va_args);

    wlen = lstrlenW(msg_buffer);
    ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), msg_buffer, wlen, &count, NULL);
    if (!ret)
    {
        DWORD len;
        char  *msgA;

        len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen,
                                  NULL, 0, NULL, NULL);
        msgA = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
        if (!msgA)
            return 0;

        WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, msgA, len,
                            NULL, NULL);
        WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
        HeapFree(GetProcessHeap(), 0, msgA);
    }

    return count;
}
示例#28
0
//------------------------------------------------------------------------------
int hooked_fwrite(const void* data, int size, int count, void* unused)
{
    wchar_t buf[2048];
    size_t characters;
    DWORD written;

    size *= count;
    
    characters = MultiByteToWideChar(
        CP_UTF8, 0,
        (const char*)data, size,
        buf, sizeof_array(buf)
    );

    characters = characters ? characters : sizeof_array(buf) - 1;
    buf[characters] = L'\0';

    if (g_alt_fwrite_hook)
    {
        g_alt_fwrite_hook(buf);
    }
    else
    {
        HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
        WriteConsoleW(handle, buf, (DWORD)wcslen(buf), &written, NULL);
    }

    return size;
}
示例#29
0
static int taskkill_vprintfW(const WCHAR *msg, __ms_va_list va_args)
{
    int wlen;
    DWORD count, ret;
    WCHAR msg_buffer[8192];

    wlen = FormatMessageW(FORMAT_MESSAGE_FROM_STRING, msg, 0, 0, msg_buffer,
                          sizeof(msg_buffer)/sizeof(*msg_buffer), &va_args);

    ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), msg_buffer, wlen, &count, NULL);
    if (!ret)
    {
        DWORD len;
        char *msgA;

        /* On Windows WriteConsoleW() fails if the output is redirected. So fall
         * back to WriteFile(), assuming the console encoding is still the right
         * one in that case.
         */
        len = WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen,
            NULL, 0, NULL, NULL);
        msgA = HeapAlloc(GetProcessHeap(), 0, len);
        if (!msgA)
            return 0;

        WideCharToMultiByte(GetConsoleOutputCP(), 0, msg_buffer, wlen, msgA, len,
            NULL, NULL);
        WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
        HeapFree(GetProcessHeap(), 0, msgA);
    }

    return count;
}
示例#30
0
 DWORD write(char const *p, DWORD n)
 {
     namespace uf = nowide::utf;
     char const *b = p;
     char const *e = p+n;
     DWORD size=0;
     if(!isatty_) {
         if(!WriteFile(handle_,p,n,&size,0) || size != n)
             return -1;
         return n;
     }
     if(n > buffer_size)
         return -1;
     wchar_t *out = wbuffer_;
     uf::code_point c;
     DWORD decoded = 0;
     while(p < e && (c = uf::utf_traits<char>::decode(p,e))!=uf::illegal && c!=uf::incomplete) {
         out = uf::utf_traits<wchar_t>::encode(c,out);
         decoded = static_cast<DWORD>(p-b);
     }
     if(c==uf::illegal)
         return -1;
     if(!WriteConsoleW(handle_,wbuffer_, static_cast<DWORD>(out - wbuffer_),&size,0))
         return -1;
     return decoded;
 }