VC++ 类型转换问题。。(编译器VS2008) U码转换解析
wchar_t* ANSIToUnicode( const char* str ) // 1. ANSI to Unicode
{
int len = 0;
len = strlen(str);
int unicodeLen = ::MultiByteToWideChar( CP_ACP,
0,
str,
-1,
NULL,
0 );
wchar_t * pUnicode;
pUnicode = new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
::MultiByteToWideChar( CP_ACP,
0,
str,
-1,
(LPWSTR)pUnicode,
unicodeLen );
//rt = ( wchar_t* )pUnicode;
//delete pUnicode;
return pUnicode;
}
char* UnicodeToANSI( const wchar_t* str ) // 2. Unicode to ANSI
{
char* pElementText;
int iTextLen;
// wide char to multi char
iTextLen = WideCharToMultiByte( CP_ACP,
0,
str,
-1,
NULL,
0,
NULL,
NULL );
pElementText = new char[iTextLen + 1];
memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );
::WideCharToMultiByte( CP_ACP,
0,
str,
-1,
pElementText,
iTextLen,
NULL,
NULL );
//string strText;
//strText = pElementText;
//delete[] pElementText;
return pElementText;
}
请问这段代码 是类型转换。。
看不太懂 我如何用呢 。。
请解析 谢谢了・・・・・・・・・
我的代码是。。这个 需要类型转换 如果用他的格式转换呢。
void CTestDlg::OnBnClickedCadd()
{
// TODO: 在此增加控件通知措置惩罚程序代码
int num1, num2, num3;
char ch1[10], ch2[10], ch3[10];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,10);
GetDlgItem(IDC_EDIT1)->GetWindowText(ch2,10);
num1 = atoi(ch1);
num2 = atoi(ch2);
num3 = num1 + num2;
itoa(num3,ch3,10);
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
}
error C2664: “int CWnd::GetWindowTextW(LPTSTR,int) const”: 不能将参数 1 从“char [10]”转换为“LPTSTR”
1> 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
---华软网友回答---
用TCHAR[];
atoi换成_ttoi();
---华软网友回复---
换成TCHAR ch1[10], ch2[10], ch3[10];
---华软网友回复---
最简单的做法是你直接给IDC_EDIT1联系关系一个CString类型的变量m_edit
---华软网友回复---
这代码写的不太习气,俺习气都是在外部来new,虽然这样也行。
华软声明:本内容来自网络,如有侵犯您版权请来信指出,本站立即删除。