我有一个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)
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)
CString::GetBuffer
还有unicode的话,得用w_xxx
CString tmp;
Tchar str[26];
如: memcpy(tmp.GetBuffer(tmp.getlength()),str,26) 以上写的不一定对,意思是明确的.
比如:
CString str;
......
strcpy(xxx, str.GetBuffer(0));而且不推荐使用strcpy,个人看好lstrcpy
也要注意ANSI与UNICODE的区别.
编译器告诉你的错误不一定准确,因为MFC会重载函数,你想用的函数不一定是你想用的,一个参数不同就可能导致调用的函数不同.
把你程序中定义的char换为TCHAR "..."换为_T("...")
或者把项目Settings... 里面C++编译选项里面的UNICODE, _UNICODE换为MBCS即可。