locked
ERROR:WINDOWS.H already included. MFC apps must not #include <windows.h> RRS feed

  • Question

  • Hello ,

    I am creating the ATL Service application in that

    I am getting  the following error.
    fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>

    I have seen the solution for the error above suggested at http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/2ab6862f-0d90-467a-b283-f62f6aef96fe/

    and included the header file #include <afxcoll.h>.

    Now this is my stdafx.h header file looks

    #pragma once

    #ifndef STRICT
    #define STRICT
    #endif

    #include <afxcoll.h>
    #define _ATL_ALL_WARNINGS
    #include "targetver.h"
    #include "atlstr.h"

    #define _ATL_APARTMENT_THREADED
    #define _ATL_NO_AUTOMATIC_NAMESPACE

    #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS    // some CString constructors will be explicit



    #include "resource.h"
    #include <atlbase.h>
    #include <atlcom.h>
    #include <atlctl.h>
    #include <comutil.h>
    #include "atlsafe.h"


    using namespace ATL;


     When i rebuild the project, the above error is get removed but  getting the new errors.
     
    error C2504: 'CAtlServiceModuleT' : base class undefined
    Error    2    error C2143: syntax error : missing ',' before '<'
    Error    5    error C2791: illegal use of 'super': 'CSDMServiceModule' does not have any base classes   
    Error    6    error C2039: 'OnPause' : is not a member of '`global namespace''   
    Error    7    error C2791: illegal use of 'super': 'CSDMServiceModule' does not have any base classes  
    Error    8    error C2039: 'OnStop' : is not a member of '`global namespace''   
    Error    10    error C2791: illegal use of 'super': 'CSDMServiceModule' does not have any base classes   
    Error    11    error C2039: 'OnContinue' : is not a member of '`global namespace''
    Error    14    error C2039: 'WinMain' : is not a member of 'CSDMServiceModule'  
    Error    15    error C2146: syntax error : missing ';' before identifier 'm_csComm'
    Error    16    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int  
    Error    17    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int  

    I am not getting the solution please Help

    Thanks in Advance
    Logic is my Greatest Asset !
    Monday, December 21, 2009 12:53 PM

Answers

  • Hi RITESH_SHINDE,

    Have you included <windows.h> file in other .cpp files? If so, I would suggest you move it to stdafx.h header file, and #include"stdafx.h" in this .cpp file.

    If this is not the case, you can try to following ways:

    1.you can try to put <afxwin.h> before the atl headers in stdafx.h;
    2. Or try to delete _WINDOWS_ marco in project property setting.

    Please let me know if it works.

    Best Regards,
    Nancy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by RITESH_SHINDE Friday, December 25, 2009 5:45 AM
    Wednesday, December 23, 2009 10:04 AM

All replies

  • move your include to be the last include in stdafx.h
    You have some dependency you would like to resolve. I myself try to avoid including afxcoll.h, it is usually included by afx.h
    Monday, December 21, 2009 2:10 PM
  • move your include to be the last include in stdafx.h
    You have some dependency you would like to resolve. I myself try to avoid including afxcoll.h, it is usually included by afx.h
    Which Include to be last in stdafx.h?

    Logic is my Greatest Asset !
    Wednesday, December 23, 2009 3:42 AM
  • Hi RITESH_SHINDE,

    Have you included <windows.h> file in other .cpp files? If so, I would suggest you move it to stdafx.h header file, and #include"stdafx.h" in this .cpp file.

    If this is not the case, you can try to following ways:

    1.you can try to put <afxwin.h> before the atl headers in stdafx.h;
    2. Or try to delete _WINDOWS_ marco in project property setting.

    Please let me know if it works.

    Best Regards,
    Nancy
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by RITESH_SHINDE Friday, December 25, 2009 5:45 AM
    Wednesday, December 23, 2009 10:04 AM