问题描述
CString str =(char *)lParam; //VC2005 unicode中存在编译错误
如果不使用unicode,则没有编译错误.
使用Unicode,如何将(char *)lParam"转换为"CString"
这是我的原始代码...
void CChatbotDlg :: OnBnClickedButton1()
{
//TODO:
CString strSend;
GetDlgItemText(IDC_EDIT2,strSend);
if(strSend.GetLength()> 0)
{
char tempBuf [256];
sprintf(tempBuf,"U:%s",strSend);
:: PostMessage(this-> m_hWnd,WM_RECVDATA,0,(LPARAM)tempBuf);
}
SetDlgItemText(IDC_EDIT2,_T(")));
}
LRESULT CChatbotDlg :: OnRecvData(WPARAM wParam,LPARAM lParam)
{
CString str =(字符*)lParam; //编译错误!
CString strTemp;
GetDlgItemText(IDC_EDIT1,strTemp);
strTemp + ="\ r \ n";
strTemp + = str;
SetDlgItemText(IDC_EDIT1,strTemp);
返回0;
}
有什么错误?也许您需要使用TCHAR?我相信CString类可以将自身转换为unicode构建的unicode类,如果确实是unicode构建中的char *,则可以使用_bstr_t进行转换(因此,TCHAR显然会破坏它). /blockquote>
CString str=(char *)lParam; //there is a compile error in VC2005 unicode
if not using unicode , there is no compile error.
Using unicode, how to convert "(char *)lParam" to "CString"
here is my original code...
void CChatbotDlg::OnBnClickedButton1()
{
// TODO:
CString strSend;
GetDlgItemText(IDC_EDIT2,strSend);
if(strSend.GetLength()>0)
{
char tempBuf[256];
sprintf(tempBuf,"U:%s",strSend);
::PostMessage(this->m_hWnd,WM_RECVDATA,0,(LPARAM)tempBuf);
}
SetDlgItemText(IDC_EDIT2,_T(""));
}
LRESULT CChatbotDlg::OnRecvData(WPARAM wParam, LPARAM lParam)
{
CString str=(char *)lParam; // compile error!
CString strTemp;
GetDlgItemText(IDC_EDIT1,strTemp);
strTemp+="\r\n";
strTemp+=str;
SetDlgItemText(IDC_EDIT1,strTemp);
return 0;
}
What is the error ? Perhaps you need to use TCHAR ? I believe that the CString class turns itself into a unicode class for unicode builds, you could use _bstr_t to do a conversion for you, if this is indeed a char * in a unicode build ( so, then TCHAR would break it obviously ).
这篇关于VC2005 lparam转换为CString编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!