WINVER,winsock和htonl()
当我没有定义WINVER时,我的(msvc9)版本充满了警告,它表示它默认为0x0600(Vista),但它构建成OK。当我定义WINVER = 0x501(XP),我得到这个错误: -WINVER,winsock和htonl()
error C3861: 'htonl': identifier not found
我宁愿使用WINVER = 0x0501比为0x0600,但我不知道如何解决它!
我注意到http://west-chamber-season-2.googlecode.com/svn-history/r2/trunk/wcs2_cli.c
#ifdef WINVER
#include <winsock.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
我需要做一些奇怪的是这样的东西吗?有任何想法吗?
如果您正在为Windows编译,那么#include winsock2.h和ws2tcpip.h并链接到ws2_32.lib。在尝试任何联网功能之前,请确保您拨打WSAStartup
。
我不是100%确定,但这看起来很有趣。 如果_WIN32_WINNT被定义为等于WINVER,那么这将解释我的问题。 C:\ Program Files文件\微软的Visual Studio 9.0 \ VC \ atlmfc \包括\ afxwin.h '#如果(_WIN32_WINNT> = 0x600) 的#ifndef _WINSOCK2API_ 的#ifdef _WINSOCKAPI_ \t #ERROR MFC需要使用的Winsock2的.h #endif \t #include
看起来像htonl在\t'Winsock2.h',你有没有试图包括它? – CharlesB