首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

下面的代码时而有有关问题时而没有有关问题

2012-02-29 
下面的代码时而有问题时而没有问题#importC:\ProgramFiles\CommonFiles\System\ado\msado15.dll no_name

下面的代码时而有问题时而没有问题
#import   "C:\Program   Files\Common   Files\System\ado\msado15.dll "no_namespace   rename( "EOF ", "rsEOF ")
#include <iostream>
#include <Afx.h>
#include <comutil.h>
#pragma   comment(   lib,   "comsupp.lib "   )

using   namespace   std;

void   main()
{
int   i=100;
long   l=2001;
float   f=300.2;
double   d=12345.119;
char   username[]= "David ";
char*   buf;
CString   str;
_variant_t   v1;
_bstr_t   v2;
}

报的错误是:
c:\Program   Files\Microsoft   Visual   Studio   .NET   2003\Vc7\atlmfc\include\afxv_w32.h(18):   fatal   error   C1189:   #error   :     WINDOWS.H   already   included.     MFC   apps   must   not   #include   <windows.h>
把afxv_w32.h这个头文件下的
#error   WINDOWS.H   already   included.     MFC   apps   must   not   #include   <windows.h>
这段代码屏蔽了就没有问题了。。。
为什么

[解决办法]
fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include

这个一般都是VC的预编译头文件所引起的。如果再编译选项中选择使用预编译头文件,则#include <stdafx.h> 应放在所有包含文件上面。
[解决办法]
非MFC工程使用MFC库时最常见的问题就是windows.h重复包含错误
[解决办法]
解决办法

非MFC工程使用MFC库时,可参考以下步骤

1、工程设置中,将MFC的使用由原来的“使用标准windows库”改为“在共享DLL中使用MFC”(VC71)

如果是英文版,相关选项是:

Microsoft Foundation Classes: Use MFC in a shared dll, no using MFC(VC6)

NOTE:因为我用的是中文版的vc71,英文版的vc6.

2、头文件包含

不同的MFC类需包含的头文件是不一样的。

常用的类,如Cstring, Cedit 等,包含afxwin.h就可以了

如果不清楚包含什么头文件的话,可以同msdn进行查询,msdn中,对于MFC类的介绍中,都会给出相应的header file requirement.

3、#include 语句一定要写在首行

这一点很重要,通常出现前面讲到的windows.h重复包含错误,都是因为#include 语句没有写在首行。

另外还要注意的是,如果#include语句是在一个头文件里,那么对应头文件的包含也要写在首行。

热点排行