VS2010 常见的错误

错误:

fatal error C1010: unexpected endof file while looking for precompiled header. Did you forget toadd '#include"StdAfx.h"' to your source?

 

#include"StdAfx.h" 你把这个放在头文件里面就行了

2 vc++编程出现错误error C2447: missing function header (old-styleformal list?)

原因:函数后面多了分号;

SUNSHINE_APISSN_RETURN SsnWriteProfileString(__in INT nPlugInId, __in_opt LPTSTRlpszGroupName, __in LPTSTR lpszKey, __in LPTSTR lpszValue)

 

3 errorC2491: 'SsnWriteProfileString' : definition of dllimport function not allowed

错误C2491:“SsnWriteProfileString’:dllimport函数的定义不允许的

 

SUNSHINE_API SSN_RETURNSsnWriteProfileString(__in INT nPlugInId, __in_opt LPTSTR lpszGroupName, __inLPTSTR lpszKey, __in LPTSTR lpszValue)

 

查看SUNSHINE_API在 .h文件中的定义

 

#ifdefSSNAPI_EXPORTS

#define SUNSHINE_API __declspec(dllexport)

#else

#define SUNSHINE_API __declspec(dllimport)

#endif

 

#ifdef SSNAPI_EXPORTS添加到#include<stdafx.h>的下面;形如:

 

#include<stdafx.h>

#defineSSNAPI_EXPORTS

则解决;

4 error C2065: “CString”:未声明的标识符

在非mfc下使用CString 会导致上面错误:

解决办法:

(1)如果你使用VC.net那么:使用MFC:包含cstringt.h;不使用MFC:包含atlstr.h

(2)或者 #include <afx.h>

5 error C2065: 'DEBUG_NEW' : undeclared identifier?

删除 .cpp 文件中的

#ifdef _DEBUG

#undef THIS_FILE

static char THIS_FILE[]=__FILE__;

#define new DEBUG_NEW

#endif

6 问题:

error C2440: 'initializing' : cannot convert from 'constchar [34]' to 'TCHAR [128]'

错误C2440:“初始化”:不能把'字符常量[34]' ' TCHAR[128]'

原因:编译选项有没有开了UNICODE;

做法:

vs2010下设置unicode编译选项,去掉unicode模式,具体设置方法为:

项目-》属性-》配置属性-》字符集-》未设置

project->Properties->ConfigurationProperties->General->Character Set->Not Set

http://blog.csdn.net/hrh2010/article/details/6681271

7问题:

C1083:Cannot open include file: 'stdafx.h': No such file or directory

C1083:无法打开包括文件:stdafx.h:没有这样的文件或目录

解决:stdafx.h文件和工程的.h文件放在一个位置;

8 error C2065: “cout”: 未声明的标识符

解决方法:加上

#include <iostream>

using namespace std;

9 错误:

error C3872: '0x3000': thischaracter is not allowed in an identifier

错误C3872'0 X3000“:此字符不允许在标识符

0x3000是汉语的空格,也就是全角空格,相当于一个汉字,但你又看不见它。

你知道的,像逗号,有半角(,)和全角(,)之分的,其实空格也有。

0x3000是全角的空格,0x20是半角的空格。

你最好把这个语句的后面空白部分,都删除掉,免得有不可见的全角空格。

10 加上 _T

error C2664: 'intswprintf_s(wchar_t *,size_t,const wchar_t *,...)' : cannot convert parameter 3from 'const char [24]' to 'const wchar_t *'

错误C2664:' int swprintf年代(wchar t *,大小t,t * wchar const,…)“:不能转换参数3“const char[24]”“const wchar t *’

_stprintf_s(filename,MAX_PATH, _T("C:\\Program\\rwini_%d.ini"),nPlugInId);

_T("C:\\Program\\rwini_%d.ini") 相当于 LPTSTR

11无法打开预编译头文件的解决方法

编辑程序,按Ctrl+F7,出现下列错误:

