in ATL #include <afxinet.h> causes MFC apps must not #include <windows.h> error

In an ATL IEHelper project I need to use
CInternetSession session;
and hence to include

but I receive
afxv_w32.h(14) : fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

I already placed the string #include<afxinet.h> in all possible places,  but the error still occured.
Pls advise the workaround.
Who is Participating?
tdubroffConnect With a Mentor Commented:
Yes you could restart your project and select the support MFC button, however its not hard to 'hand code' this functionality yourself.  Follow the steps below and you should be on your way:

1) In stdafx.h, just below the line #define STRICT, type in the following:

    // for MFC support
    #include <afxwin.h>
    #include <afxdisp.h>
    // end for MFC

2) In your main .cpp file, where the DllMain() function resides as well as where _Module is defined, type in the following just below the BEGIN_OBJECT_MAP(ObjectMap), END_OBJECT_MAP() macro pair:

    class CYourApp : public CWinApp
      virtual BOOL InitInstance();
      virtual int ExitInstance();

    CYourApp theApp;

    BOOL CYourApp::InitInstance()
      _Module.Init(ObjectMap, m_hInstance);
      return CWinApp::InitInstance();

    int CYourApp::ExitInstance()
      return CWinApp::ExitInstance();

3) In the same file, comment out the DllMain() function

That should do it.  Hope this helps.

Well, it seems that you writing a non-MFC project + trying to use an MFC class.
If you do want to use MFC, you need to switch to an MFC based project. Either start a new one (the easiest way if you project is still pretty small), or make some changes in the project's infrastructure (Like changing the four exported functions and the DLLmain in case of an inproc-server).
AssafLavie is right
rolling_ballAuthor Commented:
Thanks people.
tdubrof - your answer is excellent, I've done all you said and it starts working :)).

Another related question: previously I tryed to make this project support MFC, in project settings I changed to support MFC as shared dll, and saved and restarted project but it was still not supporting MFC.

I found a Microsoft page that explains everything in more detail:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.