// MyTransferTCHAR. cpp: Defines the entry point for the console application.
//
# Include "stdafx. h"
# Include <stdlib. h>
# Include <Windows. h>
# Include <tchar. h> // include <string. h> vs <wchar. h>
/* Part1: width and C */
// The width character is not necessarily UNICODE. UNICODE is only a reflection of the width character encoding.
// In C language, the wide character is based on the wchar_t Data Type
// L "hello", L 'A': indicates that it should be interpreted as A wide character.
// Wchar_t a [] = L "kuanzihello ";
/*
<String. h>:
Size_t _ cdecl strlen (_ In_z _ const char * _ Str)
<Wchar. h>:
Size_t _ cdecl wcslen (_ In_z _ const wchar_t * _ Str)
<Tchar. h>
# Define _ tcslen wcslen/strlen
Typedef wchar_t TCHAR
Typedef char TCHAR
*/
/* Part2: width and Windows */
// Windows. h --> windef. h (winnt. h)
/* # Include <winnt. h>
Typedef char CHAR
Typedef wchar_t TCHAR
*/
/* Part3: String function in Windows */
/* Lstrlen
Lstrcpy
Lstrcpyn
Lstrcat
Lstrcmp
Lstrcmpi */
// Sprintf/swprintf --> _ stprintf
//
// Vsprintf: Execute variable parameters va_list, va_start and va_end (# include <stdarg. h>)
Void test_strlen ()
{
Wchar_t * pw = L "hello! ";
Int iLength = 0;
ILength = wcslen (pw );
}
Void TCHAR2CHAR ()
{
TCHAR src [] = TEXT ("hello! ");
Char dest [256] = {0 };
Int length = 0; // 7
Length = WideCharToMultiByte (CP_ACP, 0, src,-1, NULL, 0, NULL, NULL );
WideCharToMultiByte (CP_ACP, 0, src,-1, dest, length, NULL, NULL );
Printf ("% s \ n", dest );
}
Void CHAR2TCHAR ()
{
CHAR src [] = "hello! ";
TCHAR dest [256] = {0 };
Int length = 0; // 7
Length = MultiByteToWideChar (CP_ACP, 0, src,-1, NULL, 0 );
MultiByteToWideChar (CP_ACP, 0, src,-1, dest, length );
Printf ("% s \ n", dest );
}
Int _ tmain (int argc, _ TCHAR * argv [])
{
CHAR2TCHAR ();
Return 0;
}