没有定义UNICODE,所以它里面的字符串就是简单用" "就行了,创建工程的时候包含了UNICODE定义,就必须对TCHAR和char进行转换。
首先是把TCHAR转为char
[cpp] view plaincopyprint?
//将TCHAR转为char
//*tchar是TCHAR类型指针,*_char是char类型指针
TcharToChar (const TCHAR * tchar, char * _char)
{
int iLength ;
//获取字节长度
iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);
//将tchar值赋给_char
WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);
}
//将TCHAR转为char //*tchar是TCHAR类型指针,*_char是char类型指针 TcharToChar (const TCHAR * tchar, char * _char) { int iLength ; //获取字节长度 iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL); //将tchar值赋给_char WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL); }
然后是把char转为TCHAR
[cpp] view plaincopyprint?
//同上
CharToTchar (const char * _char, TCHAR * tchar)
{
int iLength ;
iLength = MultiByteToWideChar (CP_ACP, 0, _char, strlen (_char) + 1, NULL, 0) ;
MultiByteToWideChar (CP_ACP, 0, _char, strlen (_char) + 1, tchar, iLength) ;
}
首先是把TCHAR转为char
[cpp] view plaincopyprint?
//将TCHAR转为char
//*tchar是TCHAR类型指针,*_char是char类型指针
TcharToChar (const TCHAR * tchar, char * _char)
{
int iLength ;
//获取字节长度
iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL);
//将tchar值赋给_char
WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL);
}
//将TCHAR转为char //*tchar是TCHAR类型指针,*_char是char类型指针 TcharToChar (const TCHAR * tchar, char * _char) { int iLength ; //获取字节长度 iLength = WideCharToMultiByte(CP_ACP, 0, tchar, -1, NULL, 0, NULL, NULL); //将tchar值赋给_char WideCharToMultiByte(CP_ACP, 0, tchar, -1, _char, iLength, NULL, NULL); }
然后是把char转为TCHAR
[cpp] view plaincopyprint?
//同上
CharToTchar (const char * _char, TCHAR * tchar)
{
int iLength ;
iLength = MultiByteToWideChar (CP_ACP, 0, _char, strlen (_char) + 1, NULL, 0) ;
MultiByteToWideChar (CP_ACP, 0, _char, strlen (_char) + 1, tchar, iLength) ;
}