?
Solved

fatal error C1189: #error :  WINDOWS.H already included.

Posted on 2006-06-26
9
Medium Priority
?
923 Views
Last Modified: 2008-01-09
First of all, I've never used MFC.   I'm mainly an ATL developer so dont kill me for this question..

I'm needing to talk to a web server via XML from an ATL service that uses MFC and the service is calling:
CInternetSession, CHttpConnection, and CHttpFile, which I've never used..   I'm a Winsock type of guy..

The service is having some compiling issues and after looking these functions up I found the project didnt have #include "afxinet.h" and so when I add them I get a fatal error C1189: #error :  WINDOWS.H already included.

How do I get around this error??

Here is the code it's using..

      CInternetSession session("temp", 1);
      CHttpConnection* pConn = NULL;
      CHttpFile* pFile = NULL;

      char szBuff[10000];
      DWORD dwRet;
      CString csWk;

      CString csURL = "domain.com";
      CString csContext = "/dir/path";

      try
      {
            INTERNET_PORT nPort = 443;

            pConn = session.GetHttpConnection(csURL, INTERNET_FLAG_DONT_CACHE, nPort);
            pFile = pConn->OpenRequest(CHttpConnection::HTTP_VERB_POST, csContext, NULL, 1, NULL, NULL, INTERNET_FLAG_SECURE);

            CString csXML = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>......";
            int nLen = csXML.GetLength();
            CString csRet = "";

            pFile->SendRequest(NULL, 0, ((void*)(LPCSTR)csXML), nLen);
            pFile->QueryInfoStatusCode(dwRet);

            if (dwRet == HTTP_STATUS_OK)
            {
                  UINT nRead;

                  while (true)
                  {
                        nRead = pFile->Read(szBuff, 4095);
                        if (nRead <= 0)
                              break;

                        szBuff[nRead] = 0;
                        csRet += szBuff;
                  }
            }
      }
      catch (CInternetException* pEx)
      {
            //. . .
            pEx->Delete();
      }

      return 1;
0
Comment
Question by:Chizl
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16989913
First you compile by not including the header file
#include "afxinet.h"
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16989939
Actually somehow the include file "windows.h" is included again
0
 
LVL 48

Expert Comment

by:AlexFM
ID: 16989997
Where did you add exactly this include line?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:Chizl
ID: 16990105
Rajeev, it will not compile and I get like 46 errors and yea, somehow.....
First error being:
H:\Code\C++\MyApp\MyClass.cpp(71) : error C2065: 'CInternetSession' : undeclared identifier


AlexFM,
I put #include "afxinet.h" at the top of my cpp.

// MyClass.cpp: implementation of the CMyClass class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MyClass.h"
#include "afxinet.h"
...
..
0
 
LVL 12

Expert Comment

by:rajeev_devin
ID: 16990156
Goto
#include "stdafx.h"
and check whether you have an entry of
#include <windows.h>

If it is there then simply remove it.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 2000 total points
ID: 16990270
>>>> If it is there then simply remove it.

No. stdafx.h is the header file for the Precompiled Header and *must* include windows.h.

>>>> afxinet.h

To get around the error you should include afxinet.h in the stdafx.h (below include afx.h == MFC). The make a Rebuild All (cause Precompiled Header needs to get replaced).

Regards, Alex
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 16990374
FYI:  MFC is optimized to use Precompiled Headers (PCH) via stdafx.h. That means that in a MFC project any cpp file (which is not excluded from PCH) needs to include "stdafx.h" prior to any other include file. There is one cpp file in project - normally stdafx.cpp - which creates the PCH. When compiling cpp files different from stdafx.cpp the compiler ignores any definition, statement or include above the include of "stdafx.h" and takes the PCH instead, what normally speeds up compilation time cause stdafx includes whole WINAPI and MFC.

The problem you run into is that afx.h the main header of MFC checks whether it was included prior to any other (Windows or MFC) header. That is to prevent user to put include statements above the include of stdafx.h where these includes would be ignored in case of PCH.

The way out is either to include additional header files below stdafx.h or to include these headers in stdafx.h - thus pushing them to PCH - below the incude of afx.h.

You also could turn off PCH option for the project or one/some individual cpp(s). However, the latter only helps if you still consider that afx.h must be included prior to any of the other MFC or WINAPI header files.

Regards, Alex
0
 
LVL 4

Author Comment

by:Chizl
ID: 16996899
I'm out of office today, but as soon as I get back tonight, I'll try this..
0
 
LVL 4

Author Comment

by:Chizl
ID: 16998088
itsmeandnobodyelse, you are the best!

Thanks,
Chizl
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question