我可以同时使用Winsock.h和Winsock2.h [英] Can I use both Winsock.h and Winsock2.h

查看:125
本文介绍了我可以同时使用Winsock.h和Winsock2.h的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在同一应用程序中同时使用winsock.h和winsock2.h吗?还是不好?请不要删除它.宁可回答这个问题,要成为好人也要花很多精力. (即使您认为这是一个愚蠢的问题)是或否也会做得很好!

Can I use both winsock.h and winsock2.h in same app? Or is that not good? Please don''t delete this. Rather answer the question, it takes just as much energy to be nice as it does to be mean. (Even if you think it''a a stupid question) Yes or No would do nicely!

推荐答案

如果您查看winsock2.h,您会发现它包括windows.h.
如果您在windows.h中查看,则可以看到它包含winsock.h.
但是winsock2.h通过定义_WINSOCKAPI_来确保winsock.h的内容均无效.
这是来自winsock2.h的行-
If you look inside winsock2.h, you can see that it includes windows.h.
And if you look inside windows.h, you can see that it includes winsock.h.
But winsock2.h makes sure that none of the contents of winsock.h are valid by defining _WINSOCKAPI_.

Here is the line from winsock2.h -
#define _WINSOCKAPI_   /* Prevent inclusion of winsock.h in windows.h */


如果您查看winsock.h,其所有内容均与这些陈述有关-


And if you look inside winsock.h, all its contents are with these statments -

#ifndef _WINSOCKAPI_

#endif


因此,简而言之,您不能同时使用它们.


So in short, you must not use both together.


您可以,但这只会引起问题;使用一个或另一个.
You can but it will just cause problems; use one or the other.


这篇关于我可以同时使用Winsock.h和Winsock2.h的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