cannot open source file "afxwin.h"/"afxext.h"/"afxdisp.h"/"afxdtctl.h"/"afxcmn.h"/afxdisp.h etc

34,273

Solution 1

I just fixed a similar problem. Here's how you can resolve this.

  1. Go to your control panel
  2. Navigate to uninstall/change a program.
  3. Scroll down until you see your visual studio installation
  4. Click change
  5. Once the window pops up, click "Modify"
  6. Under Programming Languages -> Visual C++ Make sure "Microsoft Foundation Classes for C++" is checked. If it isn't select it and click update.

Solution 2

For VS2019 the above solutions didn't worked for me. I had to go to "Installer -> Individual Components -> " and install the following to solve the issue:

  • "MSVC v141 – VS 2017 C++ x64/x86 build tools (v14.16)"
  • "C++ MFC for v141 build tools (x86 & x64)"
  • "C++ ATL for v141 build tools (x86 & x64)"

Solution 3

For what it's worth. I was getting similar errors after a fresh installation of VS2017. I installed the C++ features from the main installer and created a new project with MFC checked. I assumed "Microsoft Foundation Classes for C++" was installed by this point, but I kept getting these errors. Furthermore, after saving and closing the solution for the first time, VS wouldn't load the project if I opened the solution from the recently used list because dependencies were missing.

What worked for me

I opened the solution file directly using VS2017. Finally, VS informed me that "Microsoft Foundation Classes for C++" was not installed and gave me the option to install it. I had previously looked through the installer features and could not find this option.

EDIT

Per Vladimir's comment below...

In 2017 Visual Studio Installer it ["Microsoft Foundation Classes for C++"] is under Modify / Individual Components / SDKs... / MFC and ATL support (x86 and x64)

Share:
34,273

Related videos on Youtube

Curly
Author by

Curly

Updated on July 09, 2022

Comments

  • Curly
    Curly 6 months

    I try to ran a previous written MFC c++ code on my visual studio 2015 MFC with multitype MFC library installed.

    However, I still have 12 errors here regarding missing function:

    IntelliSense: cannot open source file "afxwin.h" C1083 Cannot open include file: 'afxwin.h': No such file or directory cannot open source file "afxext.h"/"afxdisp.h"/"afxdtctl.h"/"afxcmn.h"/afxdisp.h etc....

    Where can I get these head files?

    Again, my set up is:

    VIsual studio 2015 ultimate MFC Multibyte MFC library installed Windows 8 - 64 bit machine

    Thanks!

    • Curly
      Curly over 7 years
      I found "afxwin.h" under my directory of: C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include\ How should I include this directory in my code? Thanks!
    • cha
      cha over 7 years
      I think all you need to do is to select a proper platform toolset in the VC project property. Should be something like "v140"
  • jacobq
    jacobq about 6 years
    I do not see this option in Visual Studio 2005 (using old version to target legacy Windows CE 6.0 application). Any suggestions for how to install this component in this case?
  • Vladimir Shutow
    Vladimir Shutow almost 5 years
    In 2017 Visual Studio Installer it is under Modify / Individual Components / SDKs... / MFC and ATL support (x86 and x64)
  • Chintan
    Chintan over 4 years
    This has helped me a lot. I spent almost half day searching which version should I install or what components. (y) Thank You @VladimirShutow
  • Malachi
    Malachi almost 3 years
    For my scenario, I needed to do this with VS2015 installer even though I am opening project in VS2017/VS2019.
  • dab0bby
    dab0bby almost 3 years
    For VS2019 Open the Installer, select Modify for your installation and select C++ ATL for latest xxx build tools (xxx) and C++ MFC for latest xxx build tools (xxx) in Individual components. Replace xxx accordingly to your version and platform.
  • Juan Rojas
    Juan Rojas almost 3 years
    I have the same error in a project, MFC is installed correctly because another MFC project works just fine. I have compared the settings in both projects with no luck :(
  • Jimbo1987
    Jimbo1987 11 months
    Make that "Tools -> Get Tools and Features [which opens the VS Installer and selects the VS instance you are currently using] -> Individual Components [the top tab, not the "Individual components" in the right pane]. Check the needed components and click 'Modify". The version ('v141') must match the target framework for the project (Solution Explorer [right-click Project] -> Properties -> Configuration Properties -> General -> Platform Toolset). The three components you identified are found in sections named "Compilers, build tools, and runtimes" and "SDKs, libraries, and frameworks".

Related