Ws2_32.cs 1.1 KB

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.Net.Sockets;
  3. using System.Runtime.InteropServices;
  4. namespace Microsoft.Win32
  5. {
  6. /// <summary>
  7. /// Ws2_32扩展
  8. /// </summary>
  9. public static partial class Util
  10. {
  11. /// <summary>
  12. /// 获取扩展函数指针
  13. /// </summary>
  14. /// <param name="guid">扩展函数标识</param>
  15. /// <param name="type">函数类型</param>
  16. /// <param name="socket">socket 指针</param>
  17. /// <returns>函数指针</returns>
  18. public static Delegate SioGetExtensionFunctionPointer(Guid guid, Type type, IntPtr socket)
  19. {
  20. IntPtr funPointer = IntPtr.Zero;
  21. int byteTransfered = 0;
  22. SocketError nErrorCode = UnsafeNativeMethods.WSAIoctl(socket, NativeMethods.SIO_GET_EXTENSION_FUNCTION_POINTER, ref guid, Marshal.SizeOf(guid), ref funPointer, IntPtr.Size, out byteTransfered, NativeMethods.NULL, NativeMethods.NULL);
  23. if (nErrorCode != SocketError.Success)
  24. throw new SocketException((int)nErrorCode);
  25. return Marshal.GetDelegateForFunctionPointer(funPointer, type);
  26. }
  27. }
  28. }