TONT 34283 为什么会有 WSASetLastError 这个函数?

原文链接:https://devblogs.microsoft.com/oldnewthing/20050908-19/?p=34283

Why does the function WSASetLastError exist when there is already the perfectly good function SetLastError?

为什么在已经有了 SetLastError 这么好的一个函数的情况下,还要再有一个 WSASetLastError 呢?

Actually, you know the answer too, if you sit down and think about it.

实际上,如果坐下来思考一番的话,你也已经知道答案了。

Winsock was originally developed to run on both 16-bit Windows and 32-bit Windows. Notice how the classic Winsock functions are based on window messages for asynchronous notifications. In the 16-bit world, there was no SetLastError function. Therefore, Winsock had to provide its own version for the 16-bit implementation. And since source code compatibility is important, there was a 32-bit version as well. Of course, the 32-bit version looks kind of stupid in retrospect if you aren’t aware of the 16-bit version.

Winsock 原本是设计同时运行在 16 位和 32 位的 Windows 上的,需要注意的是,传统的 Winsock 函数的运行依赖窗口消息来获取异步通知。在 16 位的世界里,并没有 SetLastError 这么个东西,因此,Winsock 需要为 16 位环境提供它自己版本的 SetLastError。同时,由于源代码兼容性是一件很重要的事情,也就有了 32 位的 WSASetLastError。当然了,如果你不了解有 16 位环境下的需求这件事的话,32 位版本下的它看上去就有那么点多余了。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

 剩余字数 ( Characters available )

Your comment will be available after auditing.
您的评论将在通过审核后显示。

Please DO NOT add any links in your comment, otherwise it would be identified as SPAM automatically and never be audited.
请不要在评论中插入任何链接,否则将被自动归类为垃圾评论,且永远不会被提交给博主进行复审。

*