Reputation: 83
I use function pointer
MyWSARecvProc OriginalWSARecvProc = (MyWSARecvProc) WSARecv;
Function WSARecv is declared in winsock2.h:
WINSOCK_API_LINKAGE int WINAPI WSARecv(SOCKET,
LPWSABUF, DWORD, LPDWORD, LPDWORD, LPWSAOVERLAPPED,
LPWSAOVERLAPPED_COMPLETION_ROUTINE);
I include winsock2.h in my file, but there are error:
error: 'WSARecv' was not declared in this scope
Why does it happen? How to fix it? Thanks.
edited
I include winsock2.h before windows.h as Adrian Ratnapala writed. Now I have other errors:
src\netredirect.o:netredirect.cpp:(.data+0x18): undefined reference to `WSARecv@28'
src\netredirect.o:netredirect.cpp:(.data+0x1c): undefined reference to `WSARecvFrom@36'
src\netredirect.o:netredirect.cpp:(.data+0x20): undefined reference to `WSASend@28'
src\netredirect.o:netredirect.cpp:(.data+0x24): undefined reference to `WSASendTo@36'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/lib/libmingw32.a(main.o): In function `main':
e:\p\giaw\src\pkg\mingwrt-4.0.3-1-mingw32-src\bld/../mingwrt-4.0.3-1-mingw32-src/src/libcrt/crt/main.c:91: undefined reference to `WinMain@16'
Upvotes: 0
Views: 1146
Reputation: 119
If to you seem that the function is in the scope,just try to move it like a global function and see what happen.(Don't leave it there,just see if the problem is really because it's out of the scope)
Upvotes: 0
Reputation: 45654
The error message is quite explicit. WSARecv is not known at the point you use it. Either move the function definition before its first use, or add a declaration before its first use.
Upvotes: 1