VC2005 lparam转换为CString编译错误 [英] VC2005 lparam converted to CString compile error

查看:139
本文介绍了VC2005 lparam转换为CString编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;
}

解决方案

我终于找到了...
正确的代码是...

void CChatbotDlg :: OnBnClickedButton1()
{
//TODO:
CString strSend;
GetDlgItemText(IDC_EDIT2,strSend);
if(strSend.GetLength()> 0)
{
wchar_t * tempBuf =新的wchar_t [256];
swprintf_s(tempBuf,256,_T("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 =(wchar_t *)lParam;
CString strTemp;
GetDlgItemText(IDC_EDIT1,strTemp);
strTemp + ="\ r \ n";
strTemp + = str;
SetDlgItemText(IDC_EDIT1,strTemp);
返回0;
}


zop123写道:

=(char *)lParam; //VC2005 unicode中存在编译错误



有什么错误?也许您需要使用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;
}

解决方案

I finally find it...
The correct code is...

void CChatbotDlg::OnBnClickedButton1()
{
// TODO:
CString strSend;
GetDlgItemText(IDC_EDIT2,strSend);
if(strSend.GetLength()>0)
{
wchar_t *tempBuf=new wchar_t[256];
swprintf_s(tempBuf,256,_T("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=(wchar_t* )lParam;
CString strTemp;
GetDlgItemText(IDC_EDIT1,strTemp);
strTemp+="\r\n";
strTemp+=str;
SetDlgItemText(IDC_EDIT1,strTemp);
return 0;
}


zop123 wrote:

=(char *)lParam; //there is a compile error in VC2005 unicode



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编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