Help me with "fatal error C1189: #error : WINDOWS.H already included"
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Help me with "fatal error C1189: #error : WINDOWS.H already included"

  1. #1
    Join Date
    Feb 2013
    Posts
    14

    Help me with "fatal error C1189: #error : WINDOWS.H already included"

    Hello,

    I have made few changes to my code like included the CAN Dll file with in my Application code.I am using VS 2008 and after compiling I am getting this error:

    Code:
    1>------ Build started: Project: NetworkComm, Configuration: Release Win32 ------
    1>Compiling...
    1>ServerMain.cpp
    1>c:\users\xzpgbn\desktop\networkcommdll\networkcomm\stdafx.h(13) : warning C4005: 'WINVER' : macro redefinition
    1>        C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\sdkddkver.h(166) : see previous definition of 'WINVER'
    1>C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\include\afxv_w32.h(16) : fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>
    1>Build log was saved at "file://c:\Users\xzpgbn\Desktop\NetworkCommDll\NetworkComm\Release\BuildLog.htm"
    1>NetworkComm - 1 error(s), 1 warning(s)
    ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
    I am including all my Headers file below

    Code:
    Stdafx.h
    =======
    #pragma once
    #define WINVER 0x500
    #include <iostream>
    #include <stdio.h>
    #include "targetver.h"
    #include <tchar.h>
    #define _CRT_RAND_S
    #include <stdlib.h>
    #include <stdio.h>
    #include <limits.h>
    //#include "vxlapi.h"
    //#include <windows.h>
    #include <afxwin.h>
    #ifndef _SECURE_ATL
    #define _SECURE_ATL 1
    #endif
    #ifndef _WIN32_WINNT
    #define _WIN32_WINNT 0x0500	 // Allow use of features specific to Windows XP.
    #endif
    #ifndef VC_EXTRALEAN
    #define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
    #endif
    //#include "targetver.h"
    #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit
    // turns off MFC's hiding of some common and often safely ignored warning messages
    #define _AFX_ALL_WARNINGS
    #define _AFXDLL
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    #ifndef _AFX_NO_OLE_SUPPORT
    #include <afxdtctl.h>           // MFC support for Internet Explorer 4 Common Controls
    #endif
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h>             // MFC support for Windows Common Controls
    #endif // _AFX_NO_AFXCMN_SUPPORT
    #include <afxcontrolbars.h>     // MFC support for ribbons and control bars
    #include <afx.h>
    #include <afxdhtml.h>
    #ifdef _UNICODE
    #if defined _M_IX86
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_IA64
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_X64
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #else
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #endif
    #endif
    
    c_settings.h
    =========
    #pragma once
    //#include "windows.h"
    #include <winsock2.h>
    #include <string.h>
    
    c_settings.cpp
    ===========
    #include "stdafx.h"
    #include "c_settings.h"
    using namespace System;
    #pragma warning(disable: 4996)
    
    global_variables.h
    =============
    #pragma once
    #pragma comment(lib,"Ws2_32.lib")
    //standard windows headers
    #include "stdafx.h"
    //#include "windows.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <winsock2.h>
    #include <time.h>
    #include <iostream>
    #include <conio.h>
    #include <fstream>
    #include <cstdlib>
    #include "Global_Threads.h"
    #include "Dll.h"
    #include "msg_manip.h"
    #include "ParseDbcFile.h"
    #include "c_settings.h"
    #include "Server.h"
    #include "messages.h"
    #include "CanMsg.h"
    #include "Logic.h"
    using namespace std;
    
    global_variables.cpp
    ===============
    #include "stdafx.h"
    #include "Global_Variables.h"
    #include "Server.h"
    
    server_main.cpp
    ============
    
    I think the error is in this file:
    
    #pragma comment(lib,"Ws2_32.lib")
    #define _WIN32_WINNT 0x0500
    //#include "afxwin.h"
    #include "Windows.h"
    #include "stdafx.h"
    #include <iostream>
    #include <conio.h>
    #include <fstream>
    #include <cstdlib>
    #include "Server.h"
    #include "Global_Variables.h"
    #include "math.h"
    #include "Dll.h"
    #include "Messages.h"
    #include "CanMsg.h"
    
    Dll.h
    ===
    vxlapi.h
    
    Dll.cpp
    =====
    #if defined(_Windows) || defined(_MSC_VER) || defined (__GNUC__)
     #define  STRICT
    #include "windows.h"
    //#include <afxwin.h>
    #endif
    //#include "stdafx.h"
    #include <stdio.h>
    #include <stdlib.h>
    //#include <stdexcept>
    #pragma once
    #include "vxlapi.h"
    #include "Dll.h"
    #include <stdexcept>
    
    Dll's stdafx.h
    ==========
    #pragma once
    //#include <windows.h>
    #include "targetver.h"
    #define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
    #include <windows.h>

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,057

    Re: Help me with "fatal error C1189: #error : WINDOWS.H already included"

    This line from the error seems pretty self-explanatory to me.

    "MFC apps must not #include <windows.h>"

  3. #3
    Join Date
    Feb 2013
    Posts
    14

    Re: Help me with "fatal error C1189: #error : WINDOWS.H already included"

    Quote Originally Posted by GCDEF View Post
    This line from the error seems pretty self-explanatory to me.

    "MFC apps must not #include <windows.h>"

    But I haven't used #include <windows.h>,except for the file server_main.cpp. When i am trying to remove the<windows.h> from that file I am getting the error as

    1>ServerMain.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEA): (0x020003ab).
    1>ServerMain.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_PROPSHEETPAGEW): (0x020003ae).
    1>ServerMain.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (tagLVITEMW): (0x020004ec).
    1>ServerMain.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (tagTOOLINFOW): (0x02000657).
    1>ServerMain.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (tagLVCOLUMNW): (0x0200066c).
    1>ServerMain.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (tagLVHITTESTINFO): (0x020006ef).
    1>ServerMain.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (tagREBARBANDINFOW): (0x02000820).
    1>ServerMain.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (_HD_ITEMW): (0x0200082d).
    1>ServerMain.obj : error LNK2022: metadata operation failed (8013118D) : Inconsistent layout information in duplicated types (MCHITTESTINFO): (0x0200083d).
    1>LINK : fatal error LNK1255: link failed because of metadata errors

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,057

    Re: Help me with "fatal error C1189: #error : WINDOWS.H already included"

    I don't know what those link errors mean, but you won't see them until the program compiles successfully, so by removing Windows.h, you've eliminated the original problem and moved on to the next one.

  5. #5
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,583

    Re: Help me with "fatal error C1189: #error : WINDOWS.H already included"

    I can't rememer ever having seen LNK2022 unless some managed code is involved. And this snippet from the OP strengthens that impression:

    Code:
    c_settings.cpp
    ===========
    #include "stdafx.h"
    #include "c_settings.h"
    using namespace System;
    #pragma warning(disable: 4996)
    Perhaps that helps diagnosing the problem.

    ... and perhaps I should add a statement about unnecessarily mixing managed and native code being really evil to my sig...
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,301

    Re: Help me with "fatal error C1189: #error : WINDOWS.H already included"

    Quote Originally Posted by Eri523 View Post
    I can't rememer ever having seen LNK2022 unless some managed code is involved.
    You seem to be correct!
    There is a http://support.microsoft.com/kb/324088
    and a lot of the discussion about this error in
    https://www.google.com/search?source...GEA)&gs_htsa=1
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center