Question

Visual Studio 2008 Cano Not Compile C/C++ with #include <winsock2.h>. Why?

Asked by: F-J-K

I included this header <winsock2.h>, my code did not compile eventhough i have not wrote any code relates to winsock yet.

I followed this instructions: http://www.errorbase.net/LINK_:_fatal_error_LNK1104:_cannot_open_file_%27(X).obj%27 (look at the bottom).

I added this in additional dependencies: "C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\WS2_32.Lib"

I still get same errors as before. Can you tell me how to fix this problem?

NOTE: i followed the steps, which is mentioned in the link above, in VC++ Express & it worked. But that was several months ago. Now i have VS Studio 2008

Extra Q: what is ws2def.h for?

1>------ Rebuild All started: Project: X-Shab, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'X-Shab', configuration 'Debug|Win32'
1>Compiling...
1>clientSide.cpp
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(91) : warning C4005: 'AF_IPX' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(460) : see previous definition of 'AF_IPX'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(127) : warning C4005: 'AF_MAX' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(479) : see previous definition of 'AF_MAX'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(163) : warning C4005: 'SO_DONTLINGER' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(402) : see previous definition of 'SO_DONTLINGER'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(206) : error C2011: 'sockaddr' : 'struct' type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(485) : see declaration of 'sockaddr'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(384) : error C2143: syntax error : missing '}' before 'constant'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(384) : error C2143: syntax error : missing ';' before 'constant'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(384) : error C2059: syntax error : 'constant'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(437) : error C2143: syntax error : missing ';' before '}'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(437) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(437) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(518) : warning C4005: 'IN_CLASSA' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(287) : see previous definition of 'IN_CLASSA'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(524) : warning C4005: 'IN_CLASSB' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(293) : see previous definition of 'IN_CLASSB'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(530) : warning C4005: 'IN_CLASSC' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(299) : see previous definition of 'IN_CLASSC'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(541) : warning C4005: 'INADDR_ANY' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(304) : see previous definition of 'INADDR_ANY'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(543) : warning C4005: 'INADDR_BROADCAST' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(306) : see previous definition of 'INADDR_BROADCAST'
1>c:\program files\microsoft sdks\windows\v6.0a\include\ws2def.h(577) : error C2011: 'sockaddr_in' : 'struct' type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(312) : see declaration of 'sockaddr_in'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(132) : error C2011: 'fd_set' : 'struct' type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(68) : see declaration of 'fd_set'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(167) : warning C4005: 'FD_SET' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(102) : see previous definition of 'FD_SET'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(176) : error C2011: 'timeval' : 'struct' type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(111) : see declaration of 'timeval'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(232) : error C2011: 'hostent' : 'struct' type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(167) : see declaration of 'hostent'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(245) : error C2011: 'netent' : 'struct' type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(180) : see declaration of 'netent'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(252) : error C2011: 'servent' : 'struct' type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(187) : see declaration of 'servent'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(264) : error C2011: 'protoent' : 'struct' type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(199) : see declaration of 'protoent'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(360) : error C2011: 'WSAData' : 'struct' type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(322) : see declaration of 'WSAData'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(458) : error C2011: 'sockproto' : 'struct' type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(494) : see declaration of 'sockproto'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(500) : error C2011: 'linger' : 'struct' type redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(531) : see declaration of 'linger'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(513) : warning C4005: 'SOMAXCONN' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(544) : see previous definition of 'SOMAXCONN'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(542) : warning C4005: 'FD_READ' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(562) : see previous definition of 'FD_READ'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(545) : warning C4005: 'FD_WRITE' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(563) : see previous definition of 'FD_WRITE'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(548) : warning C4005: 'FD_OOB' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(564) : see previous definition of 'FD_OOB'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(551) : warning C4005: 'FD_ACCEPT' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(565) : see previous definition of 'FD_ACCEPT'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(554) : warning C4005: 'FD_CONNECT' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(566) : see previous definition of 'FD_CONNECT'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(557) : warning C4005: 'FD_CLOSE' : macro redefinition
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(567) : see previous definition of 'FD_CLOSE'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1527) : error C2375: 'accept' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(735) : see declaration of 'accept'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1548) : error C2375: 'bind' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(740) : see declaration of 'bind'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1567) : error C2375: 'closesocket' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(745) : see declaration of 'closesocket'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1586) : error C2375: 'connect' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(747) : see declaration of 'connect'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1607) : error C2375: 'ioctlsocket' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(752) : see declaration of 'ioctlsocket'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1628) : error C2375: 'getpeername' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(757) : see declaration of 'getpeername'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1649) : error C2375: 'getsockname' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(762) : see declaration of 'getsockname'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1672) : error C2375: 'getsockopt' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(767) : see declaration of 'getsockopt'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1693) : error C2375: 'htonl' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(774) : see declaration of 'htonl'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1710) : error C2375: 'htons' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(776) : see declaration of 'htons'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1728) : error C2375: 'inet_addr' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(778) : see declaration of 'inet_addr'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1745) : error C2375: 'inet_ntoa' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(780) : see declaration of 'inet_ntoa'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1763) : error C2375: 'listen' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(782) : see declaration of 'listen'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1781) : error C2375: 'ntohl' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(786) : see declaration of 'ntohl'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1798) : error C2375: 'ntohs' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(788) : see declaration of 'ntohs'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1818) : error C2375: 'recv' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(790) : see declaration of 'recv'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1843) : error C2375: 'recvfrom' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(796) : see declaration of 'recvfrom'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1869) : error C2375: 'select' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(804) : see declaration of 'select'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1893) : error C2375: 'send' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(811) : see declaration of 'send'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1918) : error C2375: 'sendto' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(817) : see declaration of 'sendto'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1944) : error C2375: 'setsockopt' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(825) : see declaration of 'setsockopt'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1966) : error C2375: 'shutdown' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(832) : see declaration of 'shutdown'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(1986) : error C2375: 'socket' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(836) : see declaration of 'socket'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2009) : error C2375: 'gethostbyaddr' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(843) : see declaration of 'gethostbyaddr'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2029) : error C2375: 'gethostbyname' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(848) : see declaration of 'gethostbyname'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2047) : error C2375: 'gethostname' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(850) : see declaration of 'gethostname'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2067) : error C2375: 'getservbyport' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(854) : see declaration of 'getservbyport'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2087) : error C2375: 'getservbyname' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(858) : see declaration of 'getservbyname'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2106) : error C2375: 'getprotobynumber' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(862) : see declaration of 'getprotobynumber'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2124) : error C2375: 'getprotobyname' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(864) : see declaration of 'getprotobyname'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2145) : error C2375: 'WSAStartup' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(868) : see declaration of 'WSAStartup'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2163) : error C2375: 'WSACleanup' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(872) : see declaration of 'WSACleanup'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2180) : error C2375: 'WSASetLastError' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(874) : see declaration of 'WSASetLastError'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2197) : error C2375: 'WSAGetLastError' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(876) : see declaration of 'WSAGetLastError'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2214) : error C2375: 'WSAIsBlocking' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(878) : see declaration of 'WSAIsBlocking'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2231) : error C2375: 'WSAUnhookBlockingHook' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(880) : see declaration of 'WSAUnhookBlockingHook'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2248) : error C2375: 'WSASetBlockingHook' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(882) : see declaration of 'WSASetBlockingHook'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2265) : error C2375: 'WSACancelBlockingCall' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(884) : see declaration of 'WSACancelBlockingCall'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2287) : error C2375: 'WSAAsyncGetServByName' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(886) : see declaration of 'WSAAsyncGetServByName'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2314) : error C2375: 'WSAAsyncGetServByPort' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(894) : see declaration of 'WSAAsyncGetServByPort'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2340) : error C2375: 'WSAAsyncGetProtoByName' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(902) : see declaration of 'WSAAsyncGetProtoByName'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2365) : error C2375: 'WSAAsyncGetProtoByNumber' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(909) : see declaration of 'WSAAsyncGetProtoByNumber'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2390) : error C2375: 'WSAAsyncGetHostByName' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(916) : see declaration of 'WSAAsyncGetHostByName'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2417) : error C2375: 'WSAAsyncGetHostByAddr' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(923) : see declaration of 'WSAAsyncGetHostByAddr'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2440) : error C2375: 'WSACancelAsyncRequest' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(932) : see declaration of 'WSACancelAsyncRequest'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(2461) : error C2375: 'WSAAsyncSelect' : redefinition; different linkage
1>        c:\program files\microsoft sdks\windows\v6.0a\include\winsock.h(934) : see declaration of 'WSAAsyncSelect'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(3910) : error C2059: syntax error : '}'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(3910) : error C2143: syntax error : missing ';' before '}'
1>c:\program files\microsoft sdks\windows\v6.0a\include\winsock2.h(3910) : error C2059: syntax error : '}'

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-01-24 at 15:40:57ID24080839
Tags

C C++ Windows Socket Winsock

Topics

Winsock

,

C++ Programming Language

,

Visual Studio

Participating Experts
1
Points
500
Comments
8

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. winsock2.h
    Hi! I am new in C++. I am working with VC++ and I am trying to use the winsock2 library. When I use a function from this library (like gethostname, gethostbyname, etc.), the linker fails with the message : Getaddr.obj : error LNK2001: unresolved external symbol __imp__getho...
  2. MFC versus winsock2.h
    Hi I am using Visual C++ 6.0 I have made a "hello world" program via the wizard I am doing #include "stdafx.h" #include "resource.h" #define WIN32_LEAN_AND_MEAN #include <process.h> #include <winsock2.h> I want to use the "s...
  3. Are the functions defined in winsock2.h poratble to the P…
    I'm trying to find out if the select function implented in winsock2.h is portable to other systems. It dosen't what the WSA prefix, so I think it should be portable, but am not sure. If not, how else can you avoid causing a socket to block from a recv call when the buffer h...
  4. Linking Ws2_32.lib
    For the life of me I can't get Ws2_32.lib to be seen in my link when using ntohl() and ntohs() calls VC++6. I've tried to include the additional lib path to where the lib is located yet just get the link error LNK1104: cannot open file files/microsoft.obj.
  5. Cannot include <winsock2.h>, wtf?
    Whenever I attempt to include <winsock2.h> in my program, I get a bunch of messages saying it is redefining alot of stuff. When I remove this include and include just: <windows.h> <string> I can compile successfully and the sockets work, but I don't have a...
  6. Problems with winsock2.h
    Hello im trying to program a client server model in C++ and wanted to do this with winsock2.h. But it doesnt seem to be able to find this in MSVC++ 6.0. Or are the functions wrong here a sample code: pubcomm::pubcomm() { } pubcomm::~pubcomm() { pubcomm::close(); ...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: itsmeandnobodyelsePosted on 2009-01-25 at 00:42:44ID: 23460103

The problem is that both winsock.h and winsock2.h were included which have most definitions in common. winsock2.h knows of winsock.h but not the other way rounde. Hence, you need to include winsock2.h *before* winsock.h. If using stdafx.h you should try to include winsock2.h as early as it compiles. If not, try to include winsock2.h as the very first include in each cpp. If this doesn't help or give other errors, open the winsock.h and check which macro protects from including it twice.. It should be like

#ifdef _winsock_h_included_
#define _winsock_h_included_

if found define the _winsock_h_included_ as a preprocessor macro in your project setting (simply add it to the other macros like _WIN32)

 

by: F-J-KPosted on 2009-01-25 at 02:22:16ID: 23460304

I put this at the top #include <winsock2.h> & my code compiled, so does this mean will take winsock2.h as the main winsock header & ignore the old version?

I never expected the order of headers is kind of important. Can you explain why this is important & when such situation usually occurs?

 

by: F-J-KPosted on 2009-01-25 at 02:25:26ID: 23460315

FIX:
.....so does this mean *compiler* will take winsock2.h.....

I never expected the order of headers is kind of important to *compilers*....

 

by: F-J-KPosted on 2009-01-25 at 02:32:01ID: 23460336

Another Question:

Which one is better, #include<Ws2tcpip.h> & #include<Winerror.h>  - I will need these two headers to help me deal with errors, etc.

OR

i just do this: #include<windows.h>?

Why this is better?

 

by: F-J-KPosted on 2009-01-25 at 11:25:22ID: 31538548

This helped...Cheers

 

by: itsmeandnobodyelsePosted on 2009-01-25 at 13:20:40ID: 23462747

>>>>> I never expected the order of headers is kind of important.
Normally it shouldn't. Each piece of source, header or implementation should include the headers needed and only these.

But of course if the header b.h needs some definitions made in a.h the b.h has to include a.h and not the other way round.

In case of a enhancement, developers - even members of the major and leading companies - sometimes have funny ideas. They supply a new header which was supposed to replace an older one but they don't change the older header for compatibility reasons. And sometimes - as it was with winsock.h - the older header survived as the enhancements coming with winsock2.h were only important for a few projects. Moreover, the non-Windows community ignored the winsock2.h hence it was a MS proprietary solution.

>>>> so does this mean will take winsock2.h as the main winsock header & ignore the old version?

Yes, the winsock2.h defines the macro which causes a further include of winsock.h to skip all the definitions and includes made in winsock.h. But if you have a file which includes winsock.h prior to winsock2.h you'll get the problems you posted above. It might be 10 or more years ago when I had the same problems.

>>>> Which one is better, #include<Ws2tcpip.h> & #include<Winerror.h>

I never included the first one and often used the second one - less to actually make an own error handling but to simply find out what a specific error returned by GetLastError means. There are runtime functions which would translate a given error code to the text given in winerror.h. I never used them myself cause a look to winerror.h does the same and I never had a reason to automate that.

 

by: itsmeandnobodyelsePosted on 2009-01-25 at 13:30:31ID: 23462784

>>>> i just do this: #include<windows.h>?
>>>> Why this is better?

I don't know whether it is *better* but you could trust when including windows.h that all basic WINAPI was included. The questions arise if you want to  use more than the basics. Do you have to include the additional headers before or after windows.h. As a rule of thumb, I would include them before cause they often include windows.h theirselfes at the right order, so your own include of windows.h was skipped and it was good so cause windows.h needed to be included in order. Some headers really were independent and you can include them before or after, it doesn't matter.

 

by: F-J-KPosted on 2009-01-25 at 16:31:47ID: 23463413

I appreciate it...

Best Regards,
F.J

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...