fatal error C1083: 无法打开预编译头文件:“Debug/UGFace.pch”: No such file or directory

解决方法:修改:项目->属性->C/C++->预编译头->不使用预编译头即可。

12

1>inifile.obj :error LNK2019: unresolved external symbol "private: __thiscallCsaveFileNameA::CsaveFileNameA(class CFileNameA *,classstd::basic_string<char,struct std::char_traits<char>,classstd::allocator<char>> const &)"(??0CsaveFileNameA@@AAE@PAVCFileNameA@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)referenced in function "public: class CsaveFileNameA * __thiscallCFileNameA::AddFileName(class std::basic_string<char,structstd::char_traits<char>,class std::allocator<char>>)"(?AddFileName@CFileNameA@@QAEPAVCsaveFileNameA@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)

错误是CsaveFileNameA没有实现,即没有写CsaveFileNameA构造函数和析构函数

13

1>e:\gc\src\core\inifile.h(344):error C2143: syntax error : missing ';' before '*'

错误原因

CIniFileW* PIniFile;应用的类在该类的下面,未定义;

classCFileNameW

{

public:

staticconstwchar_t*const LF;

public:

CFileNameW();

~CFileNameW();

 

classCsaveFileNameW

{

friendclassCFileNameW;

#ifdef _WIN32

// Added forversions earlier than VS2008

#ifdefined(_MSC_VER) && (_MSC_VER <= 1400)

friendstructci_less_w;

#endif

#endif

private:

CsaveFileNameW( CFileNameW* pIniFile , const std::wstring& sFileName );

CsaveFileNameW( constCsaveFileNameW& );// No Copy

CsaveFileNameW&operator=(constCsaveFileNameW&);// No Copy

~CsaveFileNameW();

private:

CFileNameW* m_pIniFile;

std::wstring m_sFileName;

CIniFileW* PIniFile;

};

structci_less_w

{

booloperator()(const CsaveFileNameW* s1,const CsaveFileNameW* s2)const

{

#ifndef _WIN32

returnwcscasecmp(s1->m_sFileName.c_str(), s2->m_sFileName.c_str()) < 0;

#else

return_wcsicmp(s1->m_sFileName.c_str(), s2->m_sFileName.c_str()) < 0;

#endif

}

};

typedefstd::set<CsaveFileNameW*,ci_less_w> FileIndexW;

 

#ifdef _WIN32

 

#ifdefined(_MSC_VER) && (_MSC_VER >= 1200)&& (_MSC_VER < 1300)

friendclassCsaveFileNameW;

#endif

#endif

 

public:

CsaveFileNameW* GetFileName( std::wstringsFileName );

//CsaveFileNameW*GetFileName( std::wstring sFileName ) const;

FileIndexW::const_iterator _find_file( const std::wstring& sFileName ) const;

FileIndexW::iterator _find_file( conststd::wstring& sFileName );

voidRemoveAllFileNames( );

private:

FileIndexW m_filenames;

 

};

classCIniFileW

