VC++ Express Edition 中缺少 afxwin.h 文件

38

当我尝试将文件从VC ++ 2005运行到VC ++ 2008时:

1>------ Build started: Project: canvas, Configuration: Debug Win32 ------  
1>Compiling...  
1>canvasApp.cpp  
1>c:\documents and settings\ram\my documents\visual studio 2008\demo\stdafx.h(1) : fatal error C1083: Cannot open include file: 'afxwin.h': No such file or directory  
1>canvasFrame.cpp  
1>c:\documents and settings\ram\my documents\visual studio 2008\demo\stdafx.h(1) : fatal error C1083: Cannot open include file: 'afxwin.h': No such file or directory  
1>Generating Code...  
1>Build log was saved at "file://c:\Documents and Settings\ram\My Documents\Visual Studio 2008\demo\Debug\BuildLog.htm"  
1>canvas - 2 error(s), 0 warning(s)  
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========  
4个回答

36

4
尽管这个回答是谷歌搜索结果中的热门之一,但它非常过时。自从VS Community 2014以后,MFC就已经免费了。 - user136036
2
同意,但这个答案是针对问题中的Visual Studio 2008特定的。 - D Hansen

14

包含头文件 afxwin.h 表示使用 MFC。以下指示(基于CodeProject.com上的指示)可帮助编译MFC代码:

  1. 下载并安装Windows Driver Kit

  2. 选择菜单工具 > 选项… > 项目和解决方案 > VC++目录

  3. 在下拉菜单显示目录中选择包含文件

  4. 添加以下路径(将$(WDK_directory)替换为您在第一步中安装Windows Driver Kit的目录):

    $(WDK_directory)\inc\mfc42
    $(WDK_directory)\inc\atl30
    

  5. 在下拉菜单Show directories for中选择Library files,并添加(替换与之前相同的$(WDK_directory)):

  6. $(WDK_directory)\lib\mfc\i386
    $(WDK_directory)\lib\atl\i386
    

  7. $(WDK_directory)\inc\mfc42\afxwin.inl文件中,编辑以下行(从1033开始):

  8. _AFXWIN_INLINE CMenu::operator==(const CMenu& menu) const
        { return ((HMENU) menu) == m_hMenu; }
    _AFXWIN_INLINE CMenu::operator!=(const CMenu& menu) const
        { return ((HMENU) menu) != m_hMenu; }
    

    _AFXWIN_INLINE BOOL CMenu::operator==(const CMenu& menu) const
        { return ((HMENU) menu) == m_hMenu; }
    _AFXWIN_INLINE BOOL CMenu::operator!=(const CMenu& menu) const
        { return ((HMENU) menu) != m_hMenu; }
    
    换句话说,在_AFXWIN_INLINE之后加上BOOL

第五步仍然需要。您的项目可能不使用这些行,但它们仍然存在错误,需要修复。 - malat
@malat 我已经编辑了我的答案,直接包含了更新的说明,请现在检查一下。 - Melebius

7

我看到这个问题是关于Express Edition的,但是这个话题很容易在Google搜索中弹出,并且没有其他版本的解决方案。

所以,如果你在任何VS Edition(除了Express)中遇到这个问题,你可以重新运行安装并包含MFC文件。


3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接