c# - 如何获取最后一个错误(WSAGetLastError)?

标签 c# .net winapi error-handling pinvoke

如何从 WinAPI 调用 WSAGetLastError() 以便获得有效的文本错误?

最佳答案

[DllImport("ws2_32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern Int32 WSAGetLastError();

此外,关于 pinvoke.net据说:

You should never PInvoke to GetLastError. Call Marshal.GetLastWin32Error instead!

System.Runtime.InteropServices.Marshal.GetLastWin32Error()

关于c# - 如何获取最后一个错误(WSAGetLastError)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/765491/

相关文章:

c# - 如何避免 MySql/net 连接器中的 "There is already an open DataReader associated with this Connection which must be closed first."?

c# - 读取 xml 子树和后代 C#

c# - 如何在 XPS 文档中设置权限?

c# - 在 Windows Docker 容器中设置语言和区域设置

c++ - WinAPI - 如何组织大量的 HWND 对象?

Delphi删除文件-显示消息文件正忙

c# - 用于将IQueryable <T>和IEnumerable <T>转换为ReadOnlyCollection <T>的扩展方法

c# - 通用节点的通用树 C#

c# - 托管 ASP.NET MVC 应用程序 : Security Exception

c++ - 未调用 dll Hook 函数