大家请看下面一段代码:
CString str;
BROWSEINFO bi;
char path[MAX_PATH];
ZeroMemory(&bi,sizeof(BROWSEINFO));
bi.hwndOwner = GetSafeHwnd();
bi.pszDisplayName = path;
bi.lpszTitle = _T("请选择GDC2000系统路径...");
bi.ulFlags = BIF_EDITBOX;
LPITEMIDLIST idl = SHBrowseForFolder(&bi);
if(idl == NULL)
return;
SHGetPathFromIDList(idl,str.GetBuffer(MAX_PATH));
str.ReleaseBuffer();
m_dir = str;
CString a = str.GetAt(str.GetLength()-1);
if(a != "\\")
m_dir += "\\";
UpdateData(FALSE);
在VC6.0中编译没有一点问题,但在VS2005中不能通过,具体错误为:
错误 1 error C2440: '=' : cannot convert from 'char [260]' to 'LPWSTR'(是指“bi.pszDisplayName = path”这一句)
错误 2 error C2440: 'initializing' : cannot convert from 'wchar_t' to 'ATL::CStringT<BaseType,StringTraits>'(是指“CString a = str.GetAt(str.GetLength()-1)”这一句)
请问如何转换char类型为LPWSTR类型,以及char *类型为LPCWSTR类型?
这二条错误怎么解决?
CString str;
BROWSEINFO bi;
char path[MAX_PATH];
ZeroMemory(&bi,sizeof(BROWSEINFO));
bi.hwndOwner = GetSafeHwnd();
bi.pszDisplayName = path;
bi.lpszTitle = _T("请选择GDC2000系统路径...");
bi.ulFlags = BIF_EDITBOX;
LPITEMIDLIST idl = SHBrowseForFolder(&bi);
if(idl == NULL)
return;
SHGetPathFromIDList(idl,str.GetBuffer(MAX_PATH));
str.ReleaseBuffer();
m_dir = str;
CString a = str.GetAt(str.GetLength()-1);
if(a != "\\")
m_dir += "\\";
UpdateData(FALSE);
在VC6.0中编译没有一点问题,但在VS2005中不能通过,具体错误为:
错误 1 error C2440: '=' : cannot convert from 'char [260]' to 'LPWSTR'(是指“bi.pszDisplayName = path”这一句)
错误 2 error C2440: 'initializing' : cannot convert from 'wchar_t' to 'ATL::CStringT<BaseType,StringTraits>'(是指“CString a = str.GetAt(str.GetLength()-1)”这一句)
请问如何转换char类型为LPWSTR类型,以及char *类型为LPCWSTR类型?
这二条错误怎么解决?
解决方案 »
- 十六进制求算法过程
- CBitmapButton为何出错
- 报这missing function header (old-style formal list?) 错误
- winxp 与dll问题
- 献上所有分.请教一个元旦出游的问题.
- 单文档程序对话框里面中的控件按回车键便退出了对话框,而不是点"叉"退出,请问怎么解决?
- 初学者的菜问题:怎样才能把LPCTSTR转为LPBYTE啊。100分
- 如何在程序中使用Window2000的信史服务程序
- 我从朋友处找到好书现想制作成PDF格式的电子书,有扫描仪,请问制作过程?扫描时要注意事项?需有哪些软?
- vc数据库编程,看什么书最好?
- 用Image类创建一个对象时出错,高手帮看一下!
- 问个简单问题,关于控件的
Modify project setting -> not use Unicode
Method 2:
TCHAR path[MAX_PATH];
TCHAR a = str.GetAt(str.GetLength()-1);
if(a != _T("\\"))
m_dir += _T("\\");
错误 1 error C2446: '!=' : no conversion from 'const char *' to 'int'
错误 2 error C2040: '!=' : 'int' differs in levels of indirection from 'const char [2]'
TCHAR path[MAX_PATH];
bi.lpszTitle=_T("请选择查找目录:");
v_SourceDIR=CString(path); 谢谢pkrobbie(pkrobbie)!
编译问题是解决了,但对于char类型转换为LPWSTR类型,以及char *类型转换为LPCWSTR类型还不是明白,请各位大哥指点一下,谢谢!
CString theString( "This is a test" );
LPTSTR lpsz = new TCHAR[theString.GetLength()+1];
_tcscpy(lpsz, theString);