ReactOS  0.4.11-dev-765-g5e024bf
chcp.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <windef.h>
#include <winbase.h>
#include <wincon.h>
#include <conutils.h>
#include "resource.h"
Include dependency graph for chcp.c:

Go to the source code of this file.

Functions

int wmain (int argc, WCHAR *argv[])
 

Function Documentation

int wmain ( int  argc,
WCHAR argv[] 
)

Definition at line 31 of file chcp.c.

32 {
33  UINT uOldCodePage, uNewCodePage;
34 
35  /* Initialize the Console Standard Streams */
37 
38  /* Print help */
39  if (argc > 1 && wcscmp(argv[1], L"/?") == 0)
40  {
42  return 0;
43  }
44 
45  if (argc == 1)
46  {
47  /* Display the active code page number */
49  return 0;
50  }
51 
52  if (argc > 2)
53  {
54  /* Too many parameters */
56  return 1;
57  }
58 
59  uNewCodePage = (UINT)_wtoi(argv[1]);
60 
61  if (uNewCodePage == 0)
62  {
64  return 1;
65  }
66 
67  /*
68  * Save the original console codepage to be restored in case
69  * SetConsoleCP() or SetConsoleOutputCP() fails.
70  */
71  uOldCodePage = GetConsoleCP();
72 
73  /*
74  * Try changing the console input codepage. If it works then also change
75  * the console output codepage, and refresh our local codepage cache.
76  */
77  if (SetConsoleCP(uNewCodePage))
78  {
79  if (SetConsoleOutputCP(uNewCodePage))
80  {
81  /* Display the active code page number */
83  return 0;
84  }
85  else
86  {
87  /* Failure, restore the original console codepage */
88  SetConsoleCP(uOldCodePage);
89  }
90  }
91 
92  /* An error happened, display an error and bail out */
94  return 1;
95 }
static int argc
Definition: ServiceArgs.c:12
#define STRING_CHCP_ERROR4
Definition: resource.h:8
BOOL WINAPI SetConsoleOutputCP(IN UINT wCodepage)
Definition: console.c:644
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define STRING_CHCP_HELP
Definition: resource.h:10
static char ** argv
Definition: ServiceArgs.c:11
#define ConInitStdStreams()
Definition: stream.h:122
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleOutputCP(VOID)
Definition: console.c:2453
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleCP(VOID)
Definition: console.c:2393
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
#define StdErr
Definition: stream.h:77
#define STRING_ERROR_INVALID_PARAM_FORMAT
Definition: resource.h:5
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1087
#define STRING_CHCP_ERROR1
Definition: resource.h:7
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleCP(UINT wCodePageID)
Definition: console.c:2422
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
unsigned int UINT
Definition: ndis.h:50
#define StdOut
Definition: stream.h:76
#define UINT
Definition: msvc.h:27