我有一个VC++6.0程序编译时老是报下列错,我怀疑是类型定义上有问题,原来是好的,程序被我改过了,就报这个错,主体程序没有动它,哪位高手能否帮助分析一下?
Compiling...
PIDlg.cpp
F:\vc\PITOPHD\PIDlg.cpp(101) : error C2664: 'strcpy' : cannot convert parameter 2 from 'class CString' to 'const char *'
        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
F:\vc\PITOPHD\PIDlg.cpp(108) : error C2664: 'void __cdecl CString::Format(const unsigned short *,...)' : cannot convert parameter 1 from 'char [3]' to 'const unsigned short *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
F:\vc\PITOPHD\PIDlg.cpp(113) : error C2664: 'MessageBoxW' : cannot convert parameter 1 from 'char [27]' to 'const unsigned short *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
F:\vc\PITOPHD\PIDlg.cpp(131) : error C2664: 'void __cdecl CString::Format(const unsigned short *,...)' : cannot convert parameter 1 from 'char [5]' to 'const unsigned short *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
F:\vc\PITOPHD\PIDlg.cpp(439) : error C2664: 'int __thiscall CListCtrl::InsertColumn(int,const unsigned short *,int,int,int)' : cannot convert parameter 2 from 'char [7]' to 'const unsigned short *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Generating Code...
执行 cl.exe 时出错.PITOPHD.exe - 1 error(s), 0 warning(s)

解决方案 »

  1.   

    代码?
    CString::GetBuffer
    还有unicode的话,得用w_xxx
      

  2.   

    楼主的工程是UNICODE的改成ANSI的试试
      

  3.   

    用char 类型数组代替 CString 类型
      

  4.   

    在项目属性里改成使用Unicode试试。
      

  5.   

    应该 是改为多字节的,不应是Unicode的。
      

  6.   

    strcp已经被废止了,用memcpy
     CString tmp;
     Tchar   str[26];
      如: memcpy(tmp.GetBuffer(tmp.getlength()),str,26)   以上写的不一定对,意思是明确的.   
      

  7.   

    呃,前面加强制转换(LPSTR)(LPCSTR)这个在网上查查有解决办法的,一般都是使用强制转换。建议在定义字符串时加_T()
      

  8.   

    代码压根就不对,数据类型LZ压根就不了解,还说VC++6.0老是报错,无语.
      

  9.   

    error C2664: 'strcpy' : cannot convert parameter 2 from 'class CString' to 'const char *'strcpy的第二个参数接受的是char*类型,你传递的是CString,使用CString的GetBuffer函数.
    比如:
    CString str;
    ......
    strcpy(xxx, str.GetBuffer(0));而且不推荐使用strcpy,个人看好lstrcpy
    也要注意ANSI与UNICODE的区别.
      

  10.   

    另外,只有错误信息,没有代码片段,不好说错误具体在什么地方.
    编译器告诉你的错误不一定准确,因为MFC会重载函数,你想用的函数不一定是你想用的,一个参数不同就可能导致调用的函数不同.
      

  11.   

    简言之,是你所用的程序是UNICODE编码而你在改的时候用了char型的变量。处理方法为:
    把你程序中定义的char换为TCHAR "..."换为_T("...")
    或者把项目Settings... 里面C++编译选项里面的UNICODE, _UNICODE换为MBCS即可。