Keep looking! Don't settle!

<< C语言的assert() | 首 页 | Visual Assist X 10.3.1535 无限期试用,如此破解也是一种境界! >> <Winsock.h> 和 <Winsock2.h> 冲突 2007-05-07 Tag: Windows 版权声明 :转载时请以超链接形式标明文章原始出处和作者信息及 本声明 http://icejournal.blogbus.com/logs/7021792.html 最近在写DirectShow Source Filter的时候遇到了如下问题:一个对象要使用Windows Sockets API,所以要 #include ,但是编译时出现一大堆恶心的错误。换成 #include 错误消失。 开始不知道为什么,刚才从MSDN Windows Sockets 2.0的文档里找到了原因。问题出在 和 冲突。试试编译如下代码,看是不是出现了一堆莫名其妙的错误。 #include #include int main() { return 0; } http://msdn2.microsoft.com/en-us/library/ms737629.aspx The Winsock2.h header file internally includes core elements from the Windows.h header file, so there is not usually an #include line for the Windows.h header file in Winsock applications. If an #include line is needed for the Windows.h header file, this should be preceded with the #define WIN32_LEAN_AND_MEAN macro. For historical reasons, the Windows.h header defaults to including the Winsock.h header file for Windows Sockets 1.1. The declarations in the Winsock.h header file will conflict with the declarations in the Winsock2.h header file required by Windows Sockets 2.0. 原来包含了;包含了。造成了前面所说的冲突。解决方法如下: The WIN32_LEAN_AND_MEAN macro prevents the Winsock.h from being included by the Windows.h header. #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #include #include int main() { return 0; } 随机文章: 无限延长Visual Assist X的试用期限 2007-05-07 Visual Assist X 10.3.1535 无限期试用,如此破解也是一种境界! 2007-05-07 Visual Studio 2005下通过.def 文件导出自注册DLL必须的函数 2007-05-07 9月10-13日 2007-09-13 forward declaration 2007-03-02 收藏到: Del.icio.us 引用地址: 发表于 12:00 | 编辑 | 继续话题 | 转发 | 推荐 发表评论

原始快照:web.archive.org