using System;
using System.Net.Sockets;
using System.Runtime.InteropServices;
namespace Microsoft.Win32
{
///
/// Ws2_32扩展
///
public static partial class Util
{
///
/// 获取扩展函数指针
///
/// 扩展函数标识
/// 函数类型
/// socket 指针
/// 函数指针
public static Delegate SioGetExtensionFunctionPointer(Guid guid, Type type, IntPtr socket)
{
IntPtr funPointer = IntPtr.Zero;
int byteTransfered = 0;
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);
if (nErrorCode != SocketError.Success)
throw new SocketException((int)nErrorCode);
return Marshal.GetDelegateForFunctionPointer(funPointer, type);
}
}
}