请注意:本页内容发布于 1497 天前,内容可能已经过时,请注意甄别。
原文链接: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 位版本下的它看上去就有那么点多余了。
远嚣 Comment