{

public:

staticconstwchar_t* const LF;

public:

CIniFileW();

~CIniFileW();

 

// Usedto save the data back to the file or your choice

bool Save( conststd::wstring& fileName );

修改在前面加上 class CIniFileW

即为:

classCIniFileW;

classCFileNameW

{

public:

staticconstwchar_t*const LF;

public:

CFileNameW();

~CFileNameW();

 

classCsaveFileNameW

{

friendclassCFileNameW;

#ifdef _WIN32

// Added forversions earlier than VS2008

#ifdefined(_MSC_VER) && (_MSC_VER <= 1400)

friendstructci_less_w;

#endif

#endif

private:

CsaveFileNameW( CFileNameW* pIniFile , const std::wstring& sFileName );

CsaveFileNameW( constCsaveFileNameW& );// No Copy

CsaveFileNameW&operator=(constCsaveFileNameW&);// No Copy

~CsaveFileNameW();

private:

CFileNameW* m_pIniFile;

std::wstring m_sFileName;

public:

CIniFileW* PIniFile;

};

structci_less_w

{

booloperator()(const CsaveFileNameW* s1,const CsaveFileNameW* s2)const

{

#ifndef _WIN32

returnwcscasecmp(s1->m_sFileName.c_str(), s2->m_sFileName.c_str()) < 0;

#else

return_wcsicmp(s1->m_sFileName.c_str(), s2->m_sFileName.c_str()) < 0;

#endif

}

};

typedefstd::set<CsaveFileNameW*,ci_less_w> FileIndexW;

 

#ifdef _WIN32

 

#ifdefined(_MSC_VER) && (_MSC_VER >= 1200)&& (_MSC_VER < 1300)

friendclassCsaveFileNameW;

#endif

#endif

 

public:

CsaveFileNameW* GetFileName( std::wstringsFileName );

//CsaveFileNameW*GetFileName( std::wstring sFileName ) const;

FileIndexW::const_iterator _find_file( const std::wstring& sFileName ) const;

FileIndexW::iterator _find_file( conststd::wstring& sFileName );

voidRemoveAllFileNames( );

private:

FileIndexW m_filenames;

 

};

 

 

classCIniFileW

{

public:

staticconstwchar_t* const LF;

public:

CIniFileW();

~CIniFileW();

 

// Usedto save the data back to the file or your choice

bool Save( conststd::wstring& fileName );

 

14

error C2248:'CFileNameW::CsaveFileNameW::PIniFile' : cannot access privatemember declared in class 'CFileNameW::CsaveFileNameW'

错误C2248:“CFileNameW::::PIniFileCsaveFileNameW”:不能访问私有成员中声明的类的CFileNameW::CsaveFileNameW”

改正:把PIniFile改成公有的;

public:

CIniFileW* PIniFile;

15 error C2440: 'initializing' : cannot convert from 'wchar_t *' to 'TCHAR'

修改前:

CString Description;
CString Ddvalue =_T("Command description");
SsnGetLocaleString(SSN_PLUGIN_ID_ANY,Ddvalue, SSN_AUTO_SELECT_LOCALE,NULL,Ddvalue,Description.GetBuffer(), MAX_PATH,Ddvalue);
CString Hotkeys;
CString Hdvalue =_T("Hotkeys");
SsnGetLocaleString(SSN_PLUGIN_ID_ANY,Hdvalue, SSN_AUTO_SELECT_LOCALE,NULL,Hdvalue,Hotkeys.GetBuffer(), MAX_PATH,Hdvalue);
TCHAR rgtsz[2][MAX_PATH]={Description.GetBuffer(),Hdvalue.GetBuffer()};

修改后:

CString Description;
CString Ddvalue =_T("Command description");
SsnGetLocaleString(SSN_PLUGIN_ID_ANY,Ddvalue, SSN_AUTO_SELECT_LOCALE,NULL,Ddvalue,Description.GetBuffer(), MAX_PATH,Ddvalue);
CString Hotkeys;
CString Hdvalue =_T("Hotkeys");
SsnGetLocaleString(SSN_PLUGIN_ID_ANY,Hdvalue, SSN_AUTO_SELECT_LOCALE,NULL,Hdvalue,Hotkeys.GetBuffer(), MAX_PATH,Hdvalue);
TCHAR *rgtsz[2]={Description.GetBuffer(),Hdvalue.GetBuffer()};

给二维数组赋值;

16 warning C4627: '#include <math.h>': skipped when looking for precompiled header use

解决方法:加上头文件#include "stdafx.h"

17

CString与char的转换问题,用强制转换报了如下错误,应该如何进行转换呢?

CString strName;

TCItem.item.pszText= "ok ";//显示正常
TCItem.item.pszText=(char)strName;//报如下错误

error C2440: 'type cast ' : cannot convert from 'class CString ' to 'char '
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.

解决方法:

(char *)&strName

 

18 关于VC 的 error C3872: '0x3000':

今天在网上看到了些技术代码(关于按钮动态生成菜单的代码.好象都是一个人写的吧.几乎都没有什么变化),于是边拷贝代码边测试执行程序的结果,想不到碰到了麻烦,简单的两行代码执行时居然出了十多行的error提示:

 

Error 1 error C3872: '0x3000': this character is not allowed in an identifier

  但是看上去代码明明是对的,没错啊!于是双击提示查看是哪里出的错,结果光标停在了一行注释上,那是一起拷贝进来的一些注释文字。想想也没用,删除,再运行,结果程序顺利执行完毕了。
 
  后来发现是一些网页上的非正常格式的空格在做怪,应该是字符码的问题,它与VS中的字符不兼容,所以VS编译程序时无法识别此类字符串,于是报错。
 
注释有的时候就出现莫名其妙的问题..............

19 iostream 的用法,头文件后面不能加.h

#include<iostream>
using namespace std;

20 error LNK2005: "int __cdecl PiShowListDialog(struct _SSN_OBJECT_ID_,struct _SSN_OBJECT_ID_)" (?PiShowListDialog@@YAHU_SSN_OBJECT_ID_@@0@Z) already defined in DlgDefaultList.obj

错误代表同一个工程里,有两个PiShowListDialog函数!

21

致命错误C1010:在寻找预编译指示头文件时,文件未预期结束。

就是没有找到预编译指示信息的头文件。 问题一般发生在:通过添加文件的方式,添加了一些cpp文件到一个MFC的程序,但该cpp文件并不是MFC,而是标准的C++。 解决方案1: 右键单击项目工程中的cpp文件,在菜单Project->Settings->C/C++->Precompile Header,设置为第一项:Not using precompile headers。 解决方案2:在.cpp文件开头添加包含文件stdafx.h。 #include"stdafx.h"

22 error C2664: “LoadLibraryW”: 不能将参数 1 从“const char *”转换为“LPCWSTR”

1 静态调用DLL
Project | setting
Link选项卡Library modules处
添加“XXX.lib”
然后#include “XXX.h”
把XXX.lib(引入库文件),XXX.DLL(动态库文件)
XXX.h(头文件)
全部放到工程目录下

2 动态调用DLL
通过
LoadLibrary
GetProcAddress
FreeLibrary实现。

原因 :工程只支持UNICODE字符

解决方法:

1、工程属性->配置属性–>常规—>字符集—->使用多字节符字符集

2、也就是宽字符,所以下面这行代码,应该编译有错误
hinst=LoadLibrary(“InTheHand.Net.Personal.dll”);
也就是:
cannot convert parameter 1 from ‘char [27]‘ to ‘const unsigned short *’
楼主将代码改为:
hinst=LoadLibrary(L”InTheHand.Net.Personal.dll”);
或者
hinst=LoadLibrary(_T(“InTheHand.Net.Personal.dll”));
试试

22

warning C6387: 'argument 1' might be '0': this does not adhere to the specification for the function 'GlobalLock': Lines: 328, 329, 330, 332, 333, 334, 335

就是未对输入是否为空,进行判断!

23

AfxMessageBox(("click"));

错误 error C2665: 'AfxMessageBox' : none of the 2 overloads could convert all the argument types

解决方法:
AfxMessageBox(_T("click"));

解释:如果程序中define _UNICODE,则可用_T or _TEXT将后面的内容转为UNICODE格式字符串,否则和不用_T一样

 

或者就修改项目属性里面的字符编码

24 LNK2005: "class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,class ATL::ChTraitsCRT<wchar_t> > > NextSpeakString" (?NextSpeakString@@3V?$CStringT@_WV?$StrTraitMFC_DLL@_WV?$ChTraitsCRT@_W@ATL@@@@@ATL@@A) already defined in Speech.obj

解决方案:变量或者函数的定义放到cpp文件中,不要放到.h中~

posted on 2013-07-01 15:35  Freshman11  阅读(3150)  评论(0编辑  收藏  举报

导航