{"id":3186,"date":"2020-10-20T09:58:36","date_gmt":"2020-10-20T01:58:36","guid":{"rendered":"https:\/\/www.aoisnow.net\/blog\/?p=3186"},"modified":"2020-10-20T09:58:36","modified_gmt":"2020-10-20T01:58:36","slug":"tont-34283-%e4%b8%ba%e4%bb%80%e4%b9%88%e4%bc%9a%e6%9c%89-wsasetlasterror-%e8%bf%99%e4%b8%aa%e5%87%bd%e6%95%b0%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.aoisnow.net\/blog\/archives\/3186","title":{"rendered":"TONT 34283 \u4e3a\u4ec0\u4e48\u4f1a\u6709 WSASetLastError \u8fd9\u4e2a\u51fd\u6570\uff1f"},"content":{"rendered":"<p>\u539f\u6587\u94fe\u63a5\uff1a<a href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050908-19\/?p=34283\" target=\"_blank\" rel=\"noopener\">https:\/\/devblogs.microsoft.com\/oldnewthing\/20050908-19\/?p=34283<\/a><\/p>\n<p>Why does the function WSASetLastError exist when there is already the perfectly good function SetLastError?<\/p>\n<p>\u4e3a\u4ec0\u4e48\u5728\u5df2\u7ecf\u6709\u4e86 SetLastError \u8fd9\u4e48\u597d\u7684\u4e00\u4e2a\u51fd\u6570\u7684\u60c5\u51b5\u4e0b\uff0c\u8fd8\u8981\u518d\u6709\u4e00\u4e2a\u00a0WSASetLastError \u5462\uff1f<\/p>\n<p>Actually, you know the answer too, if you sit down and think about it.<\/p>\n<p>\u5b9e\u9645\u4e0a\uff0c\u5982\u679c\u5750\u4e0b\u6765\u601d\u8003\u4e00\u756a\u7684\u8bdd\uff0c\u4f60\u4e5f\u5df2\u7ecf\u77e5\u9053\u7b54\u6848\u4e86\u3002<\/p>\n<p>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\u2019t aware of the 16-bit version.<\/p>\n<p>Winsock \u539f\u672c\u662f\u8bbe\u8ba1\u540c\u65f6\u8fd0\u884c\u5728 16 \u4f4d\u548c 32 \u4f4d\u7684 Windows \u4e0a\u7684\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4f20\u7edf\u7684 Winsock \u51fd\u6570\u7684\u8fd0\u884c\u4f9d\u8d56\u7a97\u53e3\u6d88\u606f\u6765\u83b7\u53d6\u5f02\u6b65\u901a\u77e5\u3002\u5728 16 \u4f4d\u7684\u4e16\u754c\u91cc\uff0c\u5e76\u6ca1\u6709 SetLastError \u8fd9\u4e48\u4e2a\u4e1c\u897f\uff0c\u56e0\u6b64\uff0cWinsock \u9700\u8981\u4e3a 16 \u4f4d\u73af\u5883\u63d0\u4f9b\u5b83\u81ea\u5df1\u7248\u672c\u7684 SetLastError\u3002\u540c\u65f6\uff0c\u7531\u4e8e\u6e90\u4ee3\u7801\u517c\u5bb9\u6027\u662f\u4e00\u4ef6\u5f88\u91cd\u8981\u7684\u4e8b\u60c5\uff0c\u4e5f\u5c31\u6709\u4e86 32 \u4f4d\u7684 WSASetLastError\u3002\u5f53\u7136\u4e86\uff0c\u5982\u679c\u4f60\u4e0d\u4e86\u89e3\u6709 16 \u4f4d\u73af\u5883\u4e0b\u7684\u9700\u6c42\u8fd9\u4ef6\u4e8b\u7684\u8bdd\uff0c32 \u4f4d\u7248\u672c\u4e0b\u7684\u5b83\u770b\u4e0a\u53bb\u5c31\u6709\u90a3\u4e48\u70b9\u591a\u4f59\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u539f\u6587\u94fe\u63a5\uff1ahttps:\/\/devblogs.microsoft.com\/oldnewthing\/2005090 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-3186","post","type-post","status-publish","format-standard","hentry","category-tont_history"],"_links":{"self":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/3186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/comments?post=3186"}],"version-history":[{"count":0,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/posts\/3186\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/media?parent=3186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/categories?post=3186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.aoisnow.net\/blog\/wp-json\/wp\/v2\/tags?post=3186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}