include header problem?

include header problem?

Post by paul » Sat, 24 Dec 2005 07:35:23


Hi,

I have a problem with header file included in my project under windows.

As you know, in ws2tcpip.h, IP_ADD_MEMBERSHIP is defined as 12, however,
in winsock.h (which is included in windows.h) this value is 5. So when I
include
ws2tcpip.h and windows.h in my project, why isn't there any warning for
macro redefinition?

Here is the code:

#include <stdafx.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>

int main()
{
int add_member = IP_ADD_MEMBERSHIP;
....

}

there is no warning during compiling. and the value add_member is 12;
however, if I didn't include <ws2tcpip.h> and there is no problem
of compilation, and the value of add_member is 5;

Can anybody help me how to understand that? Maybe it is a stupid question
for you, but I am bit of lost. Thanks for your reply.
 
 
 

include header problem?

Post by Simon Tre » Wed, 04 Jan 2006 20:21:26


...but you're not including winsock.h, you're including winsock2.h. At the
top of winsock2.h we see:

#define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */

And indeed, this does prevent its inclusion (or at least it having any
effect). So there's no multiple definition.

S.

 
 
 

include header problem?

Post by paul » Thu, 05 Jan 2006 07:35:34

Thank you, Simon!