原型:int PASCAL FAR WSAStartup(WORD wVersionRequested, LPWSADATA lpWSAData );
[DllImport("ws2_32.dll")]
public static extern Int32 WSAStartup(UInt16 wVer, ref WSADATA wsaData);
public struct WSADATA //這樣宣告結構體
{
public short wVersion;
public short wHighVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)]
public string szDescription;
public string szSystemStatus;
[Obsolete]
public int wMaxSockets;
public int wMAXUDPDG;
public IntPtr dwVendorInfo;
}
例項化結構體:
WSADATA wsaData = new WSADATA();
WSAStartup(0x0202, ref wsaData); //注意第二個引數前的ref ,0x202指Socket的版本號
原型:int PASCAL FAR WSAStartup(WORD wVersionRequested, LPWSADATA lpWSAData );
[DllImport("ws2_32.dll")]
public static extern Int32 WSAStartup(UInt16 wVer, ref WSADATA wsaData);
public struct WSADATA //這樣宣告結構體
{
public short wVersion;
public short wHighVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)]
public string szDescription;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)]
public string szSystemStatus;
[Obsolete]
public int wMaxSockets;
[Obsolete]
public int wMAXUDPDG;
public IntPtr dwVendorInfo;
}
例項化結構體:
WSADATA wsaData = new WSADATA();
WSAStartup(0x0202, ref wsaData); //注意第二個引數前的ref ,0x202指Socket的版本號