From ea1c63e76e42c36e41d7a23cc9245f79727c7e10 Mon Sep 17 00:00:00 2001 From: dahall Date: Sun, 10 Jul 2022 20:41:21 -0600 Subject: [PATCH] Converted winsock return values to SocketError --- PInvoke/Ws2_32/WinSock2.WSA.Struct.cs | 1 + PInvoke/Ws2_32/WinSock2.WSA.cs | 98 +++++------------------------------ PInvoke/Ws2_32/WinSock2.legacy.cs | 39 +++++++------- PInvoke/Ws2_32/ws2spi.cs | 71 ++++++++++++------------- PInvoke/Ws2_32/ws2tcpip.cs | 49 +++++++++--------- 5 files changed, 95 insertions(+), 163 deletions(-) diff --git a/PInvoke/Ws2_32/WinSock2.WSA.Struct.cs b/PInvoke/Ws2_32/WinSock2.WSA.Struct.cs index 4051d953..95783cdc 100644 --- a/PInvoke/Ws2_32/WinSock2.WSA.Struct.cs +++ b/PInvoke/Ws2_32/WinSock2.WSA.Struct.cs @@ -3,6 +3,7 @@ using System; using System.Data; using System.Runtime.InteropServices; +using Vanara.Extensions; using Vanara.InteropServices; namespace Vanara.PInvoke diff --git a/PInvoke/Ws2_32/WinSock2.WSA.cs b/PInvoke/Ws2_32/WinSock2.WSA.cs index 1e9d1401..249c3070 100644 --- a/PInvoke/Ws2_32/WinSock2.WSA.cs +++ b/PInvoke/Ws2_32/WinSock2.WSA.cs @@ -1,6 +1,4 @@ -#pragma warning disable IDE1006 // Naming Styles - -using System; +using System; using System.Data; using System.Net.Sockets; using System.Runtime.InteropServices; @@ -422,44 +420,7 @@ namespace Vanara.PInvoke /// A pointer to the WSAPROTOCOL_INFO structure for a particular provider. If this is parameter is NULL, the call is routed /// to the provider of the first protocol supporting the address family indicated in the lpsaAddress parameter. /// - /// The human-readable address string. - /// - /// - /// If no error occurs, WSAAddressToString returns a value of zero. Otherwise, the value SOCKET_ERROR is returned, and a - /// specific error number can be retrieved by calling WSAGetLastError. - /// - /// - /// - /// Error code - /// Meaning - /// - /// - /// WSAEFAULT - /// - /// The specified lpcsAddress, lpProtocolInfo, and lpszAddressString parameters point to memory that is not all in the address space - /// of the process, or the buffer pointed to by the lpszAddressString parameter is too small. Pass in a larger buffer. - /// - /// - /// - /// WSAEINVAL - /// - /// An invalid parameter was passed. This error is returned if the lpsaAddress, dwAddressLength, or lpdwAddressStringLength - /// parameter are NULL. This error is also returned if the specified address is not a valid socket address, or no transport provider - /// supports the indicated address family. - /// - /// - /// - /// WSAENOBUFS - /// No buffer space is available. - /// - /// - /// WSANOTINITIALISED - /// - /// The Winsock 2 DLL has not been initialized. The application must first call WSAStartup before calling any Windows Sockets functions. - /// - /// - /// - /// + /// The human-readable address string. /// /// /// The WSAAddressToString function provides a protocol-independent address-to-string translation. The @@ -506,7 +467,7 @@ namespace Vanara.PInvoke err = WSAAddressToString(lpsaAddress, (uint)lpsaAddress.Size, pc, sb, ref sz); if (err == 0) return sb.ToString(); } - err.ThrowIfFailed(); + throw err.GetException(); } /// @@ -4641,17 +4602,17 @@ namespace Vanara.PInvoke // dwIoControlCode, LPVOID lpvInBuffer, DWORD cbInBuffer, LPVOID lpvOutBuffer, DWORD cbOutBuffer, LPDWORD lpcbBytesReturned, // LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine ); [PInvokeData("winsock2.h", MSDNShortId = "038aeca6-d7b7-4f74-ac69-4536c2e5118b")] - public static Win32Error WSAIoctl(SOCKET s, uint dwIoControlCode, TIn inVal, out TOut outVal) where TIn : struct where TOut : struct + public static SocketError WSAIoctl(SOCKET s, uint dwIoControlCode, TIn inVal, out TOut outVal) where TIn : struct where TOut : struct { using SafeHGlobalHandle ptrIn = SafeHGlobalHandle.CreateFromStructure(inVal), ptrOut = SafeHGlobalHandle.CreateFromStructure(); var ret = WSAIoctl(s, dwIoControlCode, ptrIn, ptrIn.Size, ptrOut, ptrOut.Size, out var bRet); - if (ret == SOCKET_ERROR) + if (ret == SocketError.SocketError) { outVal = default; return WSAGetLastError(); } outVal = ptrOut.ToStructure(); - return Win32Error.ERROR_SUCCESS; + return SocketError.Success; } /// @@ -8074,7 +8035,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-wsasetlasterror void WSASetLastError( int iError ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "596155ee-3dcc-4ae3-97ab-0653e019cbee")] - public static extern void WSASetLastError(int iError); + public static extern void WSASetLastError(SocketError iError); /// The WSASetService function registers or removes from the registry a service instance within one or more namespaces. /// A pointer to the service information for registration or deregistration. @@ -9981,39 +9942,7 @@ namespace Vanara.PInvoke /// The WSAPROTOCOL_INFO structure associated with the provider to be used. If this is NULL, the call is routed to the /// provider of the first protocol supporting the indicated AddressFamily. /// - /// - /// A pointer to a buffer that is filled with a sockaddr structure for the address string if the function succeeds. - /// - /// - /// - /// The return value for WSAStringToAddress is zero if the operation was successful. Otherwise, the value SOCKET_ERROR is - /// returned, and a specific error number can be retrieved by calling WSAGetLastError. - /// - /// - /// - /// Error code - /// Meaning - /// - /// - /// WSAEFAULT - /// The buffer pointed to by the lpAddress parameter is too small. Pass in a larger buffer. - /// - /// - /// WSAEINVAL - /// The functions was unable to translate the string into a sockaddr. See the following Remarks section for more information. - /// - /// - /// WSANOTINITIALISED - /// - /// The WS2_32.DLL has not been initialized. The application must first call WSAStartup before calling any Windows Socket functions. - /// - /// - /// - /// WSA_NOT_ENOUGH_MEMORY - /// There was insufficient memory to perform the operation. - /// - /// - /// + /// A sockaddr structure for the address string if the function succeeds. /// /// /// The WSAStringToAddress function converts a network address in standard text form into its numeric binary form in a @@ -10021,8 +9950,8 @@ namespace Vanara.PInvoke /// /// /// Any missing components of the address will be defaulted to a reasonable value, if possible. For example, a missing port number - /// will default to zero. If the caller wants the translation to be done by a particular provider, it should supply the - /// corresponding WSAPROTOCOL_INFO structure in the lpProtocolInfo parameter. + /// will default to zero. If the caller wants the translation to be done by a particular provider, it should supply the corresponding + /// WSAPROTOCOL_INFO structure in the lpProtocolInfo parameter. /// /// /// The WSAStringToAddress function fails (and returns WSAEINVAL) if the sin_family member of the SOCKADDR_IN @@ -10041,14 +9970,13 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsastringtoaddressa INT WSAAPI WSAStringToAddressA( LPSTR // AddressString, INT AddressFamily, LPWSAPROTOCOL_INFOA lpProtocolInfo, LPSOCKADDR lpAddress, LPINT lpAddressLength ); [PInvokeData("winsock2.h", MSDNShortId = "7b9946c3-c8b3-45ae-9bde-03faaf604bba")] - public static Win32Error WSAStringToAddress(string AddressString, ADDRESS_FAMILY AddressFamily, [In, Optional] WSAPROTOCOL_INFO? lpProtocolInfo, out SOCKADDR_INET lpAddress) + public static SOCKADDR_INET WSAStringToAddress(string AddressString, ADDRESS_FAMILY AddressFamily, [In, Optional] WSAPROTOCOL_INFO? lpProtocolInfo) { using var pc = lpProtocolInfo.HasValue ? new SafeCoTaskMemStruct(lpProtocolInfo.Value) : SafeCoTaskMemStruct.Null; using var addr = new SafeCoTaskMemStruct(); int sz = addr.Size; - var err = WSAStringToAddress(AddressString, AddressFamily, pc, addr, ref sz); - lpAddress = addr.Value; - return err == SOCKET_ERROR ? WSAGetLastError() : Win32Error.ERROR_SUCCESS; + WSAStringToAddress(AddressString, AddressFamily, pc, addr, ref sz).ThrowIfFailed(); + return addr.Value; } /// diff --git a/PInvoke/Ws2_32/WinSock2.legacy.cs b/PInvoke/Ws2_32/WinSock2.legacy.cs index e4e49c29..72e08f63 100644 --- a/PInvoke/Ws2_32/WinSock2.legacy.cs +++ b/PInvoke/Ws2_32/WinSock2.legacy.cs @@ -2,6 +2,7 @@ using System; using System.Linq; +using System.Net.Sockets; using System.Runtime.InteropServices; using System.Text; using Vanara.Extensions; @@ -516,7 +517,7 @@ namespace Vanara.PInvoke // namelen ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "3a651daa-7404-4ef7-8cff-0d3dff41a8e8")] - public static extern int bind(SOCKET s, [In] SOCKADDR addr, int namelen); + public static extern SocketError bind(SOCKET s, [In] SOCKADDR addr, int namelen); /// The closesocket function closes an existing socket. /// A descriptor identifying the socket to close. @@ -786,7 +787,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-closesocket int closesocket( IN SOCKET s ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "2f357aa8-389b-4c92-8a9f-289e048cc41c")] - public static extern int closesocket([In] SOCKET s); + public static extern SocketError closesocket([In] SOCKET s); /// The connect function establishes a connection to a specified socket. /// A descriptor identifying an unconnected socket. @@ -1017,7 +1018,7 @@ namespace Vanara.PInvoke // *name, int namelen ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "13468139-dc03-45bd-850c-7ac2dbcb6e60")] - public static extern int connect(SOCKET s, SOCKADDR name, int namelen); + public static extern SocketError connect(SOCKET s, SOCKADDR name, int namelen); /// The gethostname function retrieves the standard host name for the local computer. /// A pointer to a buffer that receives the local host name. @@ -1089,7 +1090,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-gethostname int gethostname( char *name, int namelen ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Ansi)] [PInvokeData("winsock.h", MSDNShortId = "8fa40b60-0e93-493b-aee1-cea6cf595707")] - public static extern int gethostname(StringBuilder name, int namelen); + public static extern SocketError gethostname(StringBuilder name, int namelen); /// The GetHostNameW function retrieves the standard host name for the local computer as a Unicode string. /// A pointer to a buffer that receives the local host name as a null-terminated Unicode string. @@ -1165,7 +1166,7 @@ namespace Vanara.PInvoke // namelen ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("winsock2.h", MSDNShortId = "787EB209-5944-4F0A-8550-FE1115C2298A")] - public static extern int GetHostNameW(StringBuilder name, int namelen); + public static extern SocketError GetHostNameW(StringBuilder name, int namelen); /// The getpeername function retrieves the address of the peer to which a socket is connected. /// A descriptor identifying a connected socket. @@ -1231,7 +1232,7 @@ namespace Vanara.PInvoke // *namelen ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "df2679a5-cdd9-468b-823a-f98044189f65")] - public static extern int getpeername(SOCKET s, SOCKADDR name, ref int namelen); + public static extern SocketError getpeername(SOCKET s, SOCKADDR name, ref int namelen); /// The getprotobyname function retrieves the protocol information corresponding to a protocol name. /// Pointer to a null-terminated protocol name. @@ -1721,7 +1722,7 @@ namespace Vanara.PInvoke // int *namelen ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "be20a731-cdfc-48ae-90b2-43f2cf9ecf6d")] - public static extern int getsockname(SOCKET s, SOCKADDR name, ref int namelen); + public static extern SocketError getsockname(SOCKET s, SOCKADDR name, ref int namelen); /// The getsockopt function retrieves a socket option. /// A descriptor identifying a socket. @@ -2156,7 +2157,7 @@ namespace Vanara.PInvoke // optname, char *optval, int *optlen ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Ansi)] [PInvokeData("winsock.h", MSDNShortId = "25bc511d-7a9f-41c1-8983-1af1e3f8bf2d")] - public static extern int getsockopt(SOCKET s, int level, int optname, [Optional] IntPtr optval, ref int optlen); + public static extern SocketError getsockopt(SOCKET s, int level, int optname, [Optional] IntPtr optval, ref int optlen); /// The htonl function converts a u_long from host to TCP/IP network byte order (which is big-endian). /// A 32-bit number in host byte order. @@ -2420,7 +2421,7 @@ namespace Vanara.PInvoke // *argp ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "048fcb8d-acd3-4917-a997-dd133db399f8")] - public static extern int ioctlsocket(SOCKET s, int cmd, IntPtr argp); + public static extern SocketError ioctlsocket(SOCKET s, int cmd, IntPtr argp); /// The listen function places a socket in a state in which it is listening for an incoming connection. /// A descriptor identifying a bound, unconnected socket. @@ -2554,7 +2555,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/desktop/api/winsock2/nf-winsock2-listen int WSAAPI listen( SOCKET s, int backlog ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "1233feeb-a8c1-49ac-ab34-82af224ecf00")] - public static extern int listen(SOCKET s, int backlog); + public static extern SocketError listen(SOCKET s, int backlog); /// /// The ntohl function converts a u_long from TCP/IP network order to host byte order (which is little-endian on Intel processors). @@ -2817,7 +2818,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-recv int recv( SOCKET s, char *buf, int len, int flags ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "8c247cd3-479f-45d0-a038-a24e80cc7c73")] - public static extern int recv(SOCKET s, IntPtr buf, int len, MsgFlags flags); + public static extern SocketError recv(SOCKET s, IntPtr buf, int len, MsgFlags flags); /// The recvfrom function receives a datagram and stores the source address. /// A descriptor identifying a bound socket. @@ -3000,7 +3001,7 @@ namespace Vanara.PInvoke // flags, sockaddr *from, int *fromlen ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "3e4282e0-3ed0-43e7-9b27-72ec36b9cfa1")] - public static extern int recvfrom(SOCKET s, IntPtr buf, int len, int flags, SOCKADDR from, ref int fromlen); + public static extern SocketError recvfrom(SOCKET s, IntPtr buf, int len, int flags, SOCKADDR from, ref int fromlen); /// /// The select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O. @@ -3181,7 +3182,7 @@ namespace Vanara.PInvoke // fd_set *writefds, fd_set *exceptfds, const timeval *timeout ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "NF:winsock2.select")] - public static extern int select([Optional] int nfds, ref fd_set readfds, ref fd_set writefds, ref fd_set exceptfds, in TIMEVAL timeout); + public static extern SocketError select([Optional] int nfds, ref fd_set readfds, ref fd_set writefds, ref fd_set exceptfds, in TIMEVAL timeout); /// /// The select function determines the status of one or more sockets, waiting if necessary, to perform synchronous I/O. @@ -3362,7 +3363,7 @@ namespace Vanara.PInvoke // fd_set *writefds, fd_set *exceptfds, const timeval *timeout ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "NF:winsock2.select")] - public static extern int select([Optional] int nfds, [In, Out, Optional] IntPtr readfds, [In, Out, Optional] IntPtr writefds, [In, Out, Optional] IntPtr exceptfds, [In, Optional] IntPtr timeout); + public static extern SocketError select([Optional] int nfds, [In, Out, Optional] IntPtr readfds, [In, Out, Optional] IntPtr writefds, [In, Out, Optional] IntPtr exceptfds, [In, Optional] IntPtr timeout); /// The send function sends data on a connected socket. /// A descriptor identifying a connected socket. @@ -3558,7 +3559,7 @@ namespace Vanara.PInvoke // int flags ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "902bb9cf-d847-43fc-8282-394d619b8f1b")] - public static extern int send(SOCKET s, IntPtr buf, int len, int flags); + public static extern SocketError send(SOCKET s, IntPtr buf, int len, int flags); /// The sendto function sends data to a specific destination. /// A descriptor identifying a (possibly connected) socket. @@ -3791,7 +3792,7 @@ namespace Vanara.PInvoke // flags, const sockaddr *to, int tolen ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "a1c89c6b-d11d-4d3e-a664-af2beed0cd09")] - public static extern int sendto(SOCKET s, IntPtr buf, int len, int flags, SOCKADDR to, int tolen); + public static extern SocketError sendto(SOCKET s, IntPtr buf, int len, int flags, SOCKADDR to, int tolen); /// The setsockopt function sets a socket option. /// A descriptor that identifies a socket. @@ -4145,7 +4146,7 @@ namespace Vanara.PInvoke // optname, const char *optval, int optlen ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "3a6960c9-0c04-4403-aee1-ce250459dc30")] - public static extern int setsockopt(SOCKET s, int level, int optname, IntPtr optval, int optlen); + public static extern SocketError setsockopt(SOCKET s, int level, int optname, IntPtr optval, int optlen); /// The setsockopt function sets a socket option. /// A descriptor that identifies a socket. @@ -4497,7 +4498,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-setsockopt int setsockopt( SOCKET s, int level, int // optname, const char *optval, int optlen ); [PInvokeData("winsock.h", MSDNShortId = "3a6960c9-0c04-4403-aee1-ce250459dc30")] - public static int setsockopt(SOCKET s, TLvl level, int optname, in TIn optval) where TIn : struct where TLvl : IConvertible + public static SocketError setsockopt(SOCKET s, TLvl level, int optname, in TIn optval) where TIn : struct where TLvl : IConvertible { using var mem = SafeCoTaskMemHandle.CreateFromStructure(optval); return setsockopt(s, level.ToInt32(null), optname, mem, mem.Size); @@ -4685,7 +4686,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-shutdown int shutdown( SOCKET s, int how ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "6998f0c6-adc9-481f-b9fb-75f9c9f5caaf")] - public static extern int shutdown(SOCKET s, SD how); + public static extern SocketError shutdown(SOCKET s, SD how); /// The socket function creates a socket that is bound to a specific transport service provider. /// diff --git a/PInvoke/Ws2_32/ws2spi.cs b/PInvoke/Ws2_32/ws2spi.cs index 042a44ac..93016dcf 100644 --- a/PInvoke/Ws2_32/ws2spi.cs +++ b/PInvoke/Ws2_32/ws2spi.cs @@ -1,4 +1,5 @@ using System; +using System.Net.Sockets; using System.Runtime.InteropServices; using System.Text; using Vanara.InteropServices; @@ -83,7 +84,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nc-ws2spi-lpnspv2cleanup LPNSPV2CLEANUP Lpnspv2cleanup; INT // Lpnspv2cleanup( LPGUID lpProviderId, LPVOID pvClientSessionArg ) {...} [PInvokeData("ws2spi.h", MSDNShortId = "36064c0e-c83c-4819-a3e4-c89df50eb659")] - public delegate int LPNSPV2CLEANUP(in Guid lpProviderId, IntPtr pvClientSessionArg); + public delegate SocketError LPNSPV2CLEANUP(in Guid lpProviderId, IntPtr pvClientSessionArg); /// /// The NSPv2ClientSessionRundown function notifies a namespace service provider version-2 (NSPv2) provider that the client @@ -444,7 +445,7 @@ namespace Vanara.PInvoke // dwControlFlags, LPVOID lpvClientSessionArg, LPHANDLE lphLookup ) {...} [PInvokeData("ws2spi.h", MSDNShortId = "5664b85d-8432-4068-aa97-caa57d9377ac")] [UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Unicode)] - public delegate int LPNSPV2LOOKUPSERVICEBEGIN(in Guid lpProviderId, in WSAQUERYSET2W lpqsRestrictions, uint dwControlFlags, IntPtr lpvClientSessionArg, out HANDLE lphLookup); + public delegate SocketError LPNSPV2LOOKUPSERVICEBEGIN(in Guid lpProviderId, in WSAQUERYSET2W lpqsRestrictions, uint dwControlFlags, IntPtr lpvClientSessionArg, out HANDLE lphLookup); /// /// The NSPv2LookupServiceEnd function is called to free the handle after previous calls to NSPv2LookupServiceBegin and NSPv2LookupServiceNextEx. @@ -493,7 +494,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nc-ws2spi-lpnspv2lookupserviceend LPNSPV2LOOKUPSERVICEEND // Lpnspv2lookupserviceend; INT Lpnspv2lookupserviceend( HANDLE hLookup ) {...} [PInvokeData("ws2spi.h", MSDNShortId = "5f2b56c5-3a8e-4bf9-8f28-d2a06543227b")] - public delegate int LPNSPV2LOOKUPSERVICEEND(HANDLE hLookup); + public delegate SocketError LPNSPV2LOOKUPSERVICEEND(HANDLE hLookup); /// /// The NSPv2LookupServiceNextEx function is called after obtaining a handle from a previous call to NSPv2LookupServiceBegin @@ -1045,7 +1046,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nc-ws2spi-lpnspv2startup LPNSPV2STARTUP Lpnspv2startup; INT // Lpnspv2startup( LPGUID lpProviderId, LPVOID *ppvClientSessionArg ) {...} [PInvokeData("ws2spi.h", MSDNShortId = "93224e66-9c94-4b5c-af11-ae988b74bc03")] - public delegate int LPNSPV2STARTUP(in Guid lpProviderId, out IntPtr ppvClientSessionArg); + public delegate SocketError LPNSPV2STARTUP(in Guid lpProviderId, out IntPtr ppvClientSessionArg); /// The WSC_PROVIDER_AUDIT_INFO structure is not currently used. /// The WSC_PROVIDER_AUDIT_INFO structure is not currently used. @@ -1169,7 +1170,7 @@ namespace Vanara.PInvoke // WPUCompleteOverlappedRequest( SOCKET s, LPWSAOVERLAPPED lpOverlapped, DWORD dwError, DWORD cbTransferred, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "b0e5015f-d23f-46da-91b1-f646111f70f9")] - public static extern int WPUCompleteOverlappedRequest(SOCKET s, ref WSAOVERLAPPED lpOverlapped, uint dwError, uint cbTransferred, out int lpErrno); + public static extern SocketError WPUCompleteOverlappedRequest(SOCKET s, ref WSAOVERLAPPED lpOverlapped, uint dwError, uint cbTransferred, out int lpErrno); /// /// The WSAAdvertiseProvider function makes a specific namespace version-2 provider available for all eligible clients. @@ -1261,7 +1262,7 @@ namespace Vanara.PInvoke // GUID *puuidProviderId, const LPCNSPV2_ROUTINE pNSPv2Routine ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "574ebfa4-d7f2-43c2-b1ec-35ce3db9151f")] - public static extern int WSAAdvertiseProvider(in Guid puuidProviderId, in NSPV2_ROUTINE pNSPv2Routine); + public static extern SocketError WSAAdvertiseProvider(in Guid puuidProviderId, in NSPV2_ROUTINE pNSPv2Routine); /// /// The WSAProviderCompleteAsyncCall function notifies a client when an asynchronous call to a namespace version-2 provider @@ -1325,7 +1326,7 @@ namespace Vanara.PInvoke // WSAProviderCompleteAsyncCall( HANDLE hAsyncCall, INT iRetCode ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "2bbc20ae-ad6d-47f6-8ca9-dd5559236fbe")] - public static extern int WSAProviderCompleteAsyncCall(HANDLE hAsyncCall, int iRetCode); + public static extern SocketError WSAProviderCompleteAsyncCall(HANDLE hAsyncCall, int iRetCode); /// /// The WSAUnadvertiseProvider function makes a specific namespace version-2 provider no longer available for clients. @@ -1367,7 +1368,7 @@ namespace Vanara.PInvoke // const GUID *puuidProviderId ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "5975b496-53a7-4f8a-8efc-27ef447596c2")] - public static extern int WSAUnadvertiseProvider(in Guid puuidProviderId); + public static extern SocketError WSAUnadvertiseProvider(in Guid puuidProviderId); /// /// The WSCDeinstallProvider function removes the specified transport provider from the system configuration database. @@ -1441,7 +1442,7 @@ namespace Vanara.PInvoke // lpProviderId, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "9a2afd11-1944-491f-9c92-9dbac6b3b28e")] - public static extern int WSCDeinstallProvider(in Guid lpProviderId, out int lpErrno); + public static extern SocketError WSCDeinstallProvider(in Guid lpProviderId, out int lpErrno); /// /// The WSCDeinstallProvider32 function removes the specified 32-bit transport provider from the system configuration database. @@ -1521,7 +1522,7 @@ namespace Vanara.PInvoke // lpProviderId, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "3de74059-dbfb-49b9-830b-7b2f81f8b68c")] - public static extern int WSCDeinstallProvider32(in Guid lpProviderId, out int lpErrno); + public static extern SocketError WSCDeinstallProvider32(in Guid lpProviderId, out int lpErrno); /// /// The WSCEnableNSProvider function changes the state of a given namespace provider. It is intended to give the end-user the @@ -1590,7 +1591,7 @@ namespace Vanara.PInvoke // lpProviderId, BOOL fEnable ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "2dff5af6-3011-4e3f-b812-fffaca8fa2d9")] - public static extern int WSCEnableNSProvider(in Guid lpProviderId, [MarshalAs(UnmanagedType.Bool)] bool fEnable); + public static extern SocketError WSCEnableNSProvider(in Guid lpProviderId, [MarshalAs(UnmanagedType.Bool)] bool fEnable); /// /// The WSCEnableNSProvider32 function enables or disables a specified 32-bit namespace provider. It is intended to give the @@ -1665,7 +1666,7 @@ namespace Vanara.PInvoke // lpProviderId, BOOL fEnable ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "5ab4f8bd-d32d-4962-aac7-2d92847d0e03")] - public static extern int WSCEnableNSProvider32(in Guid lpProviderId, [MarshalAs(UnmanagedType.Bool)] bool fEnable); + public static extern SocketError WSCEnableNSProvider32(in Guid lpProviderId, [MarshalAs(UnmanagedType.Bool)] bool fEnable); /// The WSCEnumNameSpaceProviders32 function returns information on available 32-bit namespace providers. /// @@ -1725,7 +1726,7 @@ namespace Vanara.PInvoke // WSCEnumNameSpaceProviders32( LPDWORD lpdwBufferLength, LPWSANAMESPACE_INFOW lpnspBuffer ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("ws2spi.h", MSDNShortId = "792737d9-231d-4524-b1a6-b9904951d5b4")] - public static extern int WSCEnumNameSpaceProviders32(ref uint lpdwBufferLength, [In, Out] IntPtr lpnspBuffer); + public static extern SocketError WSCEnumNameSpaceProviders32(ref uint lpdwBufferLength, [In, Out] IntPtr lpnspBuffer); /// The WSCEnumNameSpaceProvidersEx32 function retrieves information on available 32-bit namespace providers. /// @@ -1794,7 +1795,7 @@ namespace Vanara.PInvoke // WSCEnumNameSpaceProvidersEx32( LPDWORD lpdwBufferLength, LPWSANAMESPACE_INFOEXW lpnspBuffer ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("ws2spi.h", MSDNShortId = "544120b2-7575-4deb-8429-2bd4582eceef")] - public static extern int WSCEnumNameSpaceProvidersEx32(ref uint lpdwBufferLength, [In, Out] IntPtr lpnspBuffer); + public static extern SocketError WSCEnumNameSpaceProvidersEx32(ref uint lpdwBufferLength, [In, Out] IntPtr lpnspBuffer); /// The WSCEnumProtocols function retrieves information about available transport protocols. /// @@ -1875,7 +1876,7 @@ namespace Vanara.PInvoke // LPWSAPROTOCOL_INFOW lpProtocolBuffer, LPDWORD lpdwBufferLength, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("ws2spi.h", MSDNShortId = "c2e5332f-3327-4624-96b4-8e321795961d")] - public static extern int WSCEnumProtocols([Optional, MarshalAs(UnmanagedType.LPArray)] int[] lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength, out int lpErrno); + public static extern SocketError WSCEnumProtocols([Optional, MarshalAs(UnmanagedType.LPArray)] int[] lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength, out int lpErrno); /// The WSCEnumProtocols32 function retrieves information about available transport protocols. /// @@ -1962,7 +1963,7 @@ namespace Vanara.PInvoke // lpiProtocols, LPWSAPROTOCOL_INFOW lpProtocolBuffer, LPDWORD lpdwBufferLength, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "f46042f6-0b14-4a14-abc1-4e40c34b1599")] - public static extern int WSCEnumProtocols32([Optional, MarshalAs(UnmanagedType.LPArray)] int[] lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength, out int lpErrno); + public static extern SocketError WSCEnumProtocols32([Optional, MarshalAs(UnmanagedType.LPArray)] int[] lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength, out int lpErrno); /// /// @@ -2151,7 +2152,7 @@ namespace Vanara.PInvoke // LPCWSTR Path, DWORD PathLength, LPCWSTR Extra, DWORD ExtraLength, DWORD *pPermittedLspCategories, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "c4e149ce-dff9-401a-8488-23676992c04d")] - public static extern int WSCGetApplicationCategory([MarshalAs(UnmanagedType.LPWStr)] string Path, uint PathLength, [MarshalAs(UnmanagedType.LPWStr)] string Extra, uint ExtraLength, out uint pPermittedLspCategories, out int lpErrno); + public static extern SocketError WSCGetApplicationCategory([MarshalAs(UnmanagedType.LPWStr)] string Path, uint PathLength, [MarshalAs(UnmanagedType.LPWStr)] string Extra, uint ExtraLength, out uint pPermittedLspCategories, out int lpErrno); /// /// A pointer to a globally unique identifier (GUID) for the provider. @@ -2321,7 +2322,7 @@ namespace Vanara.PInvoke // lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, PBYTE Info, size_t *InfoSize, DWORD Flags, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "5880f3dd-2a74-4af8-b0d8-2a8eedccc1e6")] - public static extern int WSCGetProviderInfo(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, [Out] IntPtr Info, ref SizeT InfoSize, uint Flags, out int lpErrno); + public static extern SocketError WSCGetProviderInfo(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, [Out] IntPtr Info, ref SizeT InfoSize, uint Flags, out int lpErrno); /// /// A pointer to a globally unique identifier (GUID) for the provider. @@ -2497,7 +2498,7 @@ namespace Vanara.PInvoke // lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, PBYTE Info, size_t *InfoSize, DWORD Flags, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "91686b38-3cde-4979-8bf6-45e805dd37ff")] - public static extern int WSCGetProviderInfo32(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, [Out] IntPtr Info, ref SizeT InfoSize, uint Flags, out int lpErrno); + public static extern SocketError WSCGetProviderInfo32(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, [Out] IntPtr Info, ref SizeT InfoSize, uint Flags, out int lpErrno); /// The WSCGetProviderPath function retrieves the DLL path for the specified provider. /// @@ -2540,7 +2541,7 @@ namespace Vanara.PInvoke // lpProviderId, WCHAR *lpszProviderDllPath, LPINT lpProviderDllPathLen, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "fe60c8c4-e2d0-48cc-9fdf-e58e408fb1b3")] - public static extern int WSCGetProviderPath(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszProviderDllPath, ref int lpProviderDllPathLen, out int lpErrno); + public static extern SocketError WSCGetProviderPath(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszProviderDllPath, ref int lpProviderDllPathLen, out int lpErrno); /// The WSCGetProviderPath32 function retrieves the DLL path for the specified 32-bit provider. /// Locally unique identifier of the provider. This value is obtained by using WSCEnumProtocols32. @@ -2589,7 +2590,7 @@ namespace Vanara.PInvoke // lpProviderId, WCHAR *lpszProviderDllPath, LPINT lpProviderDllPathLen, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "fd4ef7da-344d-4825-93b2-f0cd5622aeac")] - public static extern int WSCGetProviderPath32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszProviderDllPath, ref int lpProviderDllPathLen, out int lpErrno); + public static extern SocketError WSCGetProviderPath32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszProviderDllPath, ref int lpProviderDllPathLen, out int lpErrno); /// /// The WSCInstallNameSpace function installs a namespace provider. For providers that are able to support multiple @@ -2668,7 +2669,7 @@ namespace Vanara.PInvoke // lpszIdentifier, LPWSTR lpszPathName, DWORD dwNameSpace, DWORD dwVersion, LPGUID lpProviderId ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "f17f6174-879e-45e7-a250-975d1ee24fe0")] - public static extern int WSCInstallNameSpace([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId); + public static extern SocketError WSCInstallNameSpace([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId); /// /// The WSCInstallNameSpace32 function installs a specified 32-bit namespace provider. For providers that are able to support @@ -2755,7 +2756,7 @@ namespace Vanara.PInvoke // lpszIdentifier, LPWSTR lpszPathName, DWORD dwNameSpace, DWORD dwVersion, LPGUID lpProviderId ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "b107fbe6-bbfb-45be-8419-4d85d3c4e80c")] - public static extern int WSCInstallNameSpace32([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId); + public static extern SocketError WSCInstallNameSpace32([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId); /// /// The WSCInstallNameSpaceEx function installs a namespace provider. For providers that are able to support multiple @@ -2844,7 +2845,7 @@ namespace Vanara.PInvoke // lpszIdentifier, LPWSTR lpszPathName, DWORD dwNameSpace, DWORD dwVersion, LPGUID lpProviderId, LPBLOB lpProviderSpecific ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "13dde602-c958-4312-a16f-a393dd6fb829")] - public static extern int WSCInstallNameSpaceEx([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId, in BLOB lpProviderSpecific); + public static extern SocketError WSCInstallNameSpaceEx([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId, in BLOB lpProviderSpecific); /// /// @@ -2946,7 +2947,7 @@ namespace Vanara.PInvoke // lpszIdentifier, LPWSTR lpszPathName, DWORD dwNameSpace, DWORD dwVersion, LPGUID lpProviderId, LPBLOB lpProviderSpecific ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "222ebfcc-8854-4224-b464-28098c84b750")] - public static extern int WSCInstallNameSpaceEx32([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId, in BLOB lpProviderSpecific); + public static extern SocketError WSCInstallNameSpaceEx32([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId, in BLOB lpProviderSpecific); /// /// A pointer to a globally unique identifier (GUID) for the provider. @@ -3073,7 +3074,7 @@ namespace Vanara.PInvoke // lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "c0736018-2bcf-4281-aa73-3e1ff9eac92e")] - public static extern int WSCInstallProvider(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); + public static extern SocketError WSCInstallProvider(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); /// /// [**WSCInstallProvider64_32** is no longer available for use as of Windows Vista. Instead, use WSCInstallProvider or WSCInstallProviderAndChains.] @@ -3212,7 +3213,7 @@ namespace Vanara.PInvoke // lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "50d3a5d1-18f2-439e-a16c-6f31becb1e65")] - public static extern int WSCInstallProvider64_32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); + public static extern SocketError WSCInstallProvider64_32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); /// /// A pointer to a provider-specific, globally unique identifier (GUID). @@ -3407,7 +3408,7 @@ namespace Vanara.PInvoke // lpProtocolInfoList, DWORD dwNumberOfEntries, LPDWORD lpdwCatalogEntryId, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "592f48b4-5826-449f-b5cc-b0990679fe9f")] - public static extern int WSCInstallProviderAndChains64_32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPWStr)] string lpszLspName, XP1 dwServiceFlags, + public static extern SocketError WSCInstallProviderAndChains64_32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPWStr)] string lpszLspName, XP1 dwServiceFlags, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out uint lpdwCatalogEntryId, out int lpErrno); /// @@ -3616,7 +3617,7 @@ namespace Vanara.PInvoke // lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "266c9424-f6ab-4630-843d-bc0833d74e4f")] - public static extern int WSCSetApplicationCategory([MarshalAs(UnmanagedType.LPWStr)] string Path, uint PathLength, [MarshalAs(UnmanagedType.LPWStr)] string Extra, uint ExtraLength, uint PermittedLspCategories, out uint pPrevPermLspCat, out int lpErrno); + public static extern SocketError WSCSetApplicationCategory([MarshalAs(UnmanagedType.LPWStr)] string Path, uint PathLength, [MarshalAs(UnmanagedType.LPWStr)] string Extra, uint ExtraLength, uint PermittedLspCategories, out uint pPrevPermLspCat, out int lpErrno); /// /// A pointer to a globally unique identifier (GUID) for the provider. @@ -3786,7 +3787,7 @@ namespace Vanara.PInvoke // lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, PBYTE Info, size_t InfoSize, DWORD Flags, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "10eed3e6-d5a0-4ba4-964e-3d924a231afb")] - public static extern int WSCSetProviderInfo(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, IntPtr Info, SizeT InfoSize, uint Flags, out int lpErrno); + public static extern SocketError WSCSetProviderInfo(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, IntPtr Info, SizeT InfoSize, uint Flags, out int lpErrno); /// /// A pointer to a globally unique identifier (GUID) for the provider. @@ -3956,7 +3957,7 @@ namespace Vanara.PInvoke // lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, PBYTE Info, size_t InfoSize, DWORD Flags, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "adb2737f-5327-4306-bd57-f165f339f911")] - public static extern int WSCSetProviderInfo32(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, IntPtr Info, SizeT InfoSize, uint Flags, out int lpErrno); + public static extern SocketError WSCSetProviderInfo32(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, IntPtr Info, SizeT InfoSize, uint Flags, out int lpErrno); /// The WSCUnInstallNameSpace function uninstalls the indicated name-space provider. /// A pointer to a globally unique identifier (GUID) for the name-space provider to be uninstalled. @@ -4022,7 +4023,7 @@ namespace Vanara.PInvoke // lpProviderId ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "5267f986-99fc-4e53-9fbb-3850bb9d24cf")] - public static extern int WSCUnInstallNameSpace(in Guid lpProviderId); + public static extern SocketError WSCUnInstallNameSpace(in Guid lpProviderId); /// The WSCUnInstallNameSpace32 function uninstalls a specific 32-bit namespace provider. /// A pointer to a globally unique identifier (GUID) for the name-space provider to be uninstalled. @@ -4094,7 +4095,7 @@ namespace Vanara.PInvoke // lpProviderId ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "a2a08159-6ac0-493d-8f9f-d19aa199a65f")] - public static extern int WSCUnInstallNameSpace32(in Guid lpProviderId); + public static extern SocketError WSCUnInstallNameSpace32(in Guid lpProviderId); /// The WSCUpdateProvider function modifies the specified transport provider in the system configuration database. /// A pointer to a globally unique identifier (GUID) for the provider. @@ -4184,7 +4185,7 @@ namespace Vanara.PInvoke // const WCHAR *lpszProviderDllPath, const LPWSAPROTOCOL_INFOW lpProtocolInfoList, DWORD dwNumberOfEntries, LPINT lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "7777a2ff-2ece-4f28-88af-87fc96fdda9f")] - public static extern int WSCUpdateProvider(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); + public static extern SocketError WSCUpdateProvider(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); /// /// The WSCUpdateProvider32 function modifies the specified 32-bit transport provider in the system configuration database. @@ -4284,7 +4285,7 @@ namespace Vanara.PInvoke // lpErrno ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2spi.h", MSDNShortId = "803ef58a-853b-491c-bed1-e02275fef258")] - public static extern int WSCUpdateProvider32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); + public static extern SocketError WSCUpdateProvider32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); /// /// The AFPROTOCOLS structure supplies a list of protocols to which application programmers can constrain queries. The diff --git a/PInvoke/Ws2_32/ws2tcpip.cs b/PInvoke/Ws2_32/ws2tcpip.cs index 29a324ef..2b62313d 100644 --- a/PInvoke/Ws2_32/ws2tcpip.cs +++ b/PInvoke/Ws2_32/ws2tcpip.cs @@ -4,6 +4,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Net.Sockets; using System.Runtime.InteropServices; using System.Text; using System.Threading; @@ -140,7 +141,7 @@ namespace Vanara.PInvoke // LPHANDLE lpHandle ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2tcpip.h", MSDNShortId = "A4DE552D-DEA7-44F5-865F-5B02C9BB4AB6")] - public static extern Win32Error GetAddrInfoExCancel(in HANDLE lpHandle); + public static extern SocketError GetAddrInfoExCancel(in HANDLE lpHandle); /// /// The GetAddrInfoExOverlappedResult function gets the return code for an OVERLAPPED structure used by an @@ -169,7 +170,7 @@ namespace Vanara.PInvoke // GetAddrInfoExOverlappedResult( LPOVERLAPPED lpOverlapped ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2tcpip.h", MSDNShortId = "BBA6E407-561C-4B3C-9218-0047477E82DE")] - public static extern Win32Error GetAddrInfoExOverlappedResult(IntPtr lpOverlapped); + public static extern SocketError GetAddrInfoExOverlappedResult(IntPtr lpOverlapped); /// /// The GetAddrInfoExOverlappedResult function gets the return code for an OVERLAPPED structure used by an @@ -198,7 +199,7 @@ namespace Vanara.PInvoke // GetAddrInfoExOverlappedResult( LPOVERLAPPED lpOverlapped ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("ws2tcpip.h", MSDNShortId = "BBA6E407-561C-4B3C-9218-0047477E82DE")] - public static unsafe extern Win32Error GetAddrInfoExOverlappedResult(NativeOverlapped* lpOverlapped); + public static unsafe extern SocketError GetAddrInfoExOverlappedResult(NativeOverlapped* lpOverlapped); /// /// The GetAddrInfoEx function provides protocol-independent name resolution with additional parameters to qualify which @@ -864,7 +865,7 @@ namespace Vanara.PInvoke // LPOVERLAPPED lpOverlapped, LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine, LPHANDLE lpNameHandle ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("ws2tcpip.h", MSDNShortId = "cc4ccb2d-ea5a-48bd-a3ae-f70432ab2c39")] - public static unsafe extern Win32Error GetAddrInfoExW([Optional, MarshalAs(UnmanagedType.LPWStr)] string pName, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pServiceName, + public static unsafe extern SocketError GetAddrInfoExW([Optional, MarshalAs(UnmanagedType.LPWStr)] string pName, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pServiceName, [Optional] NS dwNameSpace, [In, Optional] Guid* lpNspId, [In, Optional] ADDRINFOEXW* hints, out SafeADDRINFOEXWArray ppResult, [In, Optional] TIMEVAL* timeout, [In, Optional] NativeOverlapped* lpOverlapped, [In, Optional] LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine, [Out, Optional] HANDLE* lpNameHandle); @@ -1344,7 +1345,7 @@ namespace Vanara.PInvoke // PCWSTR pServiceName, const ADDRINFOW *pHints, PADDRINFOW *ppResult ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("ws2tcpip.h", MSDNShortId = "82436a88-5b37-4758-a5c9-b60dd1cbc36c")] - public static extern Win32Error GetAddrInfoW([Optional] string pNodeName, [Optional] string pServiceName, [Optional] in ADDRINFOW pHints, out SafeADDRINFOWArray ppResult); + public static extern SocketError GetAddrInfoW([Optional] string pNodeName, [Optional] string pServiceName, [Optional] in ADDRINFOW pHints, out SafeADDRINFOWArray ppResult); /// The getipv4sourcefilter inline function retrieves the multicast filter state for an IPv4 socket. /// A descriptor that identifies a multicast socket. @@ -1419,14 +1420,14 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-getipv4sourcefilter int getipv4sourcefilter( SOCKET // Socket, IN_ADDR Interface, IN_ADDR Group, MULTICAST_MODE_TYPE *FilterMode, ULONG *SourceCount, IN_ADDR *SourceList ); [PInvokeData("ws2tcpip.h", MSDNShortId = "17D35D24-C419-4787-AB93-E6B1B6B13807")] - public static int getipv4sourcefilter(SOCKET Socket, IN_ADDR Interface, IN_ADDR Group, out MULTICAST_MODE_TYPE FilterMode, ref int SourceCount, IN_ADDR[] SourceList) + public static SocketError getipv4sourcefilter(SOCKET Socket, IN_ADDR Interface, IN_ADDR Group, out MULTICAST_MODE_TYPE FilterMode, ref int SourceCount, IN_ADDR[] SourceList) { FilterMode = MULTICAST_MODE_TYPE.MCAST_INCLUDE; if (SourceCount > (SourceList?.Length ?? 0)) { - WSASetLastError(unchecked((int)Win32Error.WSAENOBUFS)); - return SOCKET_ERROR; + WSASetLastError(System.Net.Sockets.SocketError.NoBufferSpaceAvailable); + return System.Net.Sockets.SocketError.SocketError; } var Filter = new IP_MSFILTER @@ -1643,7 +1644,7 @@ namespace Vanara.PInvoke // INT Flags ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("ws2tcpip.h", MSDNShortId = "5630a49a-c182-440c-ad54-6ff3ba4274c6")] - public static extern Win32Error GetNameInfoW([In] SOCKADDR pSockaddr, int SockaddrLength, StringBuilder pNodeBuffer, uint NodeBufferSize, StringBuilder pServiceBuffer, uint ServiceBufferSize, NI Flags); + public static extern SocketError GetNameInfoW([In] SOCKADDR pSockaddr, int SockaddrLength, StringBuilder pNodeBuffer, uint NodeBufferSize, StringBuilder pServiceBuffer, uint ServiceBufferSize, NI Flags); /// The getsourcefilter inline function retrieves the multicast filter state for an IPv4 or IPv6 socket. /// A descriptor that identifies a multicast socket. @@ -1709,14 +1710,14 @@ namespace Vanara.PInvoke // Interface, const SOCKADDR *Group, int GroupLength, MULTICAST_MODE_TYPE *FilterMode, ULONG *SourceCount, SOCKADDR_STORAGE // *SourceList ); [PInvokeData("ws2tcpip.h", MSDNShortId = "2CA84000-F114-439D-BEDE-9990044C7785")] - public static int getsourcefilter(SOCKET Socket, uint Interface, [In] SOCKADDR Group, int GroupLength, out MULTICAST_MODE_TYPE FilterMode, ref int SourceCount, SOCKADDR_STORAGE[] SourceList) + public static SocketError getsourcefilter(SOCKET Socket, uint Interface, [In] SOCKADDR Group, int GroupLength, out MULTICAST_MODE_TYPE FilterMode, ref int SourceCount, SOCKADDR_STORAGE[] SourceList) { FilterMode = MULTICAST_MODE_TYPE.MCAST_INCLUDE; if (SourceCount > SourceList.Length || GroupLength > Group.Size) { - WSASetLastError(unchecked((int)Win32Error.WSAENOBUFS)); - return SOCKET_ERROR; + WSASetLastError(System.Net.Sockets.SocketError.NoBufferSpaceAvailable); + return System.Net.Sockets.SocketError.SocketError; } var Filter = new GROUP_FILTER @@ -2162,7 +2163,7 @@ namespace Vanara.PInvoke // pszAddrString, PVOID pAddrBuf ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Ansi)] [PInvokeData("ws2tcpip.h", MSDNShortId = "d0705997-0dc7-443b-a43f-611301cc9169")] - public static extern int inet_pton(ADDRESS_FAMILY Family, string pszAddrString, out IN_ADDR pAddrBuf); + public static extern SocketError inet_pton(ADDRESS_FAMILY Family, string pszAddrString, out IN_ADDR pAddrBuf); /// /// The InetPton function converts an IPv4 or IPv6 Internet network address in its standard text presentation form into its @@ -2305,7 +2306,7 @@ namespace Vanara.PInvoke // pszAddrString, PVOID pAddrBuf ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Ansi)] [PInvokeData("ws2tcpip.h", MSDNShortId = "d0705997-0dc7-443b-a43f-611301cc9169")] - public static extern int inet_pton(ADDRESS_FAMILY Family, string pszAddrString, out IN6_ADDR pAddrBuf); + public static extern SocketError inet_pton(ADDRESS_FAMILY Family, string pszAddrString, out IN6_ADDR pAddrBuf); /// /// The InetNtop function converts an IPv4 or IPv6 Internet network address into a string in Internet standard format. The @@ -2726,7 +2727,7 @@ namespace Vanara.PInvoke // pszAddrString, PVOID pAddrBuf ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("ws2tcpip.h", MSDNShortId = "d0705997-0dc7-443b-a43f-611301cc9169")] - public static extern int InetPtonW(ADDRESS_FAMILY Family, [MarshalAs(UnmanagedType.LPWStr)] string pszAddrString, out IN_ADDR pAddrBuf); + public static extern SocketError InetPtonW(ADDRESS_FAMILY Family, [MarshalAs(UnmanagedType.LPWStr)] string pszAddrString, out IN_ADDR pAddrBuf); /// /// The InetPton function converts an IPv4 or IPv6 Internet network address in its standard text presentation form into its @@ -2869,7 +2870,7 @@ namespace Vanara.PInvoke // pszAddrString, PVOID pAddrBuf ); [DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true, CharSet = CharSet.Unicode)] [PInvokeData("ws2tcpip.h", MSDNShortId = "d0705997-0dc7-443b-a43f-611301cc9169")] - public static extern int InetPtonW(ADDRESS_FAMILY Family, [MarshalAs(UnmanagedType.LPWStr)] string pszAddrString, out IN6_ADDR pAddrBuf); + public static extern SocketError InetPtonW(ADDRESS_FAMILY Family, [MarshalAs(UnmanagedType.LPWStr)] string pszAddrString, out IN6_ADDR pAddrBuf); /// /// The SetAddrInfoEx function registers or deregisters a name, a service name, and associated addresses with a specific @@ -3045,7 +3046,7 @@ namespace Vanara.PInvoke // lpNameHandle ); [DllImport(Lib.Ws2_32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("ws2tcpip.h", MSDNShortId = "6d3c5b97-32ce-4eb5-a047-d9b37c37cdda")] - public static extern int SetAddrInfoEx([MarshalAs(UnmanagedType.LPTStr)] string pName, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pServiceName, + public static extern SocketError SetAddrInfoEx([MarshalAs(UnmanagedType.LPTStr)] string pName, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pServiceName, [In, Optional, MarshalAs(UnmanagedType.LPArray)] SOCKET_ADDRESS[] pAddresses, [Optional] uint dwAddressCount, [In, Optional] IntPtr lpBlob, [Optional] uint dwFlags, [Optional] NS dwNameSpace, in Guid lpNspId, in TIMEVAL timeout, [In, Optional] IntPtr lpOverlapped, [In, Optional] LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine, out HANDLE lpNameHandle); @@ -3223,7 +3224,7 @@ namespace Vanara.PInvoke // lpNameHandle ); [DllImport(Lib.Ws2_32, SetLastError = true, CharSet = CharSet.Auto)] [PInvokeData("ws2tcpip.h", MSDNShortId = "6d3c5b97-32ce-4eb5-a047-d9b37c37cdda")] - public static unsafe extern int SetAddrInfoEx([MarshalAs(UnmanagedType.LPTStr)] string pName, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pServiceName, + public static unsafe extern SocketError SetAddrInfoEx([MarshalAs(UnmanagedType.LPTStr)] string pName, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pServiceName, [In, Optional, MarshalAs(UnmanagedType.LPArray)] SOCKET_ADDRESS[] pAddresses, [Optional] uint dwAddressCount, [In, Optional] IntPtr lpBlob, [Optional] uint dwFlags, [Optional] NS dwNameSpace, [In, Optional] Guid* lpNspId, [In, Optional] TIMEVAL* timeout, [In, Optional] NativeOverlapped* lpOverlapped, [In, Optional] LPLOOKUPSERVICE_COMPLETION_ROUTINE lpCompletionRoutine, [Out, Optional] HANDLE* lpNameHandle); @@ -3281,12 +3282,12 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/ws2tcpip/nf-ws2tcpip-setipv4sourcefilter int setipv4sourcefilter( SOCKET // Socket, IN_ADDR Interface, IN_ADDR Group, MULTICAST_MODE_TYPE FilterMode, ULONG SourceCount, const IN_ADDR *SourceList ); [PInvokeData("ws2tcpip.h", MSDNShortId = "C296D050-9195-42B5-8EBE-C6004F2DA855")] - public static int setipv4sourcefilter(SOCKET Socket, IN_ADDR Interface, IN_ADDR Group, MULTICAST_MODE_TYPE FilterMode, uint SourceCount, IN_ADDR[] SourceList) + public static SocketError setipv4sourcefilter(SOCKET Socket, IN_ADDR Interface, IN_ADDR Group, MULTICAST_MODE_TYPE FilterMode, uint SourceCount, IN_ADDR[] SourceList) { if (SourceCount > SourceList.Length) { - WSASetLastError(unchecked((int)Win32Error.WSAENOBUFS)); - return SOCKET_ERROR; + WSASetLastError(System.Net.Sockets.SocketError.NoBufferSpaceAvailable); + return System.Net.Sockets.SocketError.SocketError; } var Filter = new IP_MSFILTER @@ -3345,12 +3346,12 @@ namespace Vanara.PInvoke // Interface, const SOCKADDR *Group, int GroupLength, MULTICAST_MODE_TYPE FilterMode, ULONG SourceCount, const SOCKADDR_STORAGE // *SourceList ); [PInvokeData("ws2tcpip.h", MSDNShortId = "320455F3-FDFB-46C6-9F26-3C60064A2CB0")] - public static int setsourcefilter(SOCKET Socket, uint Interface, [In] SOCKADDR Group, int GroupLength, MULTICAST_MODE_TYPE FilterMode, uint SourceCount, SOCKADDR_STORAGE[] SourceList) + public static SocketError setsourcefilter(SOCKET Socket, uint Interface, [In] SOCKADDR Group, int GroupLength, MULTICAST_MODE_TYPE FilterMode, uint SourceCount, SOCKADDR_STORAGE[] SourceList) { if (SourceCount > SourceList.Length || GroupLength > Group.Size) { - WSASetLastError(unchecked((int)Win32Error.WSAENOBUFS)); - return SOCKET_ERROR; + WSASetLastError(System.Net.Sockets.SocketError.NoBufferSpaceAvailable); + return System.Net.Sockets.SocketError.SocketError; } var Filter = new GROUP_FILTER