zoukankan      html  css  js  c++  java
  • MFC工程中不要#include <windows.h>,否则会出错。 from http://applehxb.blogbus.com/logs/48742135.html

     如果在MFC工程中#include   <windows.h>,那么会有以下编译错误(因为afxwin.h文件中包含了afx.h,afx.h文件中包含了afxver_.h,afxver_.h中包含了afxv_w32.h,而afxv_w32.h中包含了windows.h,请看以下分析):

      compile   error:   
      c:\program   files\microsoft   visual   studio\vc98\mfc\include\afxv_w32.h(14)   :   
      fatal   error   C1189:   #error   :     WINDOWS.H   already   included.     MFC   apps   must   not   #include   <windows.h>   
                
      如果编译器在编译afxv_w32.h文件之前编译了windows.h文件,编译器会报上面的错误,因为在afxv_w32.h文件中有下面的一句预编译报警:   
      #ifdef   _WINDOWS_   
      #error   WINDOWS.H   already   included.     MFC   apps   must   not   #include   <windows.h>   
      #endif   
        
      问题在于为什么afxv_w32.h中要有这么一句预编译处理。看了afxv_w32.h和windows.h文件就有点明白了。   
      在afxv_w32.h中有下面的预编译语句:   
      ...   ...   
      #undef   NOLOGERROR   
      #undef   NOPROFILER   
      #undef   NOMEMMGR   
      #undef   NOLFILEIO   
      #undef   NOOPENFILE   
      #undef   NORESOURCE   
      #undef   NOATOM   
      ...   ...   
      在afxv_w32.h中还有一句:   
      #include   "windows.h"   
        
      而在windows.h文件中有下面的预编译语句:   
      ...   ...   
      #define   NOATOM   
      #define   NOGDI   
      #define   NOGDICAPMASKS   
      #define   NOMETAFILE   
      #define   NOMINMAX   
      #define   NOMSG   
      #define   NOOPENFILE   
      ...   ...   
        
      注意到在windows.h的开头有防止windows.h被重复编译的预编译开关:   
      #ifndef   _WINDOWS_   
      #define   _WINDOWS_   
        
      这样问题就明白了,虽然我不知道微软为什么要这么做,但是我知道如果在afxv_w32.h没有那句预编译报警,那么如果在编译afxv_w32.h之前   
      编译了windows.h,那么在windows.h中#define的NOATOM等宏就会被#undef掉,可能会导致相应的错误发生。   
        
      猜想原因可能如上所述,我的解决方法是,将包含有#include   “windows.h"的头文件放在所有包含的头文件的最后面,这样使得对afxv_w32文件   
      的编译处理发生在先,这样,由于在afxv_w32.h中已经包含了windows.h,那么宏_WINDOWS_将被定义,后继的#include   "windows.h"语句将形同虚设,   
      上面的编译报警也不会发生了。我觉得这种处理要比将所有的#include   "windows.h”语句删掉要好一点。   
        
      一句话,编译器必须在编译windows.h之前编译afxv_w32.h,因为我不是十分清除什么时候afxv_w32.h会被编译,所以我将可能包含有#include   "windows.h"的头文件放在其他头文件之后#include。

  • 相关阅读:
    使用supervisor做进程控制
    HDU 4272 LianLianKan [状态压缩DP]
    UVALive 4297 First Knight [期望+高斯消元(优化)]
    HDU 4269 Defend Jian Ge [模拟]
    POJ 2497 Widget Factory [高斯消元解同余方程组]
    HDU 2996 In case of failure [KD树]
    HDU 4268 Alice and Bob [贪心]
    HDU 4273 Rescue [三维几何]
    HDU 4267 A Simple Problem with Integers [树状数组]
    HDU 4271 Find Black Hand [最短编辑距离DP]
  • 原文地址:https://www.cnblogs.com/songtzu/p/2793528.html
Copyright © 2011-2022 走看看