I'm having a problem including both files. Now, I know I need to either include Winsock2 first, then windows.h, or simply put:
#define WIN32_LEAN_AND_MEAN
but, I'm still having problems
I have a header file that is called XS.h
which looks like this
#ifndef XS_H
#define XS_H
#include <winsock2.h>
#include <ws2tcpip.h>
#include <Windows.h>
#endif
and I'm including XS.h
in the header Client.h
.
Client.h
include is looks like this :
#ifndef CLIENT_H
#define CLIENT_H
#include "XS.h"
XS.h
is my only include in Client.h
, yet I still get errors (and as you can see, Winsock
is included before windows.h
I'm getting about 78 errors, here are some of them :
Error 90 error C3861: 'WSASetLastError': identifier not found c:\program files (x86)\windows kits\8.0\include\um\ws2tcpip.h 703
Error 61 error C2375: 'WSAStartup' : redefinition; different linkage c:\program files (x86)\windows kits\8.0\include\um\winsock2.h 2296
Error 49 error C2375: 'send' : redefinition; different linkage c:\program files (x86)\windows kits\8.0\include\um\winsock2.h 2026
How can I solve this issue?
Thanks!
Edit: I've tried to use #define _WINSOCKAPI_
as well, though it did not resolve my problems...
I have winsock.h
first, then windows.h
, though it still does the error for me.
#pragma once
in header file – A BClient.h
includes to this :#pragma once #include <winsock2.h> #include <ws2tcpip.h> #include "Chat.h"
though it still doesnt work, same errors.... – Amitwindows.h
before including any other Windows API header. That's because Microsoft headers generally do not include all that they need, i.e. do not follow good programming practice. It's possible to just make<windows.>
a forced include, but that repeats the malpractice that caused the problem: better fix the source. – Cheers and hth. - Alf