CString 强制转化为const char*,作为形参带入函数内出错。用CW2A解决
来源:互联网 发布:python 将list拆分 编辑:程序博客网 时间:2024/06/05 15:39
CString csPath = _T("C:/Program Files/Adobe");
将csPath 带入函数:
bool GetFileVersion(const char* lpszFileName, bool bVersion); 作为其第一个参数。
CString 转为const char* ,加(char *)(LPCTSTR),即:
GetFileVersion((char *)(LPCTSTR)csPath , true);
但在GetFileVersion函数中调试发现,第一个参数只剩下首地址的一个字符。
正确做法如下:(方法1)
CString csPath = _T("C:/Program Files/Adobe");
CW2A temp1(csPath );
const char *buffer1 = temp1;
AppUpdater::GetFileVersion(buffer1, true);
(CW2A:将宽字符集(Unicode)转化为多字符集(ASCII);
CA2W:反之)
MultiByteToWideChar:映射一个字符串到一个宽字符(unicode)的字符串。由该函数映射的字符串没必要是多字节字符组。
WideCharToMultiByte:该函数映射一个unicode字符串到一个多字节字符串。
(方法2)
CString str(_T(ansdnandn测试!));
int len = WideCharToMultiByte( CP_ACP , 0 , str , str.GetLength() , NULL , 0 , NULL , NULL );
char* pAscii =new char[len+1];
len = WideCharToMultiByte( CP_ACP , 0 , str , str.GetLength() , pAscii , len +1 , NULL ,NULL );
pAscii[len] = 0;
const char* cTemp = (const char*)pAscii;
char a = cTemp[0];
char b = cTemp[1];
char c = cTemp[2];
。。。。。。。
- CString 强制转化为const char*,作为形参带入函数内出错。用CW2A解决
- CString 转化为 char*
- CString 转化为 const char* 以及WideCharToMultiByte用法实例
- Cstring转换 const char* 出错
- 将CString转化为char*
- CString 如何转化为 char* ?
- MFC CString转化为char*
- CString转换为const char*
- CString 转换为const char *
- CString转换为const char*
- CString”转换为“const char *
- CString转换为const char*
- CString转换为const char * 或者CString转换为char*
- 将const char* 转化为char*
- VC中char* 转化为CString类型
- Unicode类型的CString转化为char*
- 终于把CString转化为char*了
- 从“CString”转换为“const char *”
- 二维数组的地址
- centos配置
- Cassandra V0.7.4 新手入门点滴
- mmap共享内存
- eclipse下 alt+/快捷键方式失效的解决
- CString 强制转化为const char*,作为形参带入函数内出错。用CW2A解决
- sigsuspend函数
- 关于锐捷认证与傻瓜路由器
- URL中特殊字符的含义
- C-枚举
- How to Change ASM Home on a Node in RAC [ID 558508.1]
- url中的特殊字符问题
- bat操作数据库mysql
- 需要更加的沉稳