VS2010项目中有ANSI字符集,在项目属性中选择"多字节字符集"即可转换代码可用如下:
#include <AtlConv.h>USES_CONVERSION;
char *dst = W2A(str);

解决方案 »

  1.   

    一个好习惯:
    所有的char用 TCHAR 替换, strcpy 等字符操作函数都用 _tcscpy或者
    工程属性--字符编码 multi-btye
      

  2.   

    char 都用TCHAR
    CString str;转TCHAR a[200];
    sprintf_s(a,_T("%s"),str);
    strcpy_s(a,(char *)str);这样改试试!
      

  3.   

    这是3楼的结果:
    error C2664: “sprintf_s”: 不能将参数 1 从“TCHAR [200]”转换为“char *”
    1>          与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换1> error C2660: “strcpy_s”: 函数不接受 2 个参数
      

  4.   

    这是2楼的结果:
    使用多字节后出现了这么多的问题!(之前只有一处错误)>BtnST.cpp(1923): error C2664: “ShellExecuteA”: 不能将参数 3 从“LPCWSTR”转换为“LPCSTR”
    1>          与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
    1>BtnST.cpp(1929): error C2664: “ShellExecuteA”: 不能将参数 3 从“LPCWSTR”转换为“LPCSTR”
    1>          与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
    1>BtnST.cpp(1934): error C2664: “ShellExecuteA”: 不能将参数 3 从“LPCWSTR”转换为“LPCSTR”
    1>          与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换
    1>  Pass.cpp
    1>Pass.cpp(51): error C2039: “GetWindowTextW”: 不是“CWnd”的成员
    1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\afxwin.h(2273) : 参见“CWnd”的声明
    1>Pass.cpp(57): error C2039: “SetWindowTextW”: 不是“CWnd”的成员
    1>          C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\atlmfc\include\afxwin.h(2273) : 参见“CWnd”的声明
    1>  软件管理程序.cpp
    1>  软件管理程序Dlg.cpp
    1>软件管理程序Dlg.cpp(134): error C2440: “类型转换”: 无法从“CString”转换为“char *”
    1>          没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
    1>软件管理程序Dlg.cpp(134): error C2660: “strcpy_s”: 函数不接受 2 个参数
    1>软件管理程序Dlg.cpp(162): error C2440: “类型转换”: 无法从“CString”转换为“LPCWSTR”
    1>          没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
    1>软件管理程序Dlg.cpp(168): error C2440: “类型转换”: 无法从“CString”转换为“LPCWSTR”
    1>          没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
      

  5.   

    点击菜单 “项目”->“工程名 属性”->“属性页”->“配置属性”->“常规”->“字符集”->“使用多字节字符集”
      

  6.   

    谢谢fandh!!!!!!!!!
    谢谢fandh!!!!!!!!!
    谢谢fandh!!!!!!!!!
    非常感谢,我以后会养成TCHAR的好习惯的!!!谢谢指导,散分了,
      

  7.   


    把那个unicode 字符集改成多字节字符集之后,也没有乱码了!!!