2016-02-04 12:42:05 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
*
|
2017-04-17 19:45:41 +08:00
|
|
|
* (C) COPYRIGHT AUTHORS, 2016 - 2017
|
2016-02-04 12:42:05 +08:00
|
|
|
*
|
|
|
|
* TITLE: CUI.C
|
|
|
|
*
|
2017-04-17 19:45:41 +08:00
|
|
|
* VERSION: 1.10
|
2016-02-04 12:42:05 +08:00
|
|
|
*
|
2017-04-17 19:45:41 +08:00
|
|
|
* DATE: 20 Mar 2017
|
2016-02-04 12:42:05 +08:00
|
|
|
*
|
|
|
|
* Console output.
|
|
|
|
*
|
|
|
|
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
|
|
|
|
* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
|
|
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE.
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
|
|
|
#include "global.h"
|
|
|
|
|
|
|
|
/*
|
2017-04-17 19:45:41 +08:00
|
|
|
* cuiPrintTextA
|
2016-02-04 12:42:05 +08:00
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Output text to the console or file.
|
|
|
|
*
|
2017-04-17 19:45:41 +08:00
|
|
|
* ANSI variant
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
VOID cuiPrintTextA(
|
|
|
|
_In_ HANDLE hOutConsole,
|
|
|
|
_In_ LPSTR lpText,
|
|
|
|
_In_ BOOL ConsoleOutputEnabled,
|
|
|
|
_In_ BOOL UseReturn
|
|
|
|
)
|
|
|
|
{
|
|
|
|
SIZE_T consoleIO;
|
|
|
|
DWORD bytesIO;
|
|
|
|
LPSTR Buffer;
|
|
|
|
|
|
|
|
if (lpText == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
consoleIO = _strlen_a(lpText);
|
|
|
|
if ((consoleIO == 0) || (consoleIO > MAX_PATH * 4))
|
|
|
|
return;
|
|
|
|
|
|
|
|
consoleIO = (5 + consoleIO);
|
|
|
|
Buffer = (LPSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, consoleIO);
|
|
|
|
if (Buffer) {
|
|
|
|
|
|
|
|
_strcpy_a(Buffer, lpText);
|
|
|
|
if (UseReturn) _strcat_a(Buffer, "\r\n");
|
|
|
|
|
|
|
|
consoleIO = _strlen_a(Buffer);
|
|
|
|
|
|
|
|
if (ConsoleOutputEnabled != FALSE) {
|
|
|
|
WriteConsoleA(hOutConsole, Buffer, (DWORD)consoleIO, &bytesIO, NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
WriteFile(hOutConsole, Buffer, (DWORD)(consoleIO * sizeof(CHAR)), &bytesIO, NULL);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, Buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cuiPrintTextW
|
|
|
|
*
|
|
|
|
* Purpose:
|
|
|
|
*
|
|
|
|
* Output text to the console or file.
|
|
|
|
*
|
|
|
|
* UNICODE variant
|
|
|
|
*
|
2016-02-04 12:42:05 +08:00
|
|
|
*/
|
2017-04-17 19:45:41 +08:00
|
|
|
VOID cuiPrintTextW(
|
|
|
|
_In_ HANDLE hOutConsole,
|
|
|
|
_In_ LPWSTR lpText,
|
|
|
|
_In_ BOOL ConsoleOutputEnabled,
|
|
|
|
_In_ BOOL UseReturn
|
|
|
|
)
|
2016-02-04 12:42:05 +08:00
|
|
|
{
|
2017-04-17 19:45:41 +08:00
|
|
|
SIZE_T consoleIO;
|
|
|
|
DWORD bytesIO;
|
|
|
|
LPWSTR Buffer;
|
2016-02-04 12:42:05 +08:00
|
|
|
|
2017-04-17 19:45:41 +08:00
|
|
|
if (lpText == NULL)
|
|
|
|
return;
|
2016-02-04 12:42:05 +08:00
|
|
|
|
2017-04-17 19:45:41 +08:00
|
|
|
consoleIO = _strlen(lpText);
|
|
|
|
if ((consoleIO == 0) || (consoleIO > MAX_PATH * 4))
|
|
|
|
return;
|
2016-02-04 12:42:05 +08:00
|
|
|
|
2017-04-17 19:45:41 +08:00
|
|
|
consoleIO = (5 + consoleIO) * sizeof(WCHAR);
|
|
|
|
Buffer = (LPWSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, consoleIO);
|
|
|
|
if (Buffer) {
|
2016-02-04 12:42:05 +08:00
|
|
|
|
2017-04-17 19:45:41 +08:00
|
|
|
_strcpy(Buffer, lpText);
|
|
|
|
if (UseReturn) _strcat(Buffer, TEXT("\r\n"));
|
2016-02-04 12:42:05 +08:00
|
|
|
|
2017-04-17 19:45:41 +08:00
|
|
|
consoleIO = _strlen(Buffer);
|
2016-02-04 12:42:05 +08:00
|
|
|
|
2017-04-17 19:45:41 +08:00
|
|
|
if (ConsoleOutputEnabled != FALSE) {
|
|
|
|
WriteConsole(hOutConsole, Buffer, (DWORD)consoleIO, &bytesIO, NULL);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
WriteFile(hOutConsole, Buffer, (DWORD)(consoleIO * sizeof(WCHAR)), &bytesIO, NULL);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, Buffer);
|
|
|
|
}
|
2016-02-04 12:42:05 +08:00
|
|
|
}
|