// 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:宽字符和C*/
//宽字符并不一定是UNICODE,UNICODE只是宽字符编码的一种体现
//c语言中宽字符是基于 wchar_t数据类型
//L"hello",L'A':表示应被解释为宽字符
//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:宽字符和Windows*/
//windows.h-->windef.h(winnt.h)
/*#include<winnt.h>
typedef char CHAR
typedef wchar_t TCHAR
*/
/*part3:Windows中字符串函数*/
/*lstrlen
lstrcpy
lstrcpyn
lstrcat
lstrcmp
lstrcmpi*/
//sprintf/swprintf-->_stprintf
//
//vsprintf:执行可变参数 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;
}