From 7791d773e49c65921d6957be10dbac7e97462fab Mon Sep 17 00:00:00 2001 From: dahall Date: Mon, 11 Jul 2022 10:42:39 -0600 Subject: [PATCH] Introduced `WSRESULT` as standard error for all WinSock functions -- similar to NTStatus --- PInvoke/Ws2_32/WinSock2.WSA.Error.cs | 503 ++++++++++++++++++++++++++++++++++- PInvoke/Ws2_32/WinSock2.WSA.cs | 92 +++---- PInvoke/Ws2_32/WinSock2.legacy.cs | 38 +-- PInvoke/Ws2_32/ws2spi.cs | 70 ++--- PInvoke/Ws2_32/ws2tcpip.cs | 48 ++-- 5 files changed, 614 insertions(+), 137 deletions(-) diff --git a/PInvoke/Ws2_32/WinSock2.WSA.Error.cs b/PInvoke/Ws2_32/WinSock2.WSA.Error.cs index 813ace3e..31a89aad 100644 --- a/PInvoke/Ws2_32/WinSock2.WSA.Error.cs +++ b/PInvoke/Ws2_32/WinSock2.WSA.Error.cs @@ -1,33 +1,510 @@ using System; using System.Net.Sockets; +using System.Runtime.InteropServices; using System.Security; -namespace Vanara.PInvoke +namespace Vanara.PInvoke; + +public static partial class Ws2_32 { - public static partial class Ws2_32 + /// A WinSock2 result. Some functions can interpret the result from a simple failure (SOCKET_ERROR) to the actual error. + [StructLayout(LayoutKind.Sequential, Pack = 4)] + [PInvokeData("winsock2.h")] + public struct WSRESULT : IComparable, IComparable, IEquatable, IEquatable, IEquatable, IConvertible, IErrorProvider { + internal readonly int _value; + + /// Initializes a new instance of the structure. + /// The raw WSRESULT value. + public WSRESULT(int rawValue) => _value = rawValue; + + /// Gets a value indicating whether this is a failure (Severity bit 31 equals 1). + /// true if failed; otherwise, false. + public bool Failed => _value != 0; + + /// Gets a value indicating whether this is a success (Severity bit 31 equals 0). + /// true if succeeded; otherwise, false. + public bool Succeeded => _value == 0; + + /// Performs an explicit conversion from to . + /// The value. + /// The resulting instance from the conversion. + public static explicit operator HRESULT(WSRESULT value) => value.ToHRESULT(); + + /// Performs an explicit conversion from to . + /// The value. + /// The result of the conversion. + public static explicit operator int(WSRESULT value) => value._value; + + /// Performs an explicit conversion from to . + /// The value. + /// The result of the conversion. + public static explicit operator SocketError(WSRESULT value) => (SocketError)value._value; + + /// Performs an implicit conversion from to . + /// The value. + /// The result of the conversion. + public static implicit operator WSRESULT(int value) => new(value); + + /// Performs an implicit conversion from to . + /// The value. + /// The result of the conversion. + public static implicit operator WSRESULT(SocketError value) => new((int)value); + + /// Implements the operator !=. + /// The first . + /// The second . + /// The result of the operator. + public static bool operator !=(WSRESULT hrLeft, WSRESULT hrRight) => !(hrLeft == hrRight); + + /// Implements the operator !=. + /// The first . + /// The second . + /// The result of the operator. + public static bool operator !=(WSRESULT hrLeft, int hrRight) => !(hrLeft == hrRight); + + /// Implements the operator ==. + /// The first . + /// The second . + /// The result of the operator. + public static bool operator ==(WSRESULT hrLeft, WSRESULT hrRight) => hrLeft.Equals(hrRight); + + /// Implements the operator ==. + /// The first . + /// The second . + /// The result of the operator. + public static bool operator ==(WSRESULT hrLeft, int hrRight) => hrLeft.Equals(hrRight); + /// - /// Throws an appropriate exception if is a failure. If the value of equals (-1 or SOCKET_ERROR), then is called to retrive the actual error. + /// If the supplied raw WSRESULT value represents a failure, throw the associated with the optionally + /// supplied message. /// - /// The value to process. - public static void ThrowIfFailed(this SocketError err) { var ex = err.GetException(); if (ex is not null) throw ex; } + /// The 32-bit raw WSRESULT value. + /// The optional message to assign to the . + public static void ThrowIfFailed(int value, string message = null) => new WSRESULT(value).ThrowIfFailed(message); + + /// Throws the last error if the predicate delegate returns . + /// The type of the value to evaluate. + /// The value to check. + /// The delegate which returns on failure. + /// The message. + /// The passed in on success. + public static T ThrowLastErrorIf(T value, Func valueIsFailure, string message = null) + { + if (valueIsFailure(value)) + GetLastError().ThrowIfFailed(message); + return value; + } /// Throws the last error if the function returns . /// The value to check. - public static void ThrowLastErrorIfFalse(bool value) { if (!value) throw WSAGetLastError().GetException(); } + /// The message. + public static bool ThrowLastErrorIfFalse(bool value, string message = null) => ThrowLastErrorIf(value, v => !v, message); + + /// Throws the last error if the value is an invalid handle. + /// The SafeHandle to check. + /// The message. + public static T ThrowLastErrorIfInvalid(T value, string message = null) where T : SafeHandle => ThrowLastErrorIf(value, v => v.IsInvalid, message); + + /// Compares the current object with another object of the same type. + /// An object to compare with this object. + /// + /// A value that indicates the relative order of the objects being compared. The return value has the following + /// meanings: Value Meaning Less than zero This object is less than the parameter.Zero This object is equal + /// to . Greater than zero This object is greater than . + /// + public int CompareTo(WSRESULT other) => _value.CompareTo(other._value); /// - /// Gets the .NET associated with the value and optionally adds the supplied message. + /// Compares the current instance with another object of the same type and returns an integer that indicates whether the current + /// instance precedes, follows, or occurs in the same position in the sort order as the other object. /// - /// The value to process. - /// The associated or if this is not a failure. + /// An object to compare with this instance. + /// + /// A value that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less + /// than zero This instance precedes in the sort order. Zero This instance occurs in the same position in the + /// sort order as . Greater than zero This instance follows in the sort order. + /// + public int CompareTo(object obj) => obj switch + { + WSRESULT r => CompareTo(r), + int i => i.CompareTo(_value), + SocketError e => e.CompareTo((SocketError)_value), + IErrorProvider e => ToHRESULT().CompareTo(e.ToHRESULT()), + _ => _value.CompareTo(obj) + }; + + /// Indicates whether the current object is equal to an . + /// An object to compare with this object. + /// true if the current object is equal to the parameter; otherwise, false. + public bool Equals(int other) => other == _value; + + /// Determines whether the specified , is equal to this instance. + /// The to compare with this instance. + /// true if the specified is equal to this instance; otherwise, false. + public override bool Equals(object obj) => obj switch + { + null => false, + WSRESULT r => Equals(r), + int i => Equals(i), + SocketError e => Equals(e), + IErrorProvider e => ToHRESULT().Equals(e.ToHRESULT()), + IConvertible c => Equals(c.ToInt32(null)), + _ => base.Equals(obj) + }; + + /// Indicates whether the current object is equal to an . + /// An object to compare with this object. + /// true if the current object is equal to the parameter; otherwise, false. + public bool Equals(SocketError other) => (int)other == _value; + + /// Indicates whether the current object is equal to another object of the same type. + /// An object to compare with this object. + /// true if the current object is equal to the parameter; otherwise, false. + public bool Equals(WSRESULT other) => other._value == _value; + + /// Gets the .NET associated with the WSRESULT value and optionally adds the supplied message. + /// The optional message to assign to the . + /// The associated or null if this WSRESULT is not a failure. [SecurityCritical, SecuritySafeCritical] - public static Exception GetException(this SocketError err) => err switch + public Exception GetException(string message = null) => _value switch { 0 => null, - SocketError.SocketError => new SocketException((int)WSAGetLastError()), - _ => new SocketException((int)err) + SOCKET_ERROR => new SocketException((int)GetLastError()), + _ => new SocketException(_value) }; + + /// Returns a hash code for this instance. + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + public override int GetHashCode() => _value; + + /// Gets the last error. + /// The last error. + [SecurityCritical] + [System.Diagnostics.DebuggerStepThrough] + public static WSRESULT GetLastError() => WSAGetLastError(); + + /// + /// If this represents a failure, throw the associated with the optionally supplied message. + /// + /// The optional message to assign to the . + [SecurityCritical] + [SecuritySafeCritical] + public void ThrowIfFailed(string message = null) + { + Exception exception = GetException(message); + if (exception is not null) + throw exception; + } + + /// Converts this error to an . + /// An equivalent . + public HRESULT ToHRESULT() => HRESULT.HRESULT_FROM_WIN32(unchecked((uint)(_value == SOCKET_ERROR ? GetLastError()._value : _value))); + + /// Returns a that represents this instance. + /// A that represents this instance. + public override string ToString() => StaticFieldValueHash.TryGetFieldName(_value, out var err) ? err : ToHRESULT().ToString(); + + TypeCode IConvertible.GetTypeCode() => _value.GetTypeCode(); + + bool IConvertible.ToBoolean(IFormatProvider provider) => Succeeded; + + byte IConvertible.ToByte(IFormatProvider provider) => ((IConvertible)_value).ToByte(provider); + + char IConvertible.ToChar(IFormatProvider provider) => throw new NotSupportedException(); + + DateTime IConvertible.ToDateTime(IFormatProvider provider) => throw new NotSupportedException(); + + decimal IConvertible.ToDecimal(IFormatProvider provider) => ((IConvertible)_value).ToDecimal(provider); + + double IConvertible.ToDouble(IFormatProvider provider) => ((IConvertible)_value).ToDouble(provider); + + short IConvertible.ToInt16(IFormatProvider provider) => ((IConvertible)_value).ToInt16(provider); + + int IConvertible.ToInt32(IFormatProvider provider) => _value; + + long IConvertible.ToInt64(IFormatProvider provider) => ((IConvertible)_value).ToInt64(provider); + + sbyte IConvertible.ToSByte(IFormatProvider provider) => ((IConvertible)_value).ToSByte(provider); + + float IConvertible.ToSingle(IFormatProvider provider) => ((IConvertible)_value).ToSingle(provider); + + string IConvertible.ToString(IFormatProvider provider) => ToString(); + + object IConvertible.ToType(Type conversionType, IFormatProvider provider) => + ((IConvertible)_value).ToType(conversionType, provider); + + ushort IConvertible.ToUInt16(IFormatProvider provider) => ((IConvertible)unchecked((uint)_value)).ToUInt16(provider); + + uint IConvertible.ToUInt32(IFormatProvider provider) => unchecked((uint)_value); + + ulong IConvertible.ToUInt64(IFormatProvider provider) => ((IConvertible)unchecked((uint)_value)).ToUInt64(provider); + + /// A blocking operation was interrupted by a call to WSACancelBlockingCall. + public const int WSAEINTR = 0x00002714; + + /// The file handle supplied is not valid. + public const int WSAEBADF = 0x00002719; + + /// An attempt was made to access a socket in a way forbidden by its access permissions. + public const int WSAEACCES = 0x0000271D; + + /// The system detected an invalid pointer address in attempting to use a pointer argument in a call. + public const int WSAEFAULT = 0x0000271E; + + /// An invalid argument was supplied. + public const int WSAEINVAL = 0x00002726; + + /// Too many open sockets. + public const int WSAEMFILE = 0x00002728; + + /// A nonblocking socket operation could not be completed immediately. + public const int WSAEWOULDBLOCK = 0x00002733; + + /// A blocking operation is currently executing. + public const int WSAEINPROGRESS = 0x00002734; + + /// An operation was attempted on a nonblocking socket that already had an operation in progress. + public const int WSAEALREADY = 0x00002735; + + /// An operation was attempted on something that is not a socket. + public const int WSAENOTSOCK = 0x00002736; + + /// A required address was omitted from an operation on a socket. + public const int WSAEDESTADDRREQ = 0x00002737; + + /// A message sent on a datagram socket was larger than the internal message buffer or some other network limit, or the buffer used to receive a datagram into was smaller than the datagram itself. + public const int WSAEMSGSIZE = 0x00002738; + + /// A protocol was specified in the socket function call that does not support the semantics of the socket type requested. + public const int WSAEPROTOTYPE = 0x00002739; + + /// An unknown, invalid, or unsupported option or level was specified in a getsockopt or setsockopt call. + public const int WSAENOPROTOOPT = 0x0000273A; + + /// The requested protocol has not been configured into the system, or no implementation for it exists. + public const int WSAEPROTONOSUPPORT = 0x0000273B; + + /// The support for the specified socket type does not exist in this address family. + public const int WSAESOCKTNOSUPPORT = 0x0000273C; + + /// The attempted operation is not supported for the type of object referenced. + public const int WSAEOPNOTSUPP = 0x0000273D; + + /// The protocol family has not been configured into the system or no implementation for it exists. + public const int WSAEPFNOSUPPORT = 0x0000273E; + + /// An address incompatible with the requested protocol was used. + public const int WSAEAFNOSUPPORT = 0x0000273F; + + /// Only one usage of each socket address (protocol/network address/port) is normally permitted. + public const int WSAEADDRINUSE = 0x00002740; + + /// The requested address is not valid in its context. + public const int WSAEADDRNOTAVAIL = 0x00002741; + + /// A socket operation encountered a dead network. + public const int WSAENETDOWN = 0x00002742; + + /// A socket operation was attempted to an unreachable network. + public const int WSAENETUNREACH = 0x00002743; + + /// The connection has been broken due to keep-alive activity detecting a failure while the operation was in progress. + public const int WSAENETRESET = 0x00002744; + + /// An established connection was aborted by the software in your host machine. + public const int WSAECONNABORTED = 0x00002745; + + /// An existing connection was forcibly closed by the remote host. + public const int WSAECONNRESET = 0x00002746; + + /// An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full. + public const int WSAENOBUFS = 0x00002747; + + /// A connect request was made on an already connected socket. + public const int WSAEISCONN = 0x00002748; + + /// A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied. + public const int WSAENOTCONN = 0x00002749; + + /// A request to send or receive data was disallowed because the socket had already been shut down in that direction with a previous shutdown call. + public const int WSAESHUTDOWN = 0x0000274A; + + /// Too many references to a kernel object. + public const int WSAETOOMANYREFS = 0x0000274B; + + /// A connection attempt failed because the connected party did not properly respond after a period of time, or the established connection failed because the connected host failed to respond. + public const int WSAETIMEDOUT = 0x0000274C; + + /// No connection could be made because the target machine actively refused it. + public const int WSAECONNREFUSED = 0x0000274D; + + /// Cannot translate name. + public const int WSAELOOP = 0x0000274E; + + /// Name or name component was too long. + public const int WSAENAMETOOLONG = 0x0000274F; + + /// A socket operation failed because the destination host was down. + public const int WSAEHOSTDOWN = 0x00002750; + + /// A socket operation was attempted to an unreachable host. + public const int WSAEHOSTUNREACH = 0x00002751; + + /// Cannot remove a directory that is not empty. + public const int WSAENOTEMPTY = 0x00002752; + + /// A Windows Sockets implementation might have a limit on the number of applications that can use it simultaneously. + public const int WSAEPROCLIM = 0x00002753; + + /// Ran out of quota. + public const int WSAEUSERS = 0x00002754; + + /// Ran out of disk quota. + public const int WSAEDQUOT = 0x00002755; + + /// File handle reference is no longer available. + public const int WSAESTALE = 0x00002756; + + /// Item is not available locally. + public const int WSAEREMOTE = 0x00002757; + + /// WSAStartup cannot function at this time because the underlying system it uses to provide network services is currently unavailable. + public const int WSASYSNOTREADY = 0x0000276B; + + /// The Windows Sockets version requested is not supported. + public const int WSAVERNOTSUPPORTED = 0x0000276C; + + /// Either the application has not called WSAStartup, or WSAStartup failed. + public const int WSANOTINITIALISED = 0x0000276D; + + /// Returned by WSARecv or WSARecvFrom to indicate that the remote party has initiated a graceful shutdown sequence. + public const int WSAEDISCON = 0x00002775; + + /// No more results can be returned by WSALookupServiceNext. + public const int WSAENOMORE = 0x00002776; + + /// A call to WSALookupServiceEnd was made while this call was still processing. The call has been canceled. + public const int WSAECANCELLED = 0x00002777; + + /// The procedure call table is invalid. + public const int WSAEINVALIDPROCTABLE = 0x00002778; + + /// The requested service provider is invalid. + public const int WSAEINVALIDPROVIDER = 0x00002779; + + /// The requested service provider could not be loaded or initialized. + public const int WSAEPROVIDERFAILEDINIT = 0x0000277A; + + /// A system call that should never fail has failed. + public const int WSASYSCALLFAILURE = 0x0000277B; + + /// No such service is known. The service cannot be found in the specified namespace. + public const int WSASERVICE_NOT_FOUND = 0x0000277C; + + /// The specified class was not found. + public const int WSATYPE_NOT_FOUND = 0x0000277D; + + /// No more results can be returned by WSALookupServiceNext. + public const int WSA_E_NO_MORE = 0x0000277E; + + /// A call to WSALookupServiceEnd was made while this call was still processing. The call has been canceled. + public const int WSA_E_CANCELLED = 0x0000277F; + + /// A database query failed because it was actively refused. + public const int WSAEREFUSED = 0x00002780; + + /// No such host is known. + public const int WSAHOST_NOT_FOUND = 0x00002AF9; + + /// This is usually a temporary error during host name resolution and means that the local server did not receive a response from an authoritative server. + public const int WSATRY_AGAIN = 0x00002AFA; + + /// A nonrecoverable error occurred during a database lookup. + public const int WSANO_RECOVERY = 0x00002AFB; + + /// The requested name is valid, but no data of the requested type was found. + public const int WSANO_DATA = 0x00002AFC; + + /// At least one reserve has arrived. + public const int WSA_QOS_RECEIVERS = 0x00002AFD; + + /// At least one path has arrived. + public const int WSA_QOS_SENDERS = 0x00002AFE; + + /// There are no senders. + public const int WSA_QOS_NO_SENDERS = 0x00002AFF; + + /// There are no receivers. + public const int WSA_QOS_NO_RECEIVERS = 0x00002B00; + + /// Reserve has been confirmed. + public const int WSA_QOS_REQUEST_CONFIRMED = 0x00002B01; + + /// Error due to lack of resources. + public const int WSA_QOS_ADMISSION_FAILURE = 0x00002B02; + + /// Rejected for administrative reasons - bad credentials. + public const int WSA_QOS_POLICY_FAILURE = 0x00002B03; + + /// Unknown or conflicting style. + public const int WSA_QOS_BAD_STYLE = 0x00002B04; + + /// There is a problem with some part of the filterspec or provider-specific buffer in general. + public const int WSA_QOS_BAD_OBJECT = 0x00002B05; + + /// There is a problem with some part of the flowspec. + public const int WSA_QOS_TRAFFIC_CTRL_ERROR = 0x00002B06; + + /// General quality of serve (QOS) error. + public const int WSA_QOS_GENERIC_ERROR = 0x00002B07; + + /// An invalid or unrecognized service type was found in the flowspec. + public const int WSA_QOS_ESERVICETYPE = 0x00002B08; + + /// An invalid or inconsistent flowspec was found in the QOS structure. + public const int WSA_QOS_EFLOWSPEC = 0x00002B09; + + /// Invalid QOS provider-specific buffer. + public const int WSA_QOS_EPROVSPECBUF = 0x00002B0A; + + /// An invalid QOS filter style was used. + public const int WSA_QOS_EFILTERSTYLE = 0x00002B0B; + + /// An invalid QOS filter type was used. + public const int WSA_QOS_EFILTERTYPE = 0x00002B0C; + + /// An incorrect number of QOS FILTERSPECs were specified in the FLOWDESCRIPTOR. + public const int WSA_QOS_EFILTERCOUNT = 0x00002B0D; + + /// An object with an invalid ObjectLength field was specified in the QOS provider-specific buffer. + public const int WSA_QOS_EOBJLENGTH = 0x00002B0E; + + /// An incorrect number of flow descriptors was specified in the QOS structure. + public const int WSA_QOS_EFLOWCOUNT = 0x00002B0F; + + /// An unrecognized object was found in the QOS provider-specific buffer. + public const int WSA_QOS_EUNKOWNPSOBJ = 0x00002B10; + + /// An invalid policy object was found in the QOS provider-specific buffer. + public const int WSA_QOS_EPOLICYOBJ = 0x00002B11; + + /// An invalid QOS flow descriptor was found in the flow descriptor list. + public const int WSA_QOS_EFLOWDESC = 0x00002B12; + + /// An invalid or inconsistent flowspec was found in the QOS provider-specific buffer. + public const int WSA_QOS_EPSFLOWSPEC = 0x00002B13; + + /// An invalid FILTERSPEC was found in the QOS provider-specific buffer. + public const int WSA_QOS_EPSFILTERSPEC = 0x00002B14; + + /// An invalid shape discard mode object was found in the QOS provider-specific buffer. + public const int WSA_QOS_ESDMODEOBJ = 0x00002B15; + + /// An invalid shaping rate object was found in the QOS provider-specific buffer. + public const int WSA_QOS_ESHAPERATEOBJ = 0x00002B16; + + /// A reserved policy element was found in the QOS provider-specific buffer. + public const int WSA_QOS_RESERVED_PETYPE = 0x00002B17; } } \ No newline at end of file diff --git a/PInvoke/Ws2_32/WinSock2.WSA.cs b/PInvoke/Ws2_32/WinSock2.WSA.cs index 249c3070..e914cb7b 100644 --- a/PInvoke/Ws2_32/WinSock2.WSA.cs +++ b/PInvoke/Ws2_32/WinSock2.WSA.cs @@ -28,7 +28,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-__wsafdisset int __WSAFDIsSet( SOCKET , fd_set * ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "ca420136-0b3b-45a1-85ce-83ab6ba1a70a")] - public static extern SocketError __WSAFDIsSet(SOCKET arg1, in fd_set arg2); + public static extern WSRESULT __WSAFDIsSet(SOCKET arg1, in fd_set arg2); /// /// The WSAAccept function conditionally accepts a connection based on the return value of a condition function, provides @@ -403,7 +403,7 @@ namespace Vanara.PInvoke // lpdwAddressStringLength ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "d72e55e6-79a9-4386-9e1a-24a322f13426")] - public static extern SocketError WSAAddressToString([In] SOCKADDR lpsaAddress, uint dwAddressLength, in WSAPROTOCOL_INFO lpProtocolInfo, StringBuilder lpszAddressString, ref uint lpdwAddressStringLength); + public static extern WSRESULT WSAAddressToString([In] SOCKADDR lpsaAddress, uint dwAddressLength, in WSAPROTOCOL_INFO lpProtocolInfo, StringBuilder lpszAddressString, ref uint lpdwAddressStringLength); /// /// @@ -461,7 +461,7 @@ namespace Vanara.PInvoke using var pc = lpProtocolInfo.HasValue ? new SafeCoTaskMemStruct(lpProtocolInfo.Value) : SafeCoTaskMemStruct.Null; var sz = 1024U; var err = WSAAddressToString(lpsaAddress, (uint)lpsaAddress.Size, pc, null, ref sz); - if (err == SocketError.Fault && sz > 0) + if (err == WSRESULT.WSAEFAULT && sz > 0) { StringBuilder sb = new((int)sz); err = WSAAddressToString(lpsaAddress, (uint)lpsaAddress.Size, pc, sb, ref sz); @@ -574,7 +574,7 @@ namespace Vanara.PInvoke // lpdwAddressStringLength ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "d72e55e6-79a9-4386-9e1a-24a322f13426")] - public static extern SocketError WSAAddressToString([In] SOCKADDR lpsaAddress, uint dwAddressLength, [Optional] IntPtr lpProtocolInfo, StringBuilder lpszAddressString, ref uint lpdwAddressStringLength); + public static extern WSRESULT WSAAddressToString([In] SOCKADDR lpsaAddress, uint dwAddressLength, [Optional] IntPtr lpProtocolInfo, StringBuilder lpszAddressString, ref uint lpdwAddressStringLength); /// /// The WSAAsyncGetHostByAddr function asynchronously retrieves host information that corresponds to an address. @@ -1861,7 +1861,7 @@ namespace Vanara.PInvoke // u_int wMsg, long lEvent ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "a4d3f599-358c-4a94-91eb-7e1c80244250")] - public static extern SocketError WSAAsyncSelect(SOCKET s, HWND hWnd, uint wMsg, int lEvent); + public static extern WSRESULT WSAAsyncSelect(SOCKET s, HWND hWnd, uint wMsg, int lEvent); /// The WSACancelAsyncRequest function cancels an incomplete asynchronous operation. /// Handle that specifies the asynchronous operation to be canceled. @@ -1921,7 +1921,7 @@ namespace Vanara.PInvoke // hAsyncTaskHandle ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "0e53eccf-ef85-43ec-a02c-12896471a7a9")] - public static extern SocketError WSACancelAsyncRequest(HANDLE hAsyncTaskHandle); + public static extern WSRESULT WSACancelAsyncRequest(HANDLE hAsyncTaskHandle); /// The WSACleanup function terminates use of the Winsock 2 DLL (Ws2_32.dll). /// @@ -1999,7 +1999,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-wsacleanup int WSACleanup( ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "72b7cc3e-be34-41e7-acbf-61742149ec8b")] - public static extern SocketError WSACleanup(); + public static extern WSRESULT WSACleanup(); /// The WSACloseEvent function closes an open event object handle. /// Object handle identifying the open event. @@ -2312,7 +2312,7 @@ namespace Vanara.PInvoke // sockaddr *name, int namelen, LPWSABUF lpCallerData, LPWSABUF lpCalleeData, LPQOS lpSQOS, LPQOS lpGQOS ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "3b32cc6e-3df7-4104-a0d4-317fd445c7b2")] - public static extern SocketError WSAConnect(SOCKET s, [In] SOCKADDR name, int namelen, [In, Optional] IntPtr lpCallerData, + public static extern WSRESULT WSAConnect(SOCKET s, [In] SOCKADDR name, int namelen, [In, Optional] IntPtr lpCallerData, [Out, Optional] IntPtr lpCalleeData, [Optional] IntPtr lpSQOS, [Optional] IntPtr lpGQOS); /// @@ -2852,7 +2852,7 @@ namespace Vanara.PInvoke // SOCKET s, DWORD dwProcessId, LPWSAPROTOCOL_INFOA lpProtocolInfo ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "d4028461-bfa6-4074-9460-5d1371790d41")] - public static extern SocketError WSADuplicateSocket(SOCKET s, uint dwProcessId, out WSAPROTOCOL_INFO lpProtocolInfo); + public static extern WSRESULT WSADuplicateSocket(SOCKET s, uint dwProcessId, out WSAPROTOCOL_INFO lpProtocolInfo); /// The WSAEnumNameSpaceProviders function retrieves information on available namespace providers. /// @@ -2930,7 +2930,7 @@ namespace Vanara.PInvoke // WSAEnumNameSpaceProvidersW( LPDWORD lpdwBufferLength, LPWSANAMESPACE_INFOW lpnspBuffer ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Unicode)] [PInvokeData("winsock2.h", MSDNShortId = "f5b6cd42-c5cb-43b6-bb96-fd260217e252")] - public static extern SocketError WSAEnumNameSpaceProviders(ref uint lpdwBufferLength, [Out] IntPtr lpnspBuffer); + public static extern WSRESULT WSAEnumNameSpaceProviders(ref uint lpdwBufferLength, [Out] IntPtr lpnspBuffer); /// The WSAEnumNameSpaceProvidersEx function retrieves information on available namespace providers. /// @@ -3004,7 +3004,7 @@ namespace Vanara.PInvoke // WSAEnumNameSpaceProvidersExA( LPDWORD lpdwBufferLength, LPWSANAMESPACE_INFOEXA lpnspBuffer ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Unicode)] [PInvokeData("winsock2.h", MSDNShortId = "34bc96aa-63f7-4ab8-9376-6f4b979225ca")] - public static extern SocketError WSAEnumNameSpaceProvidersEx(ref uint lpdwBufferLength, [Out] IntPtr lpnspBuffer); + public static extern WSRESULT WSAEnumNameSpaceProvidersEx(ref uint lpdwBufferLength, [Out] IntPtr lpnspBuffer); /// /// The WSAEnumNetworkEvents function discovers occurrences of network events for the indicated socket, clear internal @@ -3170,7 +3170,7 @@ namespace Vanara.PInvoke // SOCKET s, WSAEVENT hEventObject, LPWSANETWORKEVENTS lpNetworkEvents ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "2e6abccd-c82c-4a6b-8720-259986ac9984")] - public static extern SocketError WSAEnumNetworkEvents(SOCKET s, [Optional] WSAEVENT hEventObject, out WSANETWORKEVENTS lpNetworkEvents); + public static extern WSRESULT WSAEnumNetworkEvents(SOCKET s, [Optional] WSAEVENT hEventObject, out WSANETWORKEVENTS lpNetworkEvents); /// The WSAEnumProtocols function retrieves information about available transport protocols. /// @@ -3278,7 +3278,7 @@ namespace Vanara.PInvoke // lpiProtocols, LPWSAPROTOCOL_INFOA lpProtocolBuffer, LPDWORD lpdwBufferLength ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "928b6937-41a3-4268-a3bc-14c9e04870e4")] - public static extern SocketError WSAEnumProtocols([Optional, MarshalAs(UnmanagedType.LPArray)] int[] lpiProtocols, [Out] IntPtr lpProtocolBuffer, ref uint lpdwBufferLength); + public static extern WSRESULT WSAEnumProtocols([Optional, MarshalAs(UnmanagedType.LPArray)] int[] lpiProtocols, [Out] IntPtr lpProtocolBuffer, ref uint lpdwBufferLength); /// /// The WSAEventSelect function specifies an event object to be associated with the specified set of FD_XXX network events. @@ -3624,7 +3624,7 @@ namespace Vanara.PInvoke // WSAEVENT hEventObject, long lNetworkEvents ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "f98a71e4-47fb-47a4-b37e-e4cc801a8f98")] - public static extern SocketError WSAEventSelect(SOCKET s, WSAEVENT hEventObject, FD lNetworkEvents); + public static extern WSRESULT WSAEventSelect(SOCKET s, WSAEVENT hEventObject, FD lNetworkEvents); /// The WSAGetLastError function returns the error status for the last Windows Sockets operation that failed. /// The return value indicates the error code for this thread's last Windows Sockets operation that failed. @@ -3671,7 +3671,7 @@ namespace Vanara.PInvoke // https://docs.microsoft.com/en-us/windows/desktop/api/winsock/nf-winsock-wsagetlasterror int WSAGetLastError( ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock.h", MSDNShortId = "39e41b66-44ed-46dc-bfc2-65228b669992")] - public static extern SocketError WSAGetLastError(); + public static extern WSRESULT WSAGetLastError(); /// The WSAGetOverlappedResult function retrieves the results of an overlapped operation on the specified socket. /// @@ -3935,7 +3935,7 @@ namespace Vanara.PInvoke // lpServiceClassInfo ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "e177bb7d-c7d3-43a4-a809-ab8212feea2e")] - public static extern SocketError WSAGetServiceClassInfo(in Guid lpProviderId, in Guid lpServiceClassId, ref uint lpdwBufSize, IntPtr lpServiceClassInfo); + public static extern WSRESULT WSAGetServiceClassInfo(in Guid lpProviderId, in Guid lpServiceClassId, ref uint lpdwBufSize, IntPtr lpServiceClassInfo); /// /// The WSAGetServiceClassNameByClassId function retrieves the name of the service associated with the specified type. This @@ -4000,7 +4000,7 @@ namespace Vanara.PInvoke // WSAGetServiceClassNameByClassIdA( LPGUID lpServiceClassId, LPSTR lpszServiceClassName, LPDWORD lpdwBufferLength ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "0a61751e-10e5-4f91-a0b2-8c1baf477653")] - public static extern SocketError WSAGetServiceClassNameByClassId(in Guid lpServiceClassId, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpszServiceClassName, ref uint lpdwBufferLength); + public static extern WSRESULT WSAGetServiceClassNameByClassId(in Guid lpServiceClassId, [MarshalAs(UnmanagedType.LPTStr)] StringBuilder lpszServiceClassName, ref uint lpdwBufferLength); /// The WSAHtonl function converts a u_long from host byte order to network byte order. /// A descriptor identifying a socket. @@ -4062,7 +4062,7 @@ namespace Vanara.PInvoke // hostlong, OUT u_long *lpnetlong ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "33512f49-d576-4439-ad8d-5c87387d6214")] - public static extern SocketError WSAHtonl([In] SOCKET s, [In] uint hostlong, out uint lpnetlong); + public static extern WSRESULT WSAHtonl([In] SOCKET s, [In] uint hostlong, out uint lpnetlong); /// The WSAHtons function converts a u_short from host byte order to network byte order. /// A descriptor identifying a socket. @@ -4123,7 +4123,7 @@ namespace Vanara.PInvoke // hostshort, OUT u_short *lpnetshort ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "95fb103b-f7dd-4fa4-bf68-ed8e87cdd96b")] - public static extern SocketError WSAHtons([In] SOCKET s, [In] ushort hostshort, out ushort lpnetshort); + public static extern WSRESULT WSAHtons([In] SOCKET s, [In] ushort hostshort, out ushort lpnetshort); /// /// The WSAInstallServiceClass function registers a service class schema within a namespace. This schema includes the class @@ -4190,7 +4190,7 @@ namespace Vanara.PInvoke // WSAInstallServiceClassA( LPWSASERVICECLASSINFOA lpServiceClassInfo ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "06760319-aeeb-4ad7-b77a-01efea7ed904")] - public static extern SocketError WSAInstallServiceClass(in WSASERVICECLASSINFO lpServiceClassInfo); + public static extern WSRESULT WSAInstallServiceClass(in WSASERVICECLASSINFO lpServiceClassInfo); /// The WSAIoctl function controls the mode of a socket. /// A descriptor identifying a socket. @@ -4429,7 +4429,7 @@ namespace Vanara.PInvoke // LPWSAOVERLAPPED lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "038aeca6-d7b7-4f74-ac69-4536c2e5118b")] - public static extern SocketError WSAIoctl(SOCKET s, uint dwIoControlCode, [In] IntPtr lpvInBuffer, uint cbInBuffer, [Out] IntPtr lpvOutBuffer, uint cbOutBuffer, out uint lpcbBytesReturned, [Optional] IntPtr lpOverlapped, [Optional] IntPtr lpCompletionRoutine); + public static extern WSRESULT WSAIoctl(SOCKET s, uint dwIoControlCode, [In] IntPtr lpvInBuffer, uint cbInBuffer, [Out] IntPtr lpvOutBuffer, uint cbOutBuffer, out uint lpcbBytesReturned, [Optional] IntPtr lpOverlapped, [Optional] IntPtr lpCompletionRoutine); /// The WSAIoctl function controls the mode of a socket. /// A descriptor identifying a socket. @@ -4602,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 SocketError WSAIoctl(SOCKET s, uint dwIoControlCode, TIn inVal, out TOut outVal) where TIn : struct where TOut : struct + public static WSRESULT 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 == SocketError.SocketError) + if (ret.Failed) { outVal = default; return WSAGetLastError(); } outVal = ptrOut.ToStructure(); - return SocketError.Success; + return 0; } /// @@ -5128,7 +5128,7 @@ namespace Vanara.PInvoke // LPWSAQUERYSETA lpqsRestrictions, DWORD dwControlFlags, LPHANDLE lphLookup ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "448309ef-b9dd-4960-8016-d26691df59ec")] - public static extern SocketError WSALookupServiceBegin(in WSAQUERYSET lpqsRestrictions, LUP dwControlFlags, out HANDLE lphLookup); + public static extern WSRESULT WSALookupServiceBegin(in WSAQUERYSET lpqsRestrictions, LUP dwControlFlags, out HANDLE lphLookup); /// /// @@ -5177,7 +5177,7 @@ namespace Vanara.PInvoke // HANDLE hLookup ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "f9d2ac54-a818-464d-918e-80ebb5b1b106")] - public static extern SocketError WSALookupServiceEnd(HANDLE hLookup); + public static extern WSRESULT WSALookupServiceEnd(HANDLE hLookup); /// /// @@ -5463,7 +5463,7 @@ namespace Vanara.PInvoke // HANDLE hLookup, DWORD dwControlFlags, LPDWORD lpdwBufferLength, LPWSAQUERYSETA lpqsResults ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "ab4f1830-b38d-4224-a6a9-6d4512245ad6")] - public static extern SocketError WSALookupServiceNext(HANDLE hLookup, LUP dwControlFlags, ref uint lpdwBufferLength, [Out] IntPtr lpqsResults); + public static extern WSRESULT WSALookupServiceNext(HANDLE hLookup, LUP dwControlFlags, ref uint lpdwBufferLength, [Out] IntPtr lpqsResults); /// The Windows Sockets WSANSPIoctl function enables developers to make I/O control calls to a registered namespace. /// The lookup handle returned from a previous call to the WSALookupServiceBegin function. @@ -5595,7 +5595,7 @@ namespace Vanara.PInvoke // LPWSACOMPLETION lpCompletion ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "6ecaedf0-0038-46d3-9916-c9cb069c5e92")] - public static extern SocketError WSANSPIoctl(HANDLE hLookup, uint dwControlCode, [In, Optional] IntPtr lpvInBuffer, uint cbInBuffer, [Out, Optional] IntPtr lpvOutBuffer, uint cbOutBuffer, out uint lpcbBytesReturned, [In, Optional] IntPtr lpCompletion); + public static extern WSRESULT WSANSPIoctl(HANDLE hLookup, uint dwControlCode, [In, Optional] IntPtr lpvInBuffer, uint cbInBuffer, [Out, Optional] IntPtr lpvOutBuffer, uint cbOutBuffer, out uint lpcbBytesReturned, [In, Optional] IntPtr lpCompletion); /// The WSANtohl function converts a u_long from network byte order to host byte order. /// A descriptor identifying a socket. @@ -5657,7 +5657,7 @@ namespace Vanara.PInvoke // u_long *lphostlong ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "7e3b42eb-3b93-459f-828a-c19e277882c7")] - public static extern SocketError WSANtohl(SOCKET s, uint netlong, out uint lphostlong); + public static extern WSRESULT WSANtohl(SOCKET s, uint netlong, out uint lphostlong); /// The WSANtohs function converts a u_short from network byte order to host byte order. /// A descriptor identifying a socket. @@ -5718,7 +5718,7 @@ namespace Vanara.PInvoke // u_short *lphostshort ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "0a4bc3a9-9919-4dcb-8a37-af37e0243c8f")] - public static extern SocketError WSANtohs(SOCKET s, ushort netshort, out ushort lphostshort); + public static extern WSRESULT WSANtohs(SOCKET s, ushort netshort, out ushort lphostshort); /// The WSAPoll function determines status of one or more sockets. /// @@ -5912,7 +5912,7 @@ namespace Vanara.PInvoke // fds, INT timeout ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "3f6f872c-5cee-49f3-bf22-2e8a5d147987")] - public static extern SocketError WSAPoll([In, Out, MarshalAs(UnmanagedType.LPArray)] WSAPOLLFD[] fdArray, uint fds, int timeout); + public static extern WSRESULT WSAPoll([In, Out, MarshalAs(UnmanagedType.LPArray)] WSAPOLLFD[] fdArray, uint fds, int timeout); /// The WSAProviderConfigChange function notifies the application when the provider configuration is changed. /// @@ -5996,7 +5996,7 @@ namespace Vanara.PInvoke // lpCompletionRoutine ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "abaf367a-8f99-478c-a58c-d57e9f9cd8a1")] - public static extern SocketError WSAProviderConfigChange(ref HANDLE lpNotificationHandle, [In, Out, Optional] IntPtr lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); + public static extern WSRESULT WSAProviderConfigChange(ref HANDLE lpNotificationHandle, [In, Out, Optional] IntPtr lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); /// The WSARecv function receives data from a connected socket or a bound connectionless socket. /// A descriptor identifying a connected socket. @@ -6389,7 +6389,7 @@ namespace Vanara.PInvoke // LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "bfe66e11-e9a7-4321-ad55-3141113e9a03")] - public static extern SocketError WSARecv(SOCKET s, [In] IntPtr lpBuffers, uint dwBufferCount, out uint lpNumberOfBytesRecvd, ref MsgFlags lpFlags, [In, Out, Optional] IntPtr lpOverlapped, + public static extern WSRESULT WSARecv(SOCKET s, [In] IntPtr lpBuffers, uint dwBufferCount, out uint lpNumberOfBytesRecvd, ref MsgFlags lpFlags, [In, Out, Optional] IntPtr lpOverlapped, [In, Optional, MarshalAs(UnmanagedType.FunctionPtr)] LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); /// @@ -6484,7 +6484,7 @@ namespace Vanara.PInvoke // LPWSABUF lpInboundDisconnectData ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "33e0fb8e-3ece-427f-b3ef-43a0f5cf0cc8")] - public static extern SocketError WSARecvDisconnect(SOCKET s, [In, Out, Optional] IntPtr lpInboundDisconnectData); + public static extern WSRESULT WSARecvDisconnect(SOCKET s, [In, Out, Optional] IntPtr lpInboundDisconnectData); /// The WSARecvFrom function receives a datagram and stores the source address. /// A descriptor identifying a socket. @@ -6784,7 +6784,7 @@ namespace Vanara.PInvoke // lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "8617dbb8-0e4e-4cd3-9597-5d20de6778f6")] - public static extern SocketError WSARecvFrom(SOCKET s, [In, Out, Optional, MarshalAs(UnmanagedType.LPArray)] WSABUF[] lpBuffers, uint dwBufferCount, out uint lpNumberOfBytesRecvd, ref MsgFlags lpFlags, + public static extern WSRESULT WSARecvFrom(SOCKET s, [In, Out, Optional, MarshalAs(UnmanagedType.LPArray)] WSABUF[] lpBuffers, uint dwBufferCount, out uint lpNumberOfBytesRecvd, ref MsgFlags lpFlags, [Out] SOCKADDR lpFrom, ref int lpFromlen, [In, Out, Optional] IntPtr lpOverlapped, [In, Optional, MarshalAs(UnmanagedType.FunctionPtr)] LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); /// The WSARemoveServiceClass function permanently removes the service class schema from the registry. @@ -6831,7 +6831,7 @@ namespace Vanara.PInvoke // LPGUID lpServiceClassId ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "7d72f727-cca9-4a07-beb4-d64f23c1f0c1")] - public static extern SocketError WSARemoveServiceClass(in Guid lpServiceClassId); + public static extern WSRESULT WSARemoveServiceClass(in Guid lpServiceClassId); /// The WSAResetEvent function resets the state of the specified event object to nonsignaled. /// A handle that identifies an open event object handle. @@ -7175,7 +7175,7 @@ namespace Vanara.PInvoke // lpCompletionRoutine ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "764339e6-a1ac-455d-8ebd-ad0fa50dc3b0")] - public static extern SocketError WSASend(SOCKET s, [In, MarshalAs(UnmanagedType.LPArray)] WSABUF[] lpBuffers, uint dwBufferCount, out uint lpNumberOfBytesSent, + public static extern WSRESULT WSASend(SOCKET s, [In, MarshalAs(UnmanagedType.LPArray)] WSABUF[] lpBuffers, uint dwBufferCount, out uint lpNumberOfBytesSent, MsgFlags dwFlags, [In, Out, Optional] IntPtr lpOverlapped, [In, Optional, MarshalAs(UnmanagedType.FunctionPtr)] LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); /// @@ -7259,7 +7259,7 @@ namespace Vanara.PInvoke // LPWSABUF lpOutboundDisconnectData ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "c05fc719-e35a-4194-ac01-a294b19ccce9")] - public static extern SocketError WSASendDisconnect(SOCKET s, in WSABUF lpOutboundDisconnectData); + public static extern WSRESULT WSASendDisconnect(SOCKET s, in WSABUF lpOutboundDisconnectData); /// /// The WSASendDisconnect function initiates termination of the connection for the socket and sends disconnect data. @@ -7342,7 +7342,7 @@ namespace Vanara.PInvoke // LPWSABUF lpOutboundDisconnectData ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "c05fc719-e35a-4194-ac01-a294b19ccce9")] - public static extern SocketError WSASendDisconnect(SOCKET s, [In, Optional] IntPtr lpOutboundDisconnectData); + public static extern WSRESULT WSASendDisconnect(SOCKET s, [In, Optional] IntPtr lpOutboundDisconnectData); /// The WSASendMsg function sends data and optional control information from connected and unconnected sockets. /// A descriptor identifying the socket. @@ -7649,7 +7649,7 @@ namespace Vanara.PInvoke // lpCompletionRoutine ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "3b2ba645-6a70-4ba2-b4a2-5bde0c7f8d08")] - public static extern SocketError WSASendMsg(SOCKET Handle, in WSAMSG lpMsg, MsgFlags dwFlags, out uint lpNumberOfBytesSent, [In, Out, Optional] IntPtr lpOverlapped, + public static extern WSRESULT WSASendMsg(SOCKET Handle, in WSAMSG lpMsg, MsgFlags dwFlags, out uint lpNumberOfBytesSent, [In, Out, Optional] IntPtr lpOverlapped, [In, Optional, MarshalAs(UnmanagedType.FunctionPtr)] LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); /// The WSASendTo function sends data to a specific destination, using overlapped I/O where applicable. @@ -7955,7 +7955,7 @@ namespace Vanara.PInvoke // lpOverlapped, LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine ); [DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)] [PInvokeData("winsock2.h", MSDNShortId = "e3a11522-871c-4d6b-a2e6-ca91ffc2b698")] - public static extern SocketError WSASendTo(SOCKET s, [In, MarshalAs(UnmanagedType.LPArray)] WSABUF[] lpBuffers, uint dwBufferCount, out uint lpNumberOfBytesSent, + public static extern WSRESULT WSASendTo(SOCKET s, [In, MarshalAs(UnmanagedType.LPArray)] WSABUF[] lpBuffers, uint dwBufferCount, out uint lpNumberOfBytesSent, MsgFlags dwFlags, [In, Optional] SOCKADDR lpTo, int iTolen, [In, Out, Optional] IntPtr lpOverlapped, [In, Optional, MarshalAs(UnmanagedType.FunctionPtr)] LPWSAOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine); @@ -8035,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(SocketError iError); + public static extern void WSASetLastError(WSRESULT 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. @@ -8312,7 +8312,7 @@ namespace Vanara.PInvoke // lpqsRegInfo, WSAESETSERVICEOP essoperation, DWORD dwControlFlags ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "21a8ff26-4c9e-4846-a75a-1a27c746edab")] - public static extern SocketError WSASetService(in WSAQUERYSET lpqsRegInfo, WSAESETSERVICEOP essoperation, ServiceInstallFlags dwControlFlags); + public static extern WSRESULT WSASetService(in WSAQUERYSET lpqsRegInfo, WSAESETSERVICEOP essoperation, ServiceInstallFlags dwControlFlags); /// The WSASocket function creates a socket that is bound to a specific transport-service provider. /// @@ -9766,7 +9766,7 @@ namespace Vanara.PInvoke // AddressString, INT AddressFamily, LPWSAPROTOCOL_INFOA lpProtocolInfo, LPSOCKADDR lpAddress, LPINT lpAddressLength ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "7b9946c3-c8b3-45ae-9bde-03faaf604bba")] - public static extern SocketError WSAStringToAddress([MarshalAs(UnmanagedType.LPTStr)] string AddressString, ADDRESS_FAMILY AddressFamily, in WSAPROTOCOL_INFO lpProtocolInfo, [Out] SOCKADDR lpAddress, ref int lpAddressLength); + public static extern WSRESULT WSAStringToAddress([MarshalAs(UnmanagedType.LPTStr)] string AddressString, ADDRESS_FAMILY AddressFamily, in WSAPROTOCOL_INFO lpProtocolInfo, [Out] SOCKADDR lpAddress, ref int lpAddressLength); /// /// The WSAStringToAddress function converts a network address in its standard text presentation form into its numeric binary @@ -9847,7 +9847,7 @@ namespace Vanara.PInvoke // AddressString, INT AddressFamily, LPWSAPROTOCOL_INFOA lpProtocolInfo, LPSOCKADDR lpAddress, LPINT lpAddressLength ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "7b9946c3-c8b3-45ae-9bde-03faaf604bba")] - public static extern SocketError WSAStringToAddress([MarshalAs(UnmanagedType.LPTStr)] string AddressString, ADDRESS_FAMILY AddressFamily, [In, Optional] IntPtr lpProtocolInfo, [Out] SOCKADDR lpAddress, ref int lpAddressLength); + public static extern WSRESULT WSAStringToAddress([MarshalAs(UnmanagedType.LPTStr)] string AddressString, ADDRESS_FAMILY AddressFamily, [In, Optional] IntPtr lpProtocolInfo, [Out] SOCKADDR lpAddress, ref int lpAddressLength); /// /// The WSAStringToAddress function converts a network address in its standard text presentation form into its numeric binary @@ -9928,7 +9928,7 @@ namespace Vanara.PInvoke // AddressString, INT AddressFamily, LPWSAPROTOCOL_INFOA lpProtocolInfo, LPSOCKADDR lpAddress, LPINT lpAddressLength ); [DllImport(Lib.Ws2_32, SetLastError = false, CharSet = CharSet.Auto)] [PInvokeData("winsock2.h", MSDNShortId = "7b9946c3-c8b3-45ae-9bde-03faaf604bba")] - public static extern SocketError WSAStringToAddress([MarshalAs(UnmanagedType.LPTStr)] string AddressString, ADDRESS_FAMILY AddressFamily, [In, Optional] IntPtr lpProtocolInfo, [Out] IntPtr lpAddress, ref int lpAddressLength); + public static extern WSRESULT WSAStringToAddress([MarshalAs(UnmanagedType.LPTStr)] string AddressString, ADDRESS_FAMILY AddressFamily, [In, Optional] IntPtr lpProtocolInfo, [Out] IntPtr lpAddress, ref int lpAddressLength); /// /// The WSAStringToAddress function converts a network address in its standard text presentation form into its numeric binary diff --git a/PInvoke/Ws2_32/WinSock2.legacy.cs b/PInvoke/Ws2_32/WinSock2.legacy.cs index 72e08f63..6a838eaa 100644 --- a/PInvoke/Ws2_32/WinSock2.legacy.cs +++ b/PInvoke/Ws2_32/WinSock2.legacy.cs @@ -517,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 SocketError bind(SOCKET s, [In] SOCKADDR addr, int namelen); + public static extern WSRESULT bind(SOCKET s, [In] SOCKADDR addr, int namelen); /// The closesocket function closes an existing socket. /// A descriptor identifying the socket to close. @@ -787,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 SocketError closesocket([In] SOCKET s); + public static extern WSRESULT closesocket([In] SOCKET s); /// The connect function establishes a connection to a specified socket. /// A descriptor identifying an unconnected socket. @@ -1018,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 SocketError connect(SOCKET s, SOCKADDR name, int namelen); + public static extern WSRESULT 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. @@ -1090,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 SocketError gethostname(StringBuilder name, int namelen); + public static extern WSRESULT 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. @@ -1166,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 SocketError GetHostNameW(StringBuilder name, int namelen); + public static extern WSRESULT 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. @@ -1232,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 SocketError getpeername(SOCKET s, SOCKADDR name, ref int namelen); + public static extern WSRESULT 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. @@ -1722,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 SocketError getsockname(SOCKET s, SOCKADDR name, ref int namelen); + public static extern WSRESULT getsockname(SOCKET s, SOCKADDR name, ref int namelen); /// The getsockopt function retrieves a socket option. /// A descriptor identifying a socket. @@ -2157,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 SocketError getsockopt(SOCKET s, int level, int optname, [Optional] IntPtr optval, ref int optlen); + public static extern WSRESULT 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. @@ -2421,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 SocketError ioctlsocket(SOCKET s, int cmd, IntPtr argp); + public static extern WSRESULT 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. @@ -2555,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 SocketError listen(SOCKET s, int backlog); + public static extern WSRESULT 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). @@ -2818,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 SocketError recv(SOCKET s, IntPtr buf, int len, MsgFlags flags); + public static extern WSRESULT 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. @@ -3001,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 SocketError recvfrom(SOCKET s, IntPtr buf, int len, int flags, SOCKADDR from, ref int fromlen); + public static extern WSRESULT 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. @@ -3182,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 SocketError select([Optional] int nfds, ref fd_set readfds, ref fd_set writefds, ref fd_set exceptfds, in TIMEVAL timeout); + public static extern WSRESULT 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. @@ -3363,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 SocketError 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 WSRESULT 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. @@ -3559,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 SocketError send(SOCKET s, IntPtr buf, int len, int flags); + public static extern WSRESULT 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. @@ -3792,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 SocketError sendto(SOCKET s, IntPtr buf, int len, int flags, SOCKADDR to, int tolen); + public static extern WSRESULT 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. @@ -4146,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 SocketError setsockopt(SOCKET s, int level, int optname, IntPtr optval, int optlen); + public static extern WSRESULT setsockopt(SOCKET s, int level, int optname, IntPtr optval, int optlen); /// The setsockopt function sets a socket option. /// A descriptor that identifies a socket. @@ -4498,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 SocketError setsockopt(SOCKET s, TLvl level, int optname, in TIn optval) where TIn : struct where TLvl : IConvertible + public static WSRESULT 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); @@ -4686,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 SocketError shutdown(SOCKET s, SD how); + public static extern WSRESULT 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 93016dcf..29c9d3b7 100644 --- a/PInvoke/Ws2_32/ws2spi.cs +++ b/PInvoke/Ws2_32/ws2spi.cs @@ -84,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 SocketError LPNSPV2CLEANUP(in Guid lpProviderId, IntPtr pvClientSessionArg); + public delegate WSRESULT LPNSPV2CLEANUP(in Guid lpProviderId, IntPtr pvClientSessionArg); /// /// The NSPv2ClientSessionRundown function notifies a namespace service provider version-2 (NSPv2) provider that the client @@ -445,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 SocketError LPNSPV2LOOKUPSERVICEBEGIN(in Guid lpProviderId, in WSAQUERYSET2W lpqsRestrictions, uint dwControlFlags, IntPtr lpvClientSessionArg, out HANDLE lphLookup); + public delegate WSRESULT 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. @@ -494,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 SocketError LPNSPV2LOOKUPSERVICEEND(HANDLE hLookup); + public delegate WSRESULT LPNSPV2LOOKUPSERVICEEND(HANDLE hLookup); /// /// The NSPv2LookupServiceNextEx function is called after obtaining a handle from a previous call to NSPv2LookupServiceBegin @@ -1046,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 SocketError LPNSPV2STARTUP(in Guid lpProviderId, out IntPtr ppvClientSessionArg); + public delegate WSRESULT 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. @@ -1170,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 SocketError WPUCompleteOverlappedRequest(SOCKET s, ref WSAOVERLAPPED lpOverlapped, uint dwError, uint cbTransferred, out int lpErrno); + public static extern WSRESULT 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. @@ -1262,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 SocketError WSAAdvertiseProvider(in Guid puuidProviderId, in NSPV2_ROUTINE pNSPv2Routine); + public static extern WSRESULT WSAAdvertiseProvider(in Guid puuidProviderId, in NSPV2_ROUTINE pNSPv2Routine); /// /// The WSAProviderCompleteAsyncCall function notifies a client when an asynchronous call to a namespace version-2 provider @@ -1326,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 SocketError WSAProviderCompleteAsyncCall(HANDLE hAsyncCall, int iRetCode); + public static extern WSRESULT WSAProviderCompleteAsyncCall(HANDLE hAsyncCall, int iRetCode); /// /// The WSAUnadvertiseProvider function makes a specific namespace version-2 provider no longer available for clients. @@ -1368,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 SocketError WSAUnadvertiseProvider(in Guid puuidProviderId); + public static extern WSRESULT WSAUnadvertiseProvider(in Guid puuidProviderId); /// /// The WSCDeinstallProvider function removes the specified transport provider from the system configuration database. @@ -1442,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 SocketError WSCDeinstallProvider(in Guid lpProviderId, out int lpErrno); + public static extern WSRESULT WSCDeinstallProvider(in Guid lpProviderId, out int lpErrno); /// /// The WSCDeinstallProvider32 function removes the specified 32-bit transport provider from the system configuration database. @@ -1522,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 SocketError WSCDeinstallProvider32(in Guid lpProviderId, out int lpErrno); + public static extern WSRESULT 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 @@ -1591,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 SocketError WSCEnableNSProvider(in Guid lpProviderId, [MarshalAs(UnmanagedType.Bool)] bool fEnable); + public static extern WSRESULT 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 @@ -1666,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 SocketError WSCEnableNSProvider32(in Guid lpProviderId, [MarshalAs(UnmanagedType.Bool)] bool fEnable); + public static extern WSRESULT WSCEnableNSProvider32(in Guid lpProviderId, [MarshalAs(UnmanagedType.Bool)] bool fEnable); /// The WSCEnumNameSpaceProviders32 function returns information on available 32-bit namespace providers. /// @@ -1726,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 SocketError WSCEnumNameSpaceProviders32(ref uint lpdwBufferLength, [In, Out] IntPtr lpnspBuffer); + public static extern WSRESULT WSCEnumNameSpaceProviders32(ref uint lpdwBufferLength, [In, Out] IntPtr lpnspBuffer); /// The WSCEnumNameSpaceProvidersEx32 function retrieves information on available 32-bit namespace providers. /// @@ -1795,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 SocketError WSCEnumNameSpaceProvidersEx32(ref uint lpdwBufferLength, [In, Out] IntPtr lpnspBuffer); + public static extern WSRESULT WSCEnumNameSpaceProvidersEx32(ref uint lpdwBufferLength, [In, Out] IntPtr lpnspBuffer); /// The WSCEnumProtocols function retrieves information about available transport protocols. /// @@ -1876,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 SocketError WSCEnumProtocols([Optional, MarshalAs(UnmanagedType.LPArray)] int[] lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength, out int lpErrno); + public static extern WSRESULT WSCEnumProtocols([Optional, MarshalAs(UnmanagedType.LPArray)] int[] lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength, out int lpErrno); /// The WSCEnumProtocols32 function retrieves information about available transport protocols. /// @@ -1963,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 SocketError WSCEnumProtocols32([Optional, MarshalAs(UnmanagedType.LPArray)] int[] lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength, out int lpErrno); + public static extern WSRESULT WSCEnumProtocols32([Optional, MarshalAs(UnmanagedType.LPArray)] int[] lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength, out int lpErrno); /// /// @@ -2152,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 SocketError WSCGetApplicationCategory([MarshalAs(UnmanagedType.LPWStr)] string Path, uint PathLength, [MarshalAs(UnmanagedType.LPWStr)] string Extra, uint ExtraLength, out uint pPermittedLspCategories, out int lpErrno); + public static extern WSRESULT 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. @@ -2322,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 SocketError WSCGetProviderInfo(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, [Out] IntPtr Info, ref SizeT InfoSize, uint Flags, out int lpErrno); + public static extern WSRESULT 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. @@ -2498,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 SocketError WSCGetProviderInfo32(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, [Out] IntPtr Info, ref SizeT InfoSize, uint Flags, out int lpErrno); + public static extern WSRESULT 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. /// @@ -2541,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 SocketError WSCGetProviderPath(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszProviderDllPath, ref int lpProviderDllPathLen, out int lpErrno); + public static extern WSRESULT 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. @@ -2590,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 SocketError WSCGetProviderPath32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszProviderDllPath, ref int lpProviderDllPathLen, out int lpErrno); + public static extern WSRESULT 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 @@ -2669,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 SocketError WSCInstallNameSpace([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId); + public static extern WSRESULT 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 @@ -2756,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 SocketError WSCInstallNameSpace32([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId); + public static extern WSRESULT 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 @@ -2845,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 SocketError WSCInstallNameSpaceEx([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId, in BLOB lpProviderSpecific); + public static extern WSRESULT WSCInstallNameSpaceEx([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId, in BLOB lpProviderSpecific); /// /// @@ -2947,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 SocketError WSCInstallNameSpaceEx32([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId, in BLOB lpProviderSpecific); + public static extern WSRESULT 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. @@ -3074,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 SocketError WSCInstallProvider(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); + public static extern WSRESULT 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.] @@ -3213,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 SocketError WSCInstallProvider64_32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); + public static extern WSRESULT 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). @@ -3408,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 SocketError WSCInstallProviderAndChains64_32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPWStr)] string lpszLspName, XP1 dwServiceFlags, + public static extern WSRESULT 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); /// @@ -3617,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 SocketError 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 WSRESULT 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. @@ -3787,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 SocketError WSCSetProviderInfo(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, IntPtr Info, SizeT InfoSize, uint Flags, out int lpErrno); + public static extern WSRESULT 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. @@ -3957,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 SocketError WSCSetProviderInfo32(in Guid lpProviderId, WSC_PROVIDER_INFO_TYPE InfoType, IntPtr Info, SizeT InfoSize, uint Flags, out int lpErrno); + public static extern WSRESULT 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. @@ -4023,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 SocketError WSCUnInstallNameSpace(in Guid lpProviderId); + public static extern WSRESULT 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. @@ -4095,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 SocketError WSCUnInstallNameSpace32(in Guid lpProviderId); + public static extern WSRESULT 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. @@ -4185,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 SocketError WSCUpdateProvider(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); + public static extern WSRESULT 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. @@ -4285,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 SocketError WSCUpdateProvider32(in Guid lpProviderId, [MarshalAs(UnmanagedType.LPWStr)] string lpszProviderDllPath, [MarshalAs(UnmanagedType.LPArray)] WSAPROTOCOL_INFOW[] lpProtocolInfoList, uint dwNumberOfEntries, out int lpErrno); + public static extern WSRESULT 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 2b62313d..cb612367 100644 --- a/PInvoke/Ws2_32/ws2tcpip.cs +++ b/PInvoke/Ws2_32/ws2tcpip.cs @@ -141,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 SocketError GetAddrInfoExCancel(in HANDLE lpHandle); + public static extern WSRESULT GetAddrInfoExCancel(in HANDLE lpHandle); /// /// The GetAddrInfoExOverlappedResult function gets the return code for an OVERLAPPED structure used by an @@ -170,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 SocketError GetAddrInfoExOverlappedResult(IntPtr lpOverlapped); + public static extern WSRESULT GetAddrInfoExOverlappedResult(IntPtr lpOverlapped); /// /// The GetAddrInfoExOverlappedResult function gets the return code for an OVERLAPPED structure used by an @@ -199,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 SocketError GetAddrInfoExOverlappedResult(NativeOverlapped* lpOverlapped); + public static unsafe extern WSRESULT GetAddrInfoExOverlappedResult(NativeOverlapped* lpOverlapped); /// /// The GetAddrInfoEx function provides protocol-independent name resolution with additional parameters to qualify which @@ -865,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 SocketError GetAddrInfoExW([Optional, MarshalAs(UnmanagedType.LPWStr)] string pName, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pServiceName, + public static unsafe extern WSRESULT 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); @@ -1345,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 SocketError GetAddrInfoW([Optional] string pNodeName, [Optional] string pServiceName, [Optional] in ADDRINFOW pHints, out SafeADDRINFOWArray ppResult); + public static extern WSRESULT 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. @@ -1420,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 SocketError getipv4sourcefilter(SOCKET Socket, IN_ADDR Interface, IN_ADDR Group, out MULTICAST_MODE_TYPE FilterMode, ref int SourceCount, IN_ADDR[] SourceList) + public static WSRESULT 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(System.Net.Sockets.SocketError.NoBufferSpaceAvailable); - return System.Net.Sockets.SocketError.SocketError; + WSASetLastError(WSRESULT.WSAENOBUFS); + return SOCKET_ERROR; } var Filter = new IP_MSFILTER @@ -1644,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 SocketError GetNameInfoW([In] SOCKADDR pSockaddr, int SockaddrLength, StringBuilder pNodeBuffer, uint NodeBufferSize, StringBuilder pServiceBuffer, uint ServiceBufferSize, NI Flags); + public static extern WSRESULT 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. @@ -1710,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 SocketError getsourcefilter(SOCKET Socket, uint Interface, [In] SOCKADDR Group, int GroupLength, out MULTICAST_MODE_TYPE FilterMode, ref int SourceCount, SOCKADDR_STORAGE[] SourceList) + public static WSRESULT 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(System.Net.Sockets.SocketError.NoBufferSpaceAvailable); - return System.Net.Sockets.SocketError.SocketError; + WSASetLastError(WSRESULT.WSAENOBUFS); + return SOCKET_ERROR; } var Filter = new GROUP_FILTER @@ -2163,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 SocketError inet_pton(ADDRESS_FAMILY Family, string pszAddrString, out IN_ADDR pAddrBuf); + public static extern WSRESULT 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 @@ -2306,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 SocketError inet_pton(ADDRESS_FAMILY Family, string pszAddrString, out IN6_ADDR pAddrBuf); + public static extern WSRESULT 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 @@ -2727,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 SocketError InetPtonW(ADDRESS_FAMILY Family, [MarshalAs(UnmanagedType.LPWStr)] string pszAddrString, out IN_ADDR pAddrBuf); + public static extern WSRESULT 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 @@ -2870,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 SocketError InetPtonW(ADDRESS_FAMILY Family, [MarshalAs(UnmanagedType.LPWStr)] string pszAddrString, out IN6_ADDR pAddrBuf); + public static extern WSRESULT 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 @@ -3046,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 SocketError SetAddrInfoEx([MarshalAs(UnmanagedType.LPTStr)] string pName, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pServiceName, + public static extern WSRESULT 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); @@ -3224,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 SocketError SetAddrInfoEx([MarshalAs(UnmanagedType.LPTStr)] string pName, [Optional, MarshalAs(UnmanagedType.LPTStr)] string pServiceName, + public static unsafe extern WSRESULT 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); @@ -3282,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 SocketError setipv4sourcefilter(SOCKET Socket, IN_ADDR Interface, IN_ADDR Group, MULTICAST_MODE_TYPE FilterMode, uint SourceCount, IN_ADDR[] SourceList) + public static WSRESULT setipv4sourcefilter(SOCKET Socket, IN_ADDR Interface, IN_ADDR Group, MULTICAST_MODE_TYPE FilterMode, uint SourceCount, IN_ADDR[] SourceList) { if (SourceCount > SourceList.Length) { - WSASetLastError(System.Net.Sockets.SocketError.NoBufferSpaceAvailable); - return System.Net.Sockets.SocketError.SocketError; + WSASetLastError(WSRESULT.WSAENOBUFS); + return SOCKET_ERROR; } var Filter = new IP_MSFILTER @@ -3346,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 SocketError setsourcefilter(SOCKET Socket, uint Interface, [In] SOCKADDR Group, int GroupLength, MULTICAST_MODE_TYPE FilterMode, uint SourceCount, SOCKADDR_STORAGE[] SourceList) + public static WSRESULT 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(System.Net.Sockets.SocketError.NoBufferSpaceAvailable); - return System.Net.Sockets.SocketError.SocketError; + WSASetLastError(WSRESULT.WSAENOBUFS); + return SOCKET_ERROR; } var Filter = new GROUP_FILTER