problem : Completely silent, careless a file contains the Windows.h header file, and the Windows.h file has winsock.h file in it,
If the next time you use the Winsock2.h file, the location is incorrect, and the compiler will give you a lot of redefinition errors.
Primary Solutions :
Put the winsock2.h file in front of any file that might contain winsock.h (especially the Windows.h file, which contains the Winsock.h file), because the Winsock2.h header file has such a macro definition:
#ifndef _winsock2api_
#define _winsock2api_
#define _winsockapi_ /* Prevent inclusion of winsock.h in Windows.h */
If the Winsock.h header file is referenced after Winsock2.h, then the Winsock.h file is not used for any OVA.
When building an application, even if it is not an MFC application, there is this thing:
The online interpretation of the stdafx.h file is: a project (project) used in some of the MFC standard header files (such as Windows.H, Afxwin.H) pre-compile, later when the project compiles, no longer compile this part of the header file , using only the precompiled results. This can speed up compilation and save time.
The scary thing is that it contains the Windows.h file , but it's not scary: when we use AppWizard to generate certain projects, the system automatically includes the header file of the include in the stdafx.h, so that We just need to include this stdafx.h file directly. only occurs when you use AppWizard to generate a project. Otherwise, there is no need to include this header file StdAfx.h . Reference Web page.
So if it is MFC and other Windows window project, need to StdAfx.h precompiled header deleted, or other applications to delete it does not matter.
But...... But...... But...... Even if I took the above approach, and one after another to track my own written header files, see Winsock.h and winsock2.h included in the relationship, all meet the winsock2.h in front of the relationship, but there are still redefined, this time I see a different article, which mentions " But when I call it in a wxwidgets, there's the annoying error "sockaddr": "struct" type redefined, Obviously wxwidgets first contains windows.h, now the head is big, think how to solve, in all the file at the beginning of the definition _winsock2api_ is useless ", just want to say hehe. If someone leng first contains the Windows.h file (such as MFC's stdafx.h header file), then you can not do it.
The ultimate approach:
However, the ultimate way to do this is to add the win32_lean_and_mean macro definition and add the macro definition in the despair directly in the VS setting:
So, this strange macro definition is what, after checking some information, it is said that " do not load MFC required modules ." It is faster and less capacity when compiling links, and in the last generation of modules for debugging. "A lot of places are so said, do not give links, interested in their own search this macro bar."
However, I still wonder where I load the modules required by MFC, in fact, I am very curious about the above figure _windows This macro is what, but temporarily did not search the relevant information.
Summary : In fact, we also see that the so-called ultimate solution can only solve this non-MFC application problems, as for other situations such as this problem, I have not explored, after all, have not met.
feeling : The following options do not know the circumstances of the time not to blindly choose Kazakhstan:
There is also the SDL check, personal advice not to choose, because Windows has its own set of _s security functions, otherwise, you will not pass the various compilations, but also to its _s (safe) function, this time you have to modify more things. Of course, this SDL check is still useful, after all, people's function is more safe, but the last time the use of the vsnprinf_s function, because it provides additional parameter problems, this parameter of the error caused my program in a strange error, are tears.
I'm not going to use it because I'm being asked to use vs for development, and I'm not using it either personally or in favor of the Linux platform. VS development in order to make development easier, more stupid, it silently help you do a lot of things, when you go wrong, you do stare. Also because of the use of various Ides, many programmers do not understand the entire compilation process, always accustomed to a key build. Of course, each has a good, each has its own application, I personally prefer the use of GCC.
VS2013 the ultimate solution after conflict with Winsock.h and Winsock2.h