00001
#include <windows.h>
00002
#include <stdio.h>
00003
#include <stdlib.h>
00004
#include <io.h>
00005
#include <fcntl.h>
00006
00007 #define STDIN 0
00008 #define STDOUT 1
00009 #define STDERR 2
00010
00011 #define CRTTONT(fh) (HANDLE)_get_osfhandle(fh)
00012
00013 PrintPair(
00014 LPWSTR pwch,
00015 UCHAR *pch,
00016 DWORD cch)
00017 {
00018
DWORD cchWritten;
00019
00020
SetConsoleMode(
CRTTONT(
STDOUT), ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
00021
00022 printf(
"%04x-%04x: ", pwch[0], pwch[cch-1]);
00023
WriteConsoleW(
CRTTONT(
STDOUT), pwch, cch, &cchWritten,
NULL);
00024 printf(
" ");
00025 printf(
"%02x-%02x: ", pch[0], pch[cch-1]);
00026
WriteConsoleA(
CRTTONT(
STDOUT), pch, cch, &cchWritten,
NULL);
00027
00028 printf(
"\n");
00029
SetConsoleMode(
CRTTONT(
STDOUT), ENABLE_WRAP_AT_EOL_OUTPUT);
00030
00031 printf(
"%04x-%04x: ", pwch[0], pwch[cch-1]);
00032
WriteConsoleW(
CRTTONT(
STDOUT), pwch, cch, &cchWritten,
NULL);
00033 printf(
" ");
00034 printf(
"%02x-%02x: ", pch[0], pch[cch-1]);
00035
WriteConsoleA(
CRTTONT(
STDOUT), pch, cch, &cchWritten,
NULL);
00036
00037
SetConsoleMode(
CRTTONT(
STDOUT), ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT);
00038 printf(
"\n\n");
00039 }
00040
00041 int _cdecl
main(
int argc,
char *argv[]) {
00042 WCHAR awch[100];
00043
CHAR ach[100];
00044
CHAR ch;
00045
DWORD i, j;
00046
00047 printf(
"The first and second line of each pair should be identical:\n");
00048 printf(
"Unicode ANSI\n");
00049
for (i = 0xA0; i < 0xFF; i += 0x10) {
00050
for (j = 0; j < 16; j++) {
00051 awch[j] = (WCHAR)(i + j);
00052 ach[j] = (
CHAR)(i+j);
00053 }
00054
PrintPair(awch, ach, 16);
00055 }
00056
00057 printf(
"Now test line wrapping:\n");
00058 ch = 0x80;
00059
for (j = 0; j < 100; j++) {
00060 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &awch[j], 1);
00061 ach[j] = ch;
00062 ch++;
00063 }
00064
PrintPair(awch, ach, 100);
00065
00066 }