#include <cstdio> // for printf, sprintf.
#include <cstring> // for strchr.
#include <tchar.h> // for _T.
#include <Windows.h> // for MessageBox.
/*
実行方法
chcp 65001
dir /b | test.exe
*/
int main()
{
char buffer[1024] = {};
if ( std::fgets(buffer, 1024, stdin) != nullptr )
{
if ( auto *p = std::strchr(buffer, '\n') )
*p = '\0';
char msg2[100];
std::sprintf(msg2, "%02X %02X %02X %02X : %s",
buffer[0] & 0xFF, buffer[1] & 0xFF, buffer[2] & 0xFF, buffer[3] & 0xFF, buffer);
::MessageBoxA(nullptr, msg2, "UNKO", MB_OK); // → E2 86 9D... (OK)
wchar_t msg3[100];
if ( ::MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, buffer, -1, msg3, sizeof msg3 / sizeof *msg3) == 0 )
{
_tprintf(_T("text encoding conversion failed\n"));
return ~0;
}
std::sprintf(msg2, " > %04X %04X %04X %04X",
msg3[0] & 0xFFFF, msg3[1] & 0xFFFF, msg3[2] & 0xFFFF, msg3[3] & 0xFFFF);
::MessageBoxA(nullptr, msg2, "UNKO", MB_OK); // → 219D... (OK)
::MessageBoxW(nullptr, msg3, L"UNKO", MB_OK);
}
}
I2luY2x1ZGUgPGNzdGRpbz4gICAgLy8gZm9yIHByaW50Ziwgc3ByaW50Zi4KI2luY2x1ZGUgPGNzdHJpbmc+CS8vIGZvciBzdHJjaHIuCiNpbmNsdWRlIDx0Y2hhci5oPgkvLyBmb3IgX1QuCiNpbmNsdWRlIDxXaW5kb3dzLmg+CS8vIGZvciBNZXNzYWdlQm94LgoKLyoK5a6f6KGM5pa55rOVCgpjaGNwIDY1MDAxCmRpciAvYiB8IHRlc3QuZXhlCgoqLwoKaW50IG1haW4oKQp7CgljaGFyIGJ1ZmZlclsxMDI0XSA9IHt9OwoKCWlmICggc3RkOjpmZ2V0cyhidWZmZXIsIDEwMjQsIHN0ZGluKSAhPSBudWxscHRyICkKCXsKCQlpZiAoIGF1dG8gKnAgPSBzdGQ6OnN0cmNocihidWZmZXIsIC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