| 1 |
#include <windows.h> |
| 2 |
#include <assert.h> |
| 3 |
#include <stdlib.h> |
| 4 |
#include <stdio.h> |
| 5 |
|
| 6 |
#include <vector> |
| 7 |
#include <string> |
| 8 |
|
| 9 |
int main(int argc, char *argv[]) { |
| 10 |
system("cls"); |
| 11 |
|
| 12 |
if (argc == 1) { |
| 13 |
printf("Usage: %s hhhh\n", argv[0]); |
| 14 |
return 0; |
| 15 |
} |
| 16 |
|
| 17 |
std::wstring dataToWrite; |
| 18 |
for (int i = 1; i < argc; ++i) { |
| 19 |
wchar_t ch = strtol(argv[i], NULL, 16); |
| 20 |
dataToWrite.push_back(ch); |
| 21 |
} |
| 22 |
|
| 23 |
DWORD actual = 0; |
| 24 |
BOOL ret = WriteConsoleW( |
| 25 |
GetStdHandle(STD_OUTPUT_HANDLE), |
| 26 |
dataToWrite.data(), dataToWrite.size(), &actual, NULL); |
| 27 |
assert(ret && actual == dataToWrite.size()); |
| 28 |
|
| 29 |
// Read it back. |
| 30 |
std::vector<CHAR_INFO> readBuffer(dataToWrite.size() * 2); |
| 31 |
COORD bufSize = {static_cast<short>(readBuffer.size()), 1}; |
| 32 |
COORD bufCoord = {0, 0}; |
| 33 |
SMALL_RECT topLeft = {0, 0, static_cast<short>(readBuffer.size() - 1), 0}; |
| 34 |
ret = ReadConsoleOutputW( |
| 35 |
GetStdHandle(STD_OUTPUT_HANDLE), readBuffer.data(), |
| 36 |
bufSize, bufCoord, &topLeft); |
| 37 |
assert(ret); |
| 38 |
|
| 39 |
printf("\n"); |
| 40 |
for (int i = 0; i < readBuffer.size(); ++i) { |
| 41 |
printf("CHAR: %04x %04x\n", |
| 42 |
readBuffer[i].Char.UnicodeChar, |
| 43 |
readBuffer[i].Attributes); |
| 44 |
} |
| 45 |
return 0; |
| 46 |
} |