简体   繁体   English

WINVER,Winsock和Htonl()

[英]WINVER, winsock and htonl()

When I don't define WINVER, my (msvc9) build is peppered with warnings and it says it is defaulting to 0x0600 (Vista) but it builds OK. 当我不定义WINVER时,我的(msvc9)构建中充满了警告,并说它的默认值为0x0600(Vista),但它构建良好。 When I define WINVER = 0x501 (XP), I get this error :- 当我定义WINVER = 0x501(XP)时,出现此错误:-

error C3861: 'htonl': identifier not found

I'd rather use WINVER=0x0501 than 0x0600 but I don't know how to fix it! 我宁愿使用WINVER = 0x0501而不是0x0600,但我不知道如何解决它!

I noticed something in http://west-chamber-season-2.googlecode.com/svn-history/r2/trunk/wcs2_cli.c 我在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

Do I need to do something odd like this? 我需要做一些奇怪的事情吗? Any ideas? 有任何想法吗?

If you are compiling for windows then #include winsock2.h and ws2tcpip.h and link to ws2_32.lib. 如果要针对Windows进行编译,则#include winsock2.h和ws2tcpip.h并链接到ws2_32.lib。 Also ensure you call WSAStartup before you try any networking functions. 在尝试任何网络功能之前,还请确保先致电WSAStartup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM