using System;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
using Vanara.InteropServices;
namespace Vanara.PInvoke
{
public static partial class Ws2_32
{
///
/// The NSPv2Cleanup function notifies a namespace service provider version-2 (NSPv2) provider that a client session has terminated.
///
/// A pointer to the GUID of the namespace provider to be notified.
/// A pointer to the client session.
///
///
/// The function should return NO_ERROR (zero) if the routine succeeds. It should return SOCKET_ERROR (that is, 1) if
/// the routine fails and it must set the appropriate error code using WSASetLastError.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
/// There is not enough memory available to perform this operation.
///
/// -
/// WSAEACCES
/// The calling routine does not have sufficient privileges to initialize the service.
///
/// -
/// WSAEINVAL
/// One or more parameters were invalid, or missing, for this provider.
///
/// -
/// WSAEOPNOTSUPP
/// The operation is not supported. This error is returned if the namespace provider does not implement this function.
///
/// -
/// WSASERVICE_NOT_FOUND
/// Service is unknown. The service cannot be found in the specified namespace.
///
///
///
///
///
/// The NSPv2Cleanup function is used as part of the namespace service provider version-2 (NSPv2) architecture available on
/// Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the NSPv2Cleanup function can only be used for operations on NS_EMAIL namespace providers.
///
///
/// The NSPv2Startup function is called each time a new client process begins using namespace provider. Providers may use the client
/// session argument pointed to by the ppvClientSessionArg parameter to store information about this session. If a value was
/// specified for the client session argument in the call to the NSPv2Startup function, then this same client session
/// argument can be passed in the pvClientSessionArg parameter to the NSPv2Cleanup function to notify namespace provider that
/// the client session has terminated.
///
///
/// The NSPv2Cleanup function is called when an application is finished using a Windows Sockets namespace service provider.
/// The NSPv2Cleanup allows the namespace provider to free any of namespace provider resources that were allocated for the
/// client session.
///
///
/// The NSPv2Startup function must be called successfully before calling the NSPv2Cleanup function. It is permissible to make
/// more than one NSPv2Startup call. However, for each NSPv2Startup call, a corresponding NSPv2Cleanup call
/// must also be issued. Only the final NSPv2Cleanup for the service provider does the actual cleanup; the preceding calls
/// decrement an internal reference count in the service provider.
///
///
/// The NSPv2Startup, NSPv2ClientSessionRundown, and NSPv2Cleanup functions are optional, dependent on the requirements of
/// the NSPv2 provider.
///
///
/// If the NSPv2Cleanup function isn't implemented, then calls to that function should be intercepted by a stub function that
/// returns WSAEOPNOTSUPP. The NSPv2 function pointer to the unimplemented NSPv2Cleanup function in the NSPV2_ROUTINE
/// structure should point be to the stub function.
///
///
// 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 WSRESULT LPNSPV2CLEANUP(in Guid lpProviderId, IntPtr pvClientSessionArg);
///
/// The NSPv2ClientSessionRundown function notifies a namespace service provider version-2 (NSPv2) provider that the client
/// session is terminating.
///
/// A pointer to the GUID of the specific namespace provider to notify.
/// A pointer to the client session that is terminating.
///
///
/// The function should return NO_ERROR (zero) if the routine succeeds. It should return SOCKET_ERROR (that is, 1) if
/// the routine fails and it must set the appropriate error code using WSASetLastError.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
/// There is not enough memory available to perform this operation.
///
/// -
/// WSAEACCES
/// The calling routine does not have sufficient privileges to install the service.
///
/// -
/// WSAEINVAL
/// One or more parameters were invalid, or missing, for this provider.
///
/// -
/// WSAEOPNOTSUPP
///
/// The operation is not supported. This error is returned if the namespace provider does not implement this function. This error
/// can also be returned if the specified dwControlCode is an unrecognized command.
///
///
/// -
/// WSASERVICE_NOT_FOUND
/// Service is unknown. The service cannot be found in the specified namespace.
///
///
///
///
///
/// The NSPv2ClientSessionRundown function is used as part of the namespace service provider version-2 (NSPv2) architecture
/// available on Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the NSPv2ClientSessionRundown function can only be used for operations on
/// NS_EMAIL namespace providers.
///
///
/// The NSPv2Startup function is called each time a new client process begins using namespace provider. Providers may use the client
/// session argument pointed to by the ppvClientSessionArg parameter to store information about this session. If a value was
/// specified for the client session argument in the call to the NSPv2Startup function, then this same client session
/// argument is passed in the pvClientSessionArg parameter to the NSPv2ClientSessionRundown function.
///
///
/// The NSPv2Startup, NSPv2ClientSessionRundown, and NSPv2Cleanup functions are optional, dependent on the requirements of
/// the NSPv2 provider.
///
///
/// If the NSPv2ClientSessionRundown function isn't implemented, then calls to that function should be intercepted by a stub
/// function that returns WSAEOPNOTSUPP. The NSPv2 function pointer to the unimplemented NSPv2ClientSessionRundown function
/// in the NSPV2_ROUTINE structure should point be to the stub function.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nc-ws2spi-lpnspv2clientsessionrundown LPNSPV2CLIENTSESSIONRUNDOWN
// Lpnspv2clientsessionrundown; void Lpnspv2clientsessionrundown( LPGUID lpProviderId, LPVOID pvClientSessionArg ) {...}
[PInvokeData("ws2spi.h", MSDNShortId = "7379b502-129a-4dac-b7eb-e6fae8fb23f8")]
public delegate void LPNSPV2CLIENTSESSIONRUNDOWN(in Guid lpProviderId, IntPtr pvClientSessionArg);
///
/// The NSPv2LookupServiceBegin function initiates a client query of a namespace version-2 service provider that is constrained by
/// the information contained within a WSAQUERYSET2 structure.
///
/// A pointer to the identifier for the namespace service provider to query.
/// A pointer to the search criteria. See Remarks.
///
///
/// A set of flags that affect the search. This parameter can be a combination of the following values defined in the Winsock2.h
/// header file.
///
///
///
/// Value
/// Meaning
///
/// -
/// LUP_DEEP 0x0001
/// Queries down the hierarchy of a provider as opposed to just the first level.
///
/// -
/// LUP_CONTAINERS 0x0002
/// Returns containers only.
///
/// -
/// LUP_NOCONTAINERS 0x0004
/// Returns no containers.
///
/// -
/// LUP_NEAREST 0x0008
/// If possible, returns results in the order of distance. The measure of distance is provider specific.
///
/// -
/// LUP_RETURN_NAME 0x0010
/// Retrieves the name as **lpszServiceInstanceName**.
///
/// -
/// LUP_RETURN_TYPE 0x0020
/// Retrieves the type as **lpServiceClassId**.
///
/// -
/// LUP_RETURN_VERSION 0x0040
/// Retrieves the version as **lpVersion**.
///
/// -
/// LUP_RETURN_COMMENT 0x0080
/// Retrieves the comment as **lpszComment**.
///
/// -
/// LUP_RETURN_ADDR 0x0100
/// Retrieves the addresses as **lpcsaBuffer**.
///
/// -
/// LUP_RETURN_BLOB 0x0200
/// Retrieves the private data as **lpBlob**.
///
/// -
/// LUP_RETURN_ALIASES 0x0400
///
/// Any available alias information is to be returned in successive calls to NSPv2LookupServiceNextEx, and each alias returned will
/// have the **RESULT_IS_ALIAS** flag set.
///
///
/// -
/// LUP_RETURN_QUERY_STRING 0x0800
/// Retrieves the query string as **lpszQueryString**.
///
/// -
/// LUP_RETURN_ALL 0x0ff0
/// Retrieves information including the name, type, version, comment, address, blob, aliases, and query string.
///
/// -
/// LUP_FLUSHCACHE 0x1000
/// If the provider has cached information, ignore the cache and query the namespace itself.
///
/// -
/// LUP_FLUSHPREVIOUS 0x2000
///
/// Used as a value for the dwControlFlags parameter in NSPv2LookupServiceNextEx. Setting this flag instructs the provider to
/// discard the last result set, which was too large for the supplied buffer, and move on to the next result set.
///
///
/// -
/// LUP_NON_AUTHORITATIVE 0x4000
/// Indicates that the namespace provider should included non-authoritative results for names.
///
/// -
/// LUP_RES_RESERVICE 0x8000
///
/// Indicates whether prime response is in the remote or local part of CSADDR_INFO structure. The other part must be usable in
/// either case. This option applies only to service instance requests.
///
///
/// -
/// LUP_SECURE 0x8000
/// Indicates that the namespace provider should use a secure query. This option only applies to name query requests.
///
/// -
/// LUP_RETURN_PREFERRED_NAMES 0x10000
/// Indicates that the namespace provider should return only preferred names.
///
/// -
/// LUP_ADDRCONFIG 0x100000
/// Indicates that the namespace provider should return the address configuration.
///
/// -
/// LUP_DUAL_ADDR 0x200000
///
/// Indicates that the namespace provider should return the dual addresses. This option only applies to dual-mode sockets (IPv6 and
/// IPv4 mapped addresses).
///
///
/// -
/// LUP_DISABLE_IDN_ENCODING 0x800000
///
/// Indicates that the namespace provider should disable automatic International Domain Names encoding. This value is supported on
/// Windows 8 and Windows Server 2012
///
///
///
///
/// A pointer to the client session.
///
/// A pointer to the handle to be used in subsequent calls to NSPv2LookupServiceNextEx in order to retrieve the results set.
///
///
///
/// The function should return NO_ERROR (zero) if the routine succeeds. It should return SOCKET_ERROR (that is, 1) if
/// the routine fails and it must set the appropriate error code using WSASetLastError.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEINVAL
/// One or more parameters were invalid, or missing, for this provider.
///
/// -
/// WSANO_DATA
/// The name was found in the database, but it does not have the correct associated data that is resolved for.
///
/// -
/// WSASERVICE_NOT_FOUND
/// The service is unknown. The service cannot be found in the specified namespace.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
/// There is not enough memory available to perform this operation.
///
///
///
///
///
/// The NSPv2LookupServiceBegin function is used as part of the namespace service provider version-2 (NSPv2) architecture available
/// on Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the NSPv2LookupServiceBegin function can only be used for operations on NS_EMAIL
/// namespace providers.
///
///
/// The NSPv2LookupServiceBegin function only returns a handle, which should be used by subsequent calls to NSPv2LookupServiceNextEx
/// to get the actual results. Because this operation cannot be canceled, it should be implemented to execute quickly. While it is
/// acceptable to initiate a network query, this function should not require a response to return successfully.
///
///
/// The NSPv2Startup function is called each time a new client process begins using namespace provider. Providers may use the client
/// session argument pointed to by the ppvClientSessionArg parameter to store information about this session. If a value was
/// specified for the client session argument in the call to the NSPv2Startup function, then this same client session
/// argument is passed in the lpvClientSessionArg parameter to the NSPv2LookupServiceBegin function.
///
///
/// If LUP_CONTAINERS is specified in a call, avoid all other restriction values. If any are supplied, the name service
/// provider must decide if it can support this restriction over the containers. If not, it should return an error.
///
///
/// Some name service providers may have other means of finding containers. For example, containers can all be of some well-known
/// type, or of a set of well-known types, and therefore a query restriction could be created for finding them. No matter what other
/// means the name service provider has for locating containers, LUP_CONTAINERS and LUP_NOCONTAINERS take precedence.
/// Therefore, if a query restriction is given that includes containers, specifying LUP_NOCONTAINERS will prevent the
/// container items from being returned. Similarly, no matter what the query restriction, if LUP_CONTAINERS is given, only
/// containers should be returned. If a namespace does not support containers and LUP_CONTAINERS is specified, it should
/// return WSANO_DATA.
///
/// The preferred method of obtaining the containers within another container, is the call:
///
/// followed by the requisite number of NSPv2LookupServiceNextEx calls. This will return all containers contained immediately within
/// the starting context; that is, it is not a deep query. With this, one can map the address space structure by walking the
/// hierarchy, perhaps enumerating the content of selected containers. Subsequent uses of NSPv2LookupServiceBegin use the containers
/// returned from a previous call.
///
/// Forming Queries
///
/// The WSAQUERYSET2 structure is used as an input parameter to NSPv2LookupServiceBegin to qualify the query. The following table
/// lists **WSAQUERYSET2** member names and describes how the **WSAQUERYSET2** is used to construct a query. Members labeled as
/// optional and dependent on the requirements of the NSPv2 provider may be supplied as a **NULL** pointer when unused as a search
/// criteria by the namespace provider. For more information, see Query-Related Data Structures.
///
///
///
/// WSAQUERYSET2 member name
/// Query interpretation
///
/// -
/// **dwSize**
/// Will be set to sizeof(WSAQUERYSET2). This is a versioning mechanism.
///
/// -
/// **lpszServiceInstanceName**
///
/// A string that contains the service name. The semantics for wildcarding within the string are not defined, but can be supported
/// by certain namespace providers. This member is optional, dependent on the requirements of the NSPv2 service provider.
///
///
/// -
/// **lpVersion**
///
/// The desired version number that provides version comparison semantics (that is, version must match exactly, or version must be
/// not less than the value supplied). This member is optional, dependent on the requirements of the NSPv2 service provider.
///
///
/// -
/// **lpszComment**
/// This member is ignored for queries.
///
/// -
/// **dwNameSpace**
/// The identifier of a single namespace in which to constrain the search, or **NS_ALL** to include all namespaces.
///
/// -
/// **lpNSProviderId**
///
/// The GUID of a specific namespace provider that limits the query to this provider only. This member is optional, dependent on the
/// requirements of the NSPv2 service provider.
///
///
/// -
/// **lpszContext**
///
/// The starting point of the query in a hierarchical namespace. This member is optional, dependent on the requirements of the NSPv2
/// service provider.
///
///
/// -
/// **dwNumberOfProtocols**
/// The size, in bytes, of the number of entries in the protocol constraint array. This member can be zero.
///
/// -
/// **lpafpProtocols**
///
/// An array of AFPROTOCOLS structures. Only services that use these protocols will be returned. It is permissable for the value
/// **AF_UNSPEC** to appear as a protocol family value, signifying a wildcard. Namespace providers may supply information about any
/// service that uses the corresponding protocol, regardless of address family. This member is optional, dependent on the
/// requirements of the NSPv2 service provider.
///
///
/// -
/// **lpszQueryString**
///
/// Some namespaces (such as whois++) support rich SQL-like queries contained in a simple text string. This parameter is used to
/// specify that string.This member is optional, dependent on the requirements of the NSPv2 service provider.
///
///
/// -
/// **dwNumberOfCsAddrs**
/// This member is ignored for queries.
///
/// -
/// **lpcsaBuffer**
/// This member is ignored for queries.
///
/// -
/// **dwOutputFlags**
/// This member is ignored for queries.
///
/// -
/// **lpBlob**
/// A pointer to a provider-specific entity. This member is optional, dependent on the requirements of the NSPv2 service provider.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nc-ws2spi-lpnspv2lookupservicebegin LPNSPV2LOOKUPSERVICEBEGIN
// Lpnspv2lookupservicebegin; INT Lpnspv2lookupservicebegin( LPGUID lpProviderId, LPWSAQUERYSET2W lpqsRestrictions, DWORD
// dwControlFlags, LPVOID lpvClientSessionArg, LPHANDLE lphLookup ) {...}
[PInvokeData("ws2spi.h", MSDNShortId = "5664b85d-8432-4068-aa97-caa57d9377ac")]
[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Unicode)]
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.
///
/// The handle obtained previously by a call to NSPv2LookupServiceBegin.
///
///
/// The function should return NO_ERROR (zero) if the routine succeeds. It should return SOCKET_ERROR (that is, 1) if
/// the routine fails and it must set the appropriate error code using WSASetLastError.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSA_INVALID_HANDLE
/// The handle is not valid.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
/// There is not enough memory available to perform this operation.
///
///
///
///
///
/// The NSPv2LookupServiceEnd function is used as part of the namespace service provider version-2 (NSPv2) architecture
/// available on Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the NSPv2LookupServiceEnd function can only be used for operations on NS_EMAIL
/// namespace providers.
///
///
/// It is possible to receive an NSPv2LookupServiceBegin function call on another thread while processing an
/// NSPv2LookupServiceNextEx. This indicates that the client has canceled the request and the provider should close the handle and
/// return from the NSPv2LookupServiceNextEx function call as well, setting the last error to WSA_E_CANCELLED.
///
///
/// In Windows Sockets 2, conflicting error codes are defined for WSAECANCELLED and WSA_E_CANCELLED. The error code
/// WSAECANCELLED will be removed in a future version and only WSA_E_CANCELLED will remain. Namespace Providers should use
/// the WSA_E_CANCELLED error code to maintain compatibility with the widest possible range of applications.
///
///
// 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 WSRESULT LPNSPV2LOOKUPSERVICEEND(HANDLE hLookup);
///
/// The NSPv2LookupServiceNextEx function is called after obtaining a handle from a previous call to NSPv2LookupServiceBegin
/// in order to retrieve the requested information from a namespace version-2 service provider.
///
/// A handle returned from the previous call to NSPv2LookupServiceBegin used for asynchronous calls.
/// A handle returned from the previous call to NSPv2LookupServiceBegin.
///
/// The flags used to control the next operation. Currently, only LUP_FLUSHPREVIOUS is defined as a means to handle a result
/// set that is too large. If an application cannot supply a large enough buffer, setting LUP_FLUSHPREVIOUS instructs the
/// provider to discard the last result set, which was too large, and move to the next set for this call.
///
///
/// The size, in bytes, on input, that is contained in the buffer pointed to by lpqsResults. On output, if the function fails and
/// the error is WSAEFAULT, then it contains the minimum size, in bytes to pass for the lpqsResults to retrieve the record.
///
/// A pointer to a memory block that will contain, on return, one result set in a WSAQUERYSET2 structure.
///
///
/// The function should return NO_ERROR (zero) if the routine succeeds. It should return SOCKET_ERROR (that is, 1) if
/// the routine fails and it must set the appropriate error code using WSASetLastError.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSA_E_CANCELLED
///
/// A call to NSPv2LookupServiceEnd was made while this call was still processing. The call has been canceled. The data in the
/// lpqsResults buffer is undefined. In Windows Sockets 2, conflicting error codes are defined for WSAECANCELLED (10103) and
/// WSA_E_CANCELLED (10111).The error code WSAECANCELLED will be removed in a future version and only WSA_E_CANCELLED will remain.
/// Namespace providers should use the WSA_E_CANCELLED error code to maintain compatibility with the widest possible range of applications.
///
///
/// -
/// WSA_E_NO_MORE
///
/// There is no more data available. In Windows Sockets 2, conflicting error codes are defined for WSAENOMORE (10102) and
/// WSA_E_NO_MORE (10110).The error code WSAENOMORE will be removed in a future version and only WSA_E_NO_MORE will remain.
/// Namespace providers should use the WSA_E_NO_MORE error code to maintain compatibility with the widest possible range of applications.
///
///
/// -
/// WSAEFAULT
/// The lpqsResults buffer was too small to contain a WSAQUERYSET set.
///
/// -
/// WSAEINVAL
/// One or more parameters are invalid, or missing, for this provider.
///
/// -
/// WSA_INVALID_HANDLE
/// The specified lookup handle is invalid.
///
/// -
/// WSANO_DATA
/// The name was found in the database, but no data, matching the given restrictions, was located.
///
/// -
/// WSASERVICE_NOT_FOUND
/// The service is unknown. The service cannot be found in the specified namespace.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
/// There is not enough memory available to perform this operation.
///
///
///
///
///
/// The NSPv2LookupServiceNextEx function is used as part of the namespace service provider version-2 (NSPv2) architecture
/// available on Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the NSPv2LookupServiceNextEx function can only be used for operations on
/// NS_EMAIL namespace providers.
///
///
/// The provider will pass a WSAQUERYSET2 structure in the lpqsResults buffer. The client should call the
/// NSPv2LookupServiceNextEx function until it returns WSA_E_NOMORE, indicating that all the WSAQUERYSET2
/// structures have been returned.
///
///
/// The dwControlFlags specified in this function and the ones specified at the time of NSPv2LookupServiceBegin are handled as
/// "restrictions" for the purpose of combination. The restrictions are combined between the ones at NSPv2LookupServiceBegin
/// time and the ones at NSPv2LookupServiceNextEx time. Therefore, the flags at NSPv2LookupServiceNextEx can never
/// increase the amount of data returned beyond what was requested at NSPv2LookupServiceBegin, although it is not an error to
/// specify more or less flags. The flags specified at a given NSPv2LookupServiceNextEx apply only to that call.
///
///
/// The dwControlFlags LUP_FLUSHPREVIOUS and LUP_RES_SERVICE are exceptions to the combined restrictions rule (because
/// they are behavior flags instead of "restriction" flags). If either flag is used in NSPv2LookupServiceNextEx, they have
/// their defined effect regardless of the setting of the same flags at NSPv2LookupServiceBegin.
///
///
/// For example, if LUP_RETURN_VERSION is specified at NSPv2LookupServiceBegin, the service provider retrieves records
/// including the version. If LUP_RETURN_VERSION is not specified at NSPv2LookupServiceNextEx, the returned
/// information does not include the version, even though it was available. No error is generated.
///
///
/// Also for example, if LUP_RETURN_BLOB is not specified at NSPv2LookupServiceBegin, but is specified at
/// NSPv2LookupServiceNextEx, the returned information does not include the private data. No error is generated.
///
///
/// The NSPv2LookupServiceNextEx function is typically called at least twice. The first time to get the size of the needed
/// buffer to receive the WSAQUERYSET2 pointed to by the lpqsResults parameter, and the second time to get the actual query result
/// set. On the first call, the NSPv2 provider should return the size necessary for the WSAQUERYSET2 results.
///
///
/// The WSAQUERYSET2 structure pointed to by the lpqsResults parameter that is returned is only useful in the same process context,
/// since several of the members in the WSAQUERYSET2 structure contains pointers to the actual data returned. If the query
/// result needs to be passed to another process (using RPC, for example), then it will be necessary to serialize and marshal the
/// data returned in the WSAQUERYSET2 structure pointed to by the lpqsResults parameter including the data pointed to by
/// members in the WSAQUERYSET2 structure. The data needs to be serialized in a form that can be passed across process
/// boundaries. Just passing a copy of the WSAQUERYSET2 structure is insufficient, since only pointers to data will be passed
/// and the actual data will be unavailable to other processes.
///
/// Query Results
///
/// The following table lists WSAQUERYSET2 and describes how query results are represented in the **WSAQUERYSET2** structure. For
/// more information, see Query-Related Data Structures.
///
///
///
/// WSAQUERYSET2 member name
/// Result interpretation
///
/// -
/// **dwSize**
/// The size, in bytes, of WSAQUERYSET2 structure. This is used as a versioning mechanism.
///
/// -
/// **lpszServiceInstanceName**
/// A string that contains the service name.
///
/// -
/// **lpVersion**
/// References version number of the particular service instance.
///
/// -
/// **lpszComment**
///
/// A comment string supplied by service instance. This member is optional, dependent on the requirements of the NSPv2 service provider.
///
///
/// -
/// **dwNameSpace**
/// The namespace identifier in which the name or service instance was found.
///
/// -
/// **lpNSProviderId**
/// The specific namespace provider that supplied this query result.
///
/// -
/// **lpszContext**
/// The context point in a hierarchical namespace at which the service is located.
///
/// -
/// **dwNumberOfProtocols**
/// This member is undefined for results.
///
/// -
/// **lpafpProtocols**
/// This member is undefined for results. All needed protocol information is in the CSADDR_INFO structures.
///
/// -
/// **lpszQueryString**
///
/// When dwControlFlags includes **LUP_RETURN_QUERY_STRING**, this member returns the unparsed remainder of the
/// **lpszServiceInstanceName** specified in the original query. For example, in a namespace that identifies services by
/// hierarchical names that specify a host name and a file path within that host, the address returned might be the host address and
/// the unparsed remainder might be the file path. If the **lpszServiceInstanceName** is fully parsed and
/// **LUP_RETURN_QUERY_STRING** is used, this member is null or points to a zero-length string.
///
///
/// -
/// **dwNumberOfCsAddrs**
/// The number of elements in the array of CSADDR_INFO structures.
///
/// -
/// **lpcsaBuffer**
/// A pointer to an array of CSADDR_INFO structures, with one complete transport address contained within each element.
///
/// -
/// **dwOutputFlags**
/// The **RESULT_IS_ALIAS** flag indicates this is an alias result.
///
/// -
/// **lpBlob**
/// A pointer to a provider-specific entity. This member is optional, dependent on the requirements of the NSPv2 service provider.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nc-ws2spi-lpnspv2lookupservicenextex LPNSPV2LOOKUPSERVICENEXTEX
// Lpnspv2lookupservicenextex; void Lpnspv2lookupservicenextex( HANDLE hAsyncCall, HANDLE hLookup, DWORD dwControlFlags, LPDWORD
// lpdwBufferLength, LPWSAQUERYSET2W lpqsResults ) {...}
[PInvokeData("ws2spi.h", MSDNShortId = "957fe544-9a3f-47f4-a98c-0624747650f4")]
public delegate void LPNSPV2LOOKUPSERVICENEXTEX(HANDLE hAsyncCall, HANDLE hLookup, uint dwControlFlags, ref uint lpdwBufferLength, [Out] IntPtr lpqsResults);
///
/// The NSPv2SetServiceEx function registers or deregisters a name or service instance within a namespace of a namespace
/// service provider version-2 (NSPv2) provider.
///
/// A handle returned from the previous call to NSPv2LookupServiceBegin used for asynchronous calls.
/// A pointer to the GUID of the specific namespace provider in which the name or service is registered.
/// The property information to be updated upon registration.
///
/// The type of operation requested.
///
/// This parameter can be one of the values from the WSAESETSERVICEOP enumeration type defined in the Winsock2.h header file.
///
///
///
/// Value
/// Meaning
///
/// -
/// RNRSERVICE_REGISTER 0
///
/// Register the service. For the Service Advertising Protocol (SAP) namespace used within a NetWare environment, this means sending
/// a periodic broadcast. This is an NOP for the Domain Name System (DNS) namespace. For persistent data stores this means updating
/// the address information.
///
///
/// -
/// RNRSERVICE_DEREGISTER 1
///
/// Deregister the service. For the SAP namespace, this means stop sending the periodic broadcast. This is a NOP for the DNS
/// namespace. For persistent data stores this means deleting address information.
///
///
/// -
/// RNRSERVICE_DELETE 2
///
/// Delete the service from dynamic name and persistent spaces. For services represented by multiple CSADDR_INFO structures (using
/// the SERVICE_MULTIPLE flag), only the supplied address will be deleted, and this must match exactly the corresponding
/// **CSADDR_INFO** structure supplied when the service was registered.
///
///
///
///
///
/// A set of flags that controls the operation requested.
/// The possible values for this parameter are defined in the Winsock2.h header file.
///
///
/// Value
/// Meaning
///
/// -
/// SERVICE_MULTIPLE 0x00000001
///
/// Control the scope of the operation. When this value is set, the action is only performed on the given address set. A register
/// operation does not invalidate existing addresses and a deregister operation only invalidates the given set of addresses. When
/// this value is absent, service addresses are managed as a group. A register or deregister invalidates all existing addresses
/// before adding the given address set.
///
///
///
///
/// A pointer to the client session.
///
///
/// The function should return NO_ERROR (zero) if the routine succeeds. It should return SOCKET_ERROR (that is, 1) if
/// the routine fails and it must set the appropriate error code using WSASetLastError.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
/// There is not enough memory available to perform this operation.
///
/// -
/// WSAEACCES
/// The calling routine does not have sufficient privileges to install the service.
///
/// -
/// WSAEINVAL
/// One or more parameters were invalid, or missing, for this provider.
///
/// -
/// WSAEOPNOTSUPP
///
/// The operation is not supported. This error is returned if the namespace provider does not implement this function. This error
/// can also be returned if the specified dwControlCode is an unrecognized command.
///
///
/// -
/// WSASERVICE_NOT_FOUND
/// Service is unknown. The service cannot be found in the specified namespace.
///
///
///
///
///
/// The NSPv2SetServiceEx function is used as part of the namespace service provider version-2 (NSPv2) architecture available
/// on Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the NSPv2SetServiceEx function can only be used for operations on NS_EMAIL
/// namespace providers.
///
///
/// The NSPv2Startup function is called each time a new client process begins using namespace provider. Providers may use the client
/// session argument pointed to by the ppvClientSessionArg parameter to store information about this session. This client session
/// argument can be passed to the NSPv2SetServiceEx function in the lpvClientSessionArg parameter.
///
///
/// The NSPv2SetServiceEx function is optional, dependent on the requirements of the NSPv2 provider. If the
/// NSPv2SetServiceEx function isn't implemented, then the NSPv2 function pointer can be to a stub function that always
/// returns NO_ERROR.
///
/// The following table lists the possible combination of values for essOperation and dwControlFlags parameters.
///
///
/// essOperation
/// dwControlFlags
/// Service already exists
/// Service does not exist
///
/// -
/// **RNRSERVICE_REGISTER**
/// None
/// Overwrites the object. Uses only addresses specified. Object is REGISTERED.
/// Creates a new object. Uses only addresses specified. Object is REGISTERED.
///
/// -
/// **RNRSERVICE_REGISTER**
/// **SERVICE_MULTIPLE**
/// Updates object. Adds new addresses to existing set. Object is REGISTERED.
/// Creates a new object. Uses all addresses specified. Object is REGISTERED.
///
/// -
/// **RNRSERVICE_DEREGISTER**
/// None
/// Removes all addresses, but does not remove object from namespace. Object is DEREGISTERED.
/// WSASERVICE_NOT_FOUND
///
/// -
/// **RNRSERVICE_DEREGISTER**
/// **SERVICE_MULTIPLE**
///
/// Updates object. Removes only addresses that are specified. Only mark object as DEREGISTERED if no addresses are present. Does
/// not remove from the namespace.
///
/// WSASERVICE_NOT_FOUND
///
/// -
/// **RNRSERVICE_DELETE**
/// None
/// Removes object from the namespace.
/// WSASERVICE_NOT_FOUND
///
/// -
/// **RNRSERVICE_DELETE**
/// **SERVICE_MULTIPLE**
/// Removes only addresses that are specified. Only removes object from the namespace if no addresses remain.
/// WSASERVICE_NOT_FOUND
///
///
///
/// When the dwControlFlags parameter is set to SERVICE_MULTIPLE, this enables an application to manage its addresses
/// independently. This is useful when the application must manage its protocols individually or when the service resides on more
/// than one computer. For example, when a service uses more than one protocol, one listening socket may abort, but the other
/// sockets remain operational. In this example, the service could deregister the aborted address without affecting the other addresses.
///
///
/// When using SERVICE_MULTIPLE, an application must not let old addresses remain in the object. This can happen if the
/// application aborts without issuing a RNRSERVICE_DEREGISTER request. When a service registers, it should store its
/// addresses. On its next call, the service should explicitly deregister these old addresses before registering new addresses.
///
///
/// If the NSPv2SetServiceEx function isn't implemented, then calls to that function should be intercepted by a stub function
/// that returns WSAEOPNOTSUPP. The NSPv2 function pointer to the unimplemented NSPv2SetServiceEx function in the
/// NSPV2_ROUTINE structure should point be to the stub function.
///
/// Service Properties
///
/// The following table lists WSAQUERYSET2 member names and describes how service property data is represented. Members labeled as
/// optional and dependent on the requirements of the NSPv2 provider may be supplied as a **NULL** pointer when unused by the
/// namespace provider.
///
///
///
/// WSAQUERYSET2 member name
/// Service property description
///
/// -
/// **dwSize**
/// Set to the sizeof(WSAQUERYSET2). This is a versioning mechanism.
///
/// -
/// **lpszServiceInstanceName**
/// A string that contains the service instance name.
///
/// -
/// **lpVersion**
/// The service instance version number. This member is optional, dependent on the requirements of the NSPv2 service provider.
///
/// -
/// **lpszComment**
/// A comment string. This member is optional, dependent on the requirements of the NSPv2 service provider.
///
/// -
/// **dwNameSpace**
/// The namespace identifier. This member is optional, dependent on the requirements of the NSPv2 service provider.
///
/// -
/// **lpNSProviderId**
///
/// The provider identifier. Note that the namespace provider identifier is also passed in the lpProviderId parameter. This member
/// is optional, dependent on the requirements of the NSPv2 service provider.
///
///
/// -
/// **lpszContext**
///
/// The starting point of the query in a hierarchical namespace. This member is optional, dependent on the requirements of the NSPv2
/// service provider.
///
///
/// -
/// **dwNumberOfProtocols**
///
/// The size, in bytes, of the number of entries in the protocol constraint array. This member can be zero.This member is optional,
/// dependent on the requirements of the NSPv2 service provider.
///
///
/// -
/// **lpafpProtocols**
/// An array of AFPROTOCOLS structures. This member is optional, dependent on the requirements of the NSPv2 service provider.
///
/// -
/// **lpszQueryString**
///
/// Some namespaces (such as whois++) support rich SQL-like queries contained in a simple text string. This parameter is used to
/// specify that string.This member is optional, dependent on the requirements of the NSPv2 service provider.
///
///
/// -
/// **dwNumberOfCsAddrs**
/// The number of elements in the array of CSADDR_INFO structures referenced by lpcsaBuffer.
///
/// -
/// **lpcsaBuffer**
/// A pointer to an array of CSADDR_INFO structures that contain the address or addresses that the service is listening on.
///
/// -
/// **dwOutputFlags**
/// This member is optional, dependent on the requirements of the NSPv2 service provider.
///
/// -
/// **lpBlob**
///
/// A pointer to a provider-specific entity. This member is required for the NS_EMAIL namespace. This member is optional, dependent
/// on the requirements for other NSPv2 service providers.
///
///
///
///
/// **Note** It is acceptable for the **iProtocol** member of the CSADDR_INFO structure to contain the manifest constant
/// **IPROTOCOL_ANY**, indicating a wildcard value. The namespace provider should substitute an acceptable value for the given
/// address family and socket type.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nc-ws2spi-lpnspv2setserviceex LPNSPV2SETSERVICEEX Lpnspv2setserviceex;
// void Lpnspv2setserviceex( HANDLE hAsyncCall, LPGUID lpProviderId, LPWSAQUERYSET2W lpqsRegInfo, WSAESETSERVICEOP essOperation,
// DWORD dwControlFlags, LPVOID lpvClientSessionArg ) {...}
[PInvokeData("ws2spi.h", MSDNShortId = "596fe0bd-ec11-44f3-bffe-333758171ea6")]
public delegate void LPNSPV2SETSERVICEEX(HANDLE hAsyncCall, in Guid lpProviderId, in WSAQUERYSET2W lpqsRegInfo, WSAESETSERVICEOP essOperation, ServiceInstallFlags dwControlFlags, [In] IntPtr lpvClientSessionArg);
///
/// The NSPv2Startup function notifies a namespace service provider version-2 (NSPv2) provider that a new client process is
/// to begin using the provider.
///
/// A pointer to the GUID of the specific namespace provider to notify.
///
///
///
/// The function should return NO_ERROR (zero) if the routine succeeds. It should return SOCKET_ERROR (that is, 1) if
/// the routine fails and it must set the appropriate error code using WSASetLastError.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
/// There is not enough memory available to perform this operation.
///
/// -
/// WSAEACCES
/// The calling routine does not have sufficient privileges to initialize the service.
///
/// -
/// WSAEINVAL
/// One or more parameters were invalid, or missing, for this provider.
///
/// -
/// WSAEOPNOTSUPP
/// The operation is not supported. This error is returned if the namespace provider does not implement this function.
///
/// -
/// WSASERVICE_NOT_FOUND
/// Service is unknown. The service cannot be found in the specified namespace.
///
///
///
///
///
/// The NSPv2Startup function is used as part of the namespace service provider version-2 (NSPv2) architecture available on
/// Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the NSPv2Startup function can only be used for operations on NS_EMAIL namespace providers.
///
///
/// The NSPv2Startup function is called each time a new client process begins using namespace provider. Providers may use the
/// client session argument pointed to by the ppvClientSessionArg parameter to store information about this session. The value in
/// the ppvClientSessionArg parameter will be passed to subsequent NSPv2 function calls in the same session. The client session
/// argument may NULL, if the namespace provider does not require this information.
///
///
/// The NSPv2Startup function is called when a new client session initializes. The NSPv2Startup and NSPv2Cleanup
/// functions must be called as pairs.
///
///
/// The NSPv2Startup function must be called successfully before calling the NSPv2Cleanup function. It is permissible to make
/// more than one NSPv2Startup call. However, for each NSPv2Startup call, a corresponding NSPv2Cleanup call
/// must also be issued. Only the final NSPv2Cleanup for the service provider does the actual cleanup; the preceding calls
/// decrement an internal reference count in the namespace service provider.
///
///
/// The NSPv2Startup, NSPv2ClientSessionRundown, and NSPv2Cleanup functions are optional, dependent on the requirements of
/// the NSPv2 provider.
///
///
/// If the NSPv2Startup function isn't implemented, then calls to that function should be intercepted by a stub function that
/// returns WSAEOPNOTSUPP. The NSPv2 function pointer to the unimplemented NSPv2Startup function in the NSPV2_ROUTINE
/// structure should point be to the stub function.
///
///
// 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 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.
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/ne-ws2spi-wsc_provider_info_type typedef enum _WSC_PROVIDER_INFO_TYPE {
// ProviderInfoLspCategories, ProviderInfoAudit } WSC_PROVIDER_INFO_TYPE;
[PInvokeData("ws2spi.h", MSDNShortId = "7f93a660-6f53-4e3c-a938-54a13b34258d")]
public enum WSC_PROVIDER_INFO_TYPE
{
///
/// The LSP category information for a protocol entry in a layered protocol. The information class should point to a DWORD value
/// containing the appropriate LSP category flags implemented by LSP.
///
ProviderInfoLspCategories,
///
/// The LSP class information for audit information for the LSP entry. The information class should point to a
/// WSC_PROVIDER_AUDIT_INFO structure containing an audit record for the LSP.
///
ProviderInfoAudit,
}
///
/// The WPUCompleteOverlappedRequest function performs overlapped I/O completion notification for overlapped I/O operations.
///
/// The service provider socket created by WPUCreateSocketHandle.
///
/// A pointer to a WSAOVERLAPPED structure associated with the overlapped I/O operation whose completion is to be notified.
///
/// The completion status of the overlapped I/O operation whose completion is to be notified.
///
/// The number of bytes transferred to or from client buffers (the direction of the transfer depends on the send or receive nature
/// of the overlapped I/O operation whose completion is to be notified).
///
/// A pointer to the error code resulting from execution of this function.
///
///
/// If no error occurs, WPUCompleteOverlappedRequest returns zero and notifies completion of the overlapped I/O operation
/// according to the mechanism selected by the client (signals an event found in the WSAOVERLAPPED structure referenced by
/// lpOverlapped and/or queues a completion status report to the completion port associated with the socket if a completion port is
/// associated). Otherwise, WPUCompleteOverlappedRequest returns SOCKET_ERROR, and a specific error code is available in lpErrno.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEINVAL
/// The socket passed in the s parameter is not a socket created by WPUCreateSocketHandle.
///
///
///
///
///
/// The WPUCompleteOverlappedRequest function performs overlapped I/O completion notification for overlapped I/O operations
/// where the client-specified completion mechanism is something other than user mode–asynchronous procedure call (APC). This
/// function can only be used for socket handles created by WPUCreateSocketHandle.
///
///
/// **Note** This function is different from other functions with the "WPU" prefix in that it is not accessed through the upcall
/// table. Instead, it is exported directly by Ws2_32.dll. Service providers that need to call this function should link with
/// WS2_32.lib or use appropriate operating system functions such as LoadLibrary and GetProcAddress to retrieve the function pointer.
///
///
/// The function **WPUCompleteOverlappedRequest** is used by service providers that do not implement Installable File System (IFS)
/// functionality directly for the socket handles they expose. It performs completion notification for any overlapped I/O request
/// for which the specified completion notification is other than a user-mode APC. **WPUCompleteOverlappedRequest** is supported
/// only for the socket handles created by WPUCreateSocketHandle and not for sockets created by a service provider directly.
///
///
/// If the client selects a user-mode APC as the notification method, the service provider should use WPUQueueApc or another
/// appropriate operating system function to perform the completion notification. If user-mode APC is not selected by the client, a
/// service provider that does not implement IFS functionality directly cannot determine whether or not the client has associated a
/// completion port with the socket handle. Thus, it cannot determine whether the completion notification method should be queuing a
/// completion status record to a completion port or signaling an event found in the WSAOVERLAPPED structure. The Windows Socket 2
/// architecture keeps track of any completion port association with a socket created by WPUCreateSocketHandle and can make a
/// correct decision between completion port-based notification or event-based notification.
///
///
/// When WPUCompleteOverlappedRequest queues a completion indication, it sets the InternalHigh member of the
/// WSAOVERLAPPED structure to the count of bytes transferred. Then, it sets the Internal member to some OS-dependent value
/// other than the special value WSS_OPERATION_IN_PROGRESS. There may be some slight delay after WPUCompleteOverlappedRequest
/// returns before these values appear, since processing may occur asynchronously. However, the InternalHigh value (byte
/// count) is guaranteed to be set by the time Internal is set.
///
///
/// WPUCompleteOverlappedRequest works as stated (performs the completion notification as requested by the client) whether or
/// not the socket handle has been associated with a completion port.
///
/// Interaction with WSPGetOverlappedResult
///
/// The behavior of WPUCompleteOverlappedRequest places some constraints on how a service provider implements
/// WSPGetOverlappedResult since only the Offset and OffsetHigh members of the WSAOVERLAPPED structure are exclusively
/// controlled by the service provider, yet three values (byte count, flags, and error) must be retrieved from the structure by
/// WSPGetOverlappedResult. A service provider may accomplish this any way it chooses as long as it interacts with the
/// behavior of WPUCompleteOverlappedRequest properly. However, a typical implementation is as follows:
///
///
/// -
/// At the start of overlapped processing, the service provider sets Internal to WSS_OPERATION_IN_PROGRESS.
///
/// -
///
/// When the I/O operation has been completed, the provider sets OffsetHigh to the Windows Socket 2 error code resulting from
/// the operation, sets Offset to the flags resulting from the I/O operation, and calls WPUCompleteOverlappedRequest,
/// passing the transfer byte count as one of the parameters. WPUCompleteOverlappedRequest eventually sets
/// InternalHigh to the transfer byte count, then sets Internal to a value other than WSS_OPERATION_IN_PROGRESS.
///
///
/// -
///
/// When WSPGetOverlappedResult is called, the service provider checks Internal. If it is WSS_OPERATION_IN_PROGRESS, the
/// provider waits on the event handle in the hEvent member or returns an error, based on the setting of the FWAIT flag of
/// WSPGetOverlappedResult. If not in progress, or after completion of waiting, the provider returns the values from
/// InternalHigh, OffsetHigh, and Offset as the transfer count, operation result error code, and flags respectively.
///
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wpucompleteoverlappedrequest int
// 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 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.
///
/// A pointer to the provider ID of the namespace provider to be advertised.
///
/// A pointer to a NSPV2_ROUTINE structure with the namespace service provider version-2 entry points supported by the provider.
///
///
/// If no error occurs, WSAProviderCompleteAsyncCall returns zero.
///
/// If the function fails, the return value is SOCKET_ERROR. To get extended error information, call WSAGetLastError, which returns
/// one of the following extended error values.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
/// There was insufficient memory to perform the operation.
///
/// -
/// WSAEFAULT
/// An internal error occurred.
///
/// -
/// WSAEINVAL
///
/// A parameter was not valid. This error is returned if the puuidProviderId or pNSPv2Routine parameters were **NULL**. This error
/// is also returned if the NSPv2LookupServiceBegin, NSPv2LookupServiceNextEx, or NSPv2LookupServiceEnd members of the NSPV2_ROUTINE
/// structure pointed to by the pNSPv2Routine parameter are NULL. A namespace version-2 provider must at least support name
/// resolution which this minimum set of functions.
///
///
/// -
/// WSAEINVALIDPROVIDER
/// The namespace provider could not be found for the specified puuidProviderId parameter.
///
/// -
/// WSANOTINITIALISED
///
/// The Ws2_32.dll has not been initialized. The application must first call WSAStartup before calling any Windows Sockets functions.
///
///
///
///
///
///
/// The WSAAdvertiseProvider function is used as part of the namespace service provider version-2 (NSPv2) architecture
/// available on Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the WSAAdvertiseProvider function can only be used for operations on NS_EMAIL
/// namespace providers.
///
///
/// The WSAAdvertiseProvider function advertises an instance of a NSPv2 provider for clients to find. If the instance to be
/// advertised is an instance of an application-type provider (a namespace provider where the dwProvideType member of the
/// NAPI_PROVIDER_INSTALLATION_BLOB structure is ProviderType_Application), the advertised provider instance will be visible
/// to all the client processes running under the same user and in the same session as the caller of WSAAdvertiseProvider.
///
///
/// In general, NSPv2 providers are implemented in processes other than the calling applications. NSPv2 providers are not activated
/// as a result of client activity. Each provider hosting application decides when to make a specific provider available or
/// unavailable by calling the WSAAdvertiseProvider and WSAUnadvertiseProvider functions. The client activity only results in
/// attempts to contact the provider, when available (when the namespace provider is advertised).
///
///
/// The WSAAdvertiseProvider function is called by any application that wants to make a specific provider available for all
/// eligible clients (currently all the applications running with the same credentials as the hosting application, and in the same
/// user session).
///
///
/// A process can implement and advertise multiple providers at the same time. Windows Sockets will manage the namespace providers
/// by dispatching calls to the correct one. It will also hide RPC interface details and translates cross-process calls into
/// in-process calls. So that the NSPv2 provider has only to implement a table of entry point functions similar to the NSP_ROUTINE
/// structure used by an NSPv1 provider. A NSPv2 provider does not have to worry about RPC specific requirements (data marshalling
/// and serialization, for example).
///
///
/// The WSAAdvertiseProvider caller passes a pointer to an NSPV2_ROUTINE structure in the pNSPv2Routine parameter with the
/// NSPv2 entry points supported by the provider.
///
/// The WSAUnadvertiseProvider function makes a specific namespace provider no longer available for clients.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wsaadvertiseprovider INT WSAAPI WSAAdvertiseProvider( const
// 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 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
/// is completed.
///
///
/// The handle passed to the asynchronous call being completed. This handle is passed by the client to the namespace version-2
/// provider in the asynchronous function call.
///
/// The return code for the asynchronous call to the namespace version-2 provider.
///
/// If no error occurs, WSAProviderCompleteAsyncCall returns zero.
///
/// If the function fails, the return value is SOCKET_ERROR. To get extended error information, call WSAGetLastError, which returns
/// one of the following extended error values.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
/// There was insufficient memory to perform the operation.
///
/// -
/// WSAEFAULT
/// An internal error occurred.
///
/// -
/// WSAEINVAL
/// A parameter was not valid. This error is returned if the hAsyncCall parameter was **NULL**.
///
/// -
/// WSANOTINITIALISED
///
/// The Ws2_32.dll has not been initialized. The application must first call WSAStartup before calling any Windows Sockets functions.
///
///
///
///
///
///
/// The WSAProviderCompleteAsyncCall function is used as part of the namespace service provider version-2 (NSPv2)
/// architecture available on Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the WSAUnadvertiseProvider function can only be used for operations on NS_EMAIL
/// namespace providers. Asynchronous calls to NSPv2 providers are not supported on Windows Vista and Windows Server 2008. So the
/// WSAProviderCompleteAsyncCall is not currently applicable. This function is planned for use in later versions of Windows
/// when asynchronous calls to namespace providers are supported.
///
///
/// In general, NSPv2 providers are implemented in processes other than the calling applications. NSPv2 providers are not activated
/// as result of client activity. Each provider hosting application decides when to make a specific provider available or
/// unavailable by calling the WSAAdvertiseProvider and WSAUnadvertiseProvider functions. The client activity only results in
/// attempts to contact the provider, when available (when the namespace provider is advertised).
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wsaprovidercompleteasynccall INT WSAAPI
// 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 WSRESULT WSAProviderCompleteAsyncCall(HANDLE hAsyncCall, int iRetCode);
///
/// The WSAUnadvertiseProvider function makes a specific namespace version-2 provider no longer available for clients.
///
/// A pointer to the provider ID of the namespace provider.
///
///
/// If no error occurs, WSAUnadvertiseProvider returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error
/// code is available by calling WSAGetLastError.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEINVAL
/// A parameter was not valid. This error is returned if the puuidProviderId parameter was **NULL**.
///
///
///
///
///
/// The WSAUnadvertiseProvider function is used as part of the namespace service provider version-2 (NSPv2) architecture
/// available on Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the WSAUnadvertiseProvider function can only be used for operations on NS_EMAIL
/// namespace providers.
///
///
/// In general, NSPv2 providers are implemented in processes other than the calling applications. NSPv2 providers are not activated
/// as result of client activity. Each provider hosting application decides when to make a specific provider available or
/// unavailable by calling the WSAAdvertiseProvider and WSAUnadvertiseProvider functions. The client activity only results in
/// attempts to contact the provider, when available (when the namespace provider is advertised).
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wsaunadvertiseprovider INT WSAAPI WSAUnadvertiseProvider(
// const GUID *puuidProviderId );
[DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("ws2spi.h", MSDNShortId = "5975b496-53a7-4f8a-8efc-27ef447596c2")]
public static extern WSRESULT WSAUnadvertiseProvider(in Guid puuidProviderId);
///
/// The WSCDeinstallProvider function removes the specified transport provider from the system configuration database.
///
///
/// A pointer to a globally unique identifier (GUID) for the provider. This value is stored within each WSAProtocol_Info structure.
///
/// A pointer to the error code if the function fails.
///
///
/// If no error occurs, WSCDeinstallProvider returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error
/// code is available in lpErrno.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEINVAL
/// The lpProviderId parameter does not specify a valid provider.
///
/// -
/// WSAEFAULT
/// The lpErrno parameter is not in a valid part of the user address space.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the
/// administrative privileges required to write to the Windows Sockets registry, or a failure occurred when opening a catalog entry.
///
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// The WSCDeinstallProvider function removes the common Windows Sockets 2 configuration information for the specified
/// provider. After this routine completes successfully, the configuration information stored in the registry will be changed.
/// However, any Ws2_32.dll instances currently in memory will not be able to recognize this change.
///
///
/// On success, WSCDeinstallProvider will attempt to alert all interested applications that have registered for notification
/// of the change by calling WSAProviderConfigChange.
///
///
/// The WSCDeinstallProvider function can only be called by a user logged on as a member of the Administrators group. If
/// WSCDeinstallProvider is called by a user that is not a member of the Administrators group, the function call will fail
/// and WSANO_RECOVERY is returned in the lpErrno parameter.
///
///
/// For computers running Windows Vista or Windows Server 2008, this function can also fail because of user account control (UAC).
/// If an application that contains this function is executed by a user logged on as a member of the Administrators group other than
/// the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
///
/// The caller of this function must remove any additional files or service provider–specific configuration information that is
/// needed to completely uninstall the service provider.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscdeinstallprovider int WSCDeinstallProvider( LPGUID
// lpProviderId, LPINT lpErrno );
[DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ws2spi.h", MSDNShortId = "9a2afd11-1944-491f-9c92-9dbac6b3b28e")]
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.
///
///
/// A pointer to a globally unique identifier (GUID) for the provider. This value is stored within each WSAProtocol_Info structure.
///
/// A pointer to the error code if the function fails.
///
///
/// If no error occurs, WSCDeinstallProvider32 returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error
/// code is available in lpErrno.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEINVAL
/// The lpProviderId parameter does not specify a valid provider.
///
/// -
/// WSAEFAULT
/// The lpErrno parameter is not in a valid part of the user address space.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the
/// administrative privileges required to write to the Windows Sockets registry, or a failure occurred when opening a catalog entry.
///
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// WSCDeinstallProvider32 is a strictly 32-bit version of WSCDeinstallProvider. On a 64-bit computer, all calls not
/// specifically 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog. Processes that
/// execute on a 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog and preserve
/// compatibility. The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// The WSCDeinstallProvider32 function removes the common Windows Sockets 2 configuration information for the specified
/// 32-bit provider. After this routine completes successfully, the configuration information stored in the registry will be
/// changed. However, any Ws2_32.dll instances currently in memory will not be able to recognize this change.
///
///
/// On success, WSCDeinstallProvider32 will attempt to alert all interested applications that have registered for
/// notification of the change by calling WSAProviderConfigChange.
///
///
/// The WSCDeinstallProvider32 function can only be called by a user logged on as a member of the Administrators group. If
/// WSCDeinstallProvider32 is called by a user that is not a member of the Administrators group, the function call will fail
/// and WSANO_RECOVERY is returned in the lpErrno parameter.
///
///
/// For computers running Windows Vista or Windows Server 2008, this function can also fail because of user account control (UAC).
/// If an application that contains this function is executed by a user logged on as a member of the Administrators group other than
/// the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
///
/// The caller of this function must remove any additional files or service provider–specific configuration information that is
/// needed to completely uninstall the service provider.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscdeinstallprovider32 int WSCDeinstallProvider32( LPGUID
// lpProviderId, LPINT lpErrno );
[DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ws2spi.h", MSDNShortId = "3de74059-dbfb-49b9-830b-7b2f81f8b68c")]
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
/// ability to change the state of the namespace providers.
///
/// A pointer to a globally unique identifier (GUID) for the namespace provider.
///
/// A Boolean value that, if TRUE, the provider is set to the active state. If FALSE, the provider is disabled and
/// will not be available for query operations or service registration.
///
///
///
/// If no error occurs, the WSCEnableNSProvider function returns NO_ERROR (zero). Otherwise, it returns
/// SOCKET_ERROR if the function fails, and you must retrieve the appropriate error code using the WSAGetLastError function.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// The lpProviderId parameter points to memory that is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// The specified namespace provider identifier is invalid.
///
/// -
/// WSASYSCALLFAILURE
/// A system call that should never fail has failed.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// The WSCEnableNSProvider function is intended to be used to change the state of the namespace providers. An independent
/// software vendor (ISV) should not normally de-activate another ISV namespace provider in order to activate its own. The choice
/// should be left to the user.
///
///
/// The WSCEnableNSProvider function does not affect applications that are already running. Newly installed namespace
/// providers will not be visible to applications nor will the changes in a namespace provider's activation state be visible.
/// Applications launched after the call to WSCEnableNSProvider will see the changes.
///
///
/// The WSCEnableNSProvider function can only be called by a user logged on as a member of the Administrators group. If
/// WSCEnableNSProvider is called by a user that is not a member of the Administrators group, the function call will fail.
///
///
/// For computers running Windows Vista or Windows Server 2008, this function can also fail because of user account control (UAC).
/// If an application that contains this function is executed by a user logged on as a member of the Administrators group other than
/// the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscenablensprovider INT WSCEnableNSProvider( LPGUID
// lpProviderId, BOOL fEnable );
[DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("ws2spi.h", MSDNShortId = "2dff5af6-3011-4e3f-b812-fffaca8fa2d9")]
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
/// end-user the ability to change the state of the namespace providers.
///
/// A pointer to a globally unique identifier (GUID) for the namespace provider.
///
/// A Boolean value that, if TRUE, the namespace provider is set to the active state. If FALSE, the namespace provider
/// is disabled and will not be available for query operations or service registration.
///
///
///
/// If no error occurs, the WSCEnableNSProvider32 function returns NO_ERROR (zero). Otherwise, it returns
/// SOCKET_ERROR if the function fails, and you must retrieve the appropriate error code using the WSAGetLastError function.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// The lpProviderId parameter points to memory that is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// The specified namespace provider identifier is invalid.
///
/// -
/// WSASYSCALLFAILURE
/// A system call that should never fail has failed.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// The WSCEnableNSProvider32 function is intended to be used to change the state of the namespace providers. An independent
/// software vendor (ISV) should not normally de-activate another ISV's namespace provider in order to activate its own. The choice
/// should be left to the user.
///
///
/// WSCEnableNSProvider32 is a strictly 32-bit version of WSCEnableNSProvider. On a 64-bit computer, all calls not
/// specifically 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog. Processes that
/// execute on a 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog and preserve
/// compatibility. The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// The namespace configuration functions do not affect applications that are already running. Newly installed namespace providers
/// will not be visible to applications nor will the changes in a namespace provider's activation state. Applications launched after
/// the call to WSCEnableNSProvider32 will see the changes.
///
///
/// The WSCEnableNSProvider32 function can only be called by a user logged on as a member of the Administrators group. If
/// WSCEnableNSProvider32 is called by a user that is not a member of the Administrators group, the function call will fail.
///
///
/// For computers running on Windows Vista or Windows Server 2008, this function can also fail because of user account control
/// (UAC). If an application that contains this function is executed by a user logged on as a member of the Administrators group
/// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscenablensprovider32 INT WSCEnableNSProvider32( LPGUID
// lpProviderId, BOOL fEnable );
[DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("ws2spi.h", MSDNShortId = "5ab4f8bd-d32d-4962-aac7-2d92847d0e03")]
public static extern WSRESULT WSCEnableNSProvider32(in Guid lpProviderId, [MarshalAs(UnmanagedType.Bool)] bool fEnable);
/// The WSCEnumNameSpaceProviders32 function returns information on available 32-bit namespace providers.
///
/// On input, the number of bytes contained in the buffer pointed to by lpnspBuffer. On output (if the function fails, and the error
/// is WSAEFAULT), the minimum number of bytes to allocate for the lpnspBuffer buffer to allow it to retrieve all the requested
/// information. The buffer passed to WSCEnumNameSpaceProviders32 must be sufficient to hold all of the namespace information.
///
///
/// A buffer that is filled with WSANAMESPACE_INFOW structures. The returned structures are located consecutively at the head of the
/// buffer. Variable sized information referenced by pointers in the structures point to locations within the buffer located between
/// the end of the fixed sized structures and the end of the buffer. The number of structures filled in is the return value of WSCEnumNameSpaceProviders32.
///
///
///
/// The WSCEnumNameSpaceProviders32 function returns the number of WSANAMESPACE_INFOW structures copied into lpnspBuffer.
/// Otherwise, the value SOCKET_ERROR is returned, and a specific error number can be retrieved by calling WSAGetLastError.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
///
/// The lpnspBuffer parameter was a **NULL** pointer or the buffer length, lpdwBufferLength, was too small to receive all the
/// relevant WSANAMESPACE_INFOW structures and associated information. When this error is returned, the buffer length required is
/// returned in the lpdwBufferLength parameter.
///
///
/// -
/// WSANOTINITIALISED
///
/// The WS2_32.DLL has not been initialized. The application must first call WSAStartup before calling any Windows Sockets functions.
///
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
/// There was insufficient memory to perform the operation.
///
///
///
///
///
/// WSCEnumNameSpaceProviders32 is a strictly 32-bit version of WSAEnumNameSpaceProviders. On a 64-bit computer, all calls
/// not specifically 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog. Processes
/// that execute on a 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog and
/// preserve compatibility. The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// The 32-bit SPI function is equivalent to the native API function (WSAEnumNameSpaceProviders) because there is no concept of a
/// "hidden" namespace provider.
///
/// The WSCEnumNameSpaceProviders32 function is a Unicode only function and returns WSANAMESPACE_INFOEXW structures.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscenumnamespaceproviders32 INT WSAAPI
// 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 WSRESULT WSCEnumNameSpaceProviders32(ref uint lpdwBufferLength, [In, Out] IntPtr lpnspBuffer);
/// The WSCEnumNameSpaceProvidersEx32 function retrieves information on available 32-bit namespace providers.
///
/// On input, the number of bytes contained in the buffer pointed to by lpnspBuffer. On output (if the function fails, and the error
/// is WSAEFAULT), the minimum number of bytes to allocate for the lpnspBuffer buffer to allow it to retrieve all the requested
/// information. The buffer passed to WSCEnumNameSpaceProvidersEx32 must be sufficient to hold all of the namespace information.
///
///
/// A buffer that is filled with WSANAMESPACE_INFOEXW structures. The returned structures are located consecutively at the head of
/// the buffer. Variable sized information referenced by pointers in the structures point to locations within the buffer located
/// between the end of the fixed sized structures and the end of the buffer. The number of structures filled in is the return value
/// of WSCEnumNameSpaceProvidersEx32.
///
///
///
/// The WSCEnumNameSpaceProvidersEx32 function returns the number of WSANAMESPACE_INFOEXW structures copied into lpnspBuffer.
/// Otherwise, the value SOCKET_ERROR is returned, and a specific error number can be retrieved by calling WSAGetLastError.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
///
/// The buffer length was too small to receive all the relevant WSANAMESPACE_INFOEXW structures and associated information or the
/// lpnspBuffer parameter was a **NULL** pointer. When this error is returned, the buffer length required is returned in the
/// lpdwBufferLength parameter.
///
///
/// -
/// WSANOTINITIALISED
///
/// The WS2_32.DLL has not been initialized. The application must first call WSAStartup before calling any Windows Sockets functions.
///
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
/// There was insufficient memory to perform the operation.
///
///
///
///
///
/// WSCEnumNameSpaceProvidersEx32 is a strictly 32-bit version of WSAEnumNameSpaceProvidersEx. On a 64-bit computer, all
/// calls not specifically 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog.
/// Processes that execute on a 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog
/// and preserve compatibility. The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// Currently, the only namespace included with Windows that uses information in the ProviderSpecific member of the
/// WSANAMESPACE_INFOEXW structure are namespace providers for the NS_EMAIL namespace. The format of the ProviderSpecific
/// member for an NS_EMAIL namespace provider is a NAPI_PROVIDER_INSTALLATION_BLOB structure.
///
///
/// The 32-bit SPI function is equivalent to the native API function (WSAEnumNameSpaceProvidersEx) because there is no concept of a
/// "hidden" namespace provider.
///
///
/// The provider-specific data blob associated with namespace entry passed in the lpProviderInfo parameter to the
/// WSCInstallNameSpaceEx32 function can be queried using WSCEnumNameSpaceProvidersEx32 function.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscenumnamespaceprovidersex32 INT WSAAPI
// 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 WSRESULT WSCEnumNameSpaceProvidersEx32(ref uint lpdwBufferLength, [In, Out] IntPtr lpnspBuffer);
/// The WSCEnumProtocols function retrieves information about available transport protocols.
///
/// A NULL-terminated array of iProtocol values. This parameter is optional; if lpiProtocols is NULL, information on all
/// available protocols is returned. Otherwise, information is retrieved only for those protocols listed in the array.
///
/// A pointer to a buffer that is filled with WSAPROTOCOL_INFOW structures.
///
/// On input, size of the lpProtocolBuffer buffer passed to WSCEnumProtocols, in bytes. On output, the minimum buffer size,
/// in bytes, that can be passed to WSCEnumProtocols to retrieve all the requested information.
///
/// A pointer to the error code.
///
///
/// If no error occurs, WSCEnumProtocols returns the number of protocols to be reported on. Otherwise, a value of
/// SOCKET_ERROR is returned and a specific error code is available in lpErrno.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// One of more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// Indicates that one of the specified parameters was invalid.
///
/// -
/// WSAENOBUFS
///
/// Buffer length was too small to receive all the relevant WSAProtocol_Info structures and associated information. Pass in a buffer
/// at least as large as the value returned in lpdwBufferLength.
///
///
///
///
///
///
/// The WSCEnumProtocols function is used to discover information about the collection of transport protocols installed on
/// the local computer. This function differs from its API counterpart (WSAEnumProtocols) in that WSAPROTOCOL_INFOW structures for
/// all installed protocols are returned. This includes protocols that the service provider has set the PFL_HIDDEN flag in
/// the dwProviderFlags member of the WSAPROTOCOL_INFOW structure to indicate to the Ws2_32.dll that this protocol
/// should not be returned in the result buffer generated by WSAEnumProtocols function. In addition, the
/// WSCEnumProtocols also returns data for WSAPROTOCOL_INFOW structures that have a chain length of zero ( a dummy LSP
/// provider). The WSAEnumProtocols only returns information on base protocols and protocol chains that lack the
/// PFL_HIDDEN flag and don't have a protocol chain length of zero.
///
///
/// **Note** Layered Service Providers are deprecated. Starting with Windows 8 and Windows Server 2012, use Windows Filtering Platform.
///
///
/// The lpiProtocols parameter can be used as a filter to constrain the amount of information provided. Typically, a null pointer is
/// supplied so the function will return information on all available transport protocols.
///
///
/// A WSAPROTOCOL_INFOW structure is provided in the buffer pointed to by lpProtocolBuffer for each requested protocol. If the
/// supplied buffer is not large enough (as indicated by the input value of lpdwBufferLength), the value pointed to by
/// lpdwBufferLength will be updated to indicate the required buffer size. The Windows Sockets SPI client should then obtain a large
/// enough buffer and call this function again. The WSCEnumProtocols function cannot enumerate over multiple calls; the
/// passed-in buffer must be large enough to hold all expected entries in order for the function to succeed. This reduces the
/// complexity of the function and should not pose a problem because the number of protocols loaded on a local computer is typically small.
///
///
/// The order in which the WSAPROTOCOL_INFOW structures appear in the buffer coincides with the order in which the protocol entries
/// were registered by the service provider with the WS2_32.dll, or with any subsequent reordering that may have occurred through
/// the Windows Sockets applet supplied for establishing default transport providers.
///
/// Examples
///
/// The following example demonstrates the use of the WSCEnumProtocols function to retrieve an array of WSAPROTOCOL_INFOW
/// structures for protocols installed on the local computer.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscenumprotocols int WSCEnumProtocols( LPINT lpiProtocols,
// 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 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.
///
/// Null-terminated array of iProtocol values. This parameter is optional; if lpiProtocols is null, information on all available
/// protocols is returned. Otherwise, information is retrieved only for those protocols listed in the array.
///
/// Buffer that is filled with WSAPROTOCOL_INFOW structures.
///
/// On input, size of the lpProtocolBuffer buffer passed to WSCEnumProtocols, in bytes. On output, the minimum buffer size, in
/// bytes, that can be passed to WSCEnumProtocols to retrieve all the requested information.
///
/// Pointer to the error code.
///
///
/// If no error occurs, WSCEnumProtocols32 returns the number of protocols to be reported on. Otherwise, a value of
/// SOCKET_ERROR is returned and a specific error code is available in lpErrno.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// One of more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// Indicates that one of the specified parameters was invalid.
///
/// -
/// WSAENOBUFS
///
/// Buffer length was too small to receive all the relevant WSAProtocol_Info structures and associated information. Pass in a buffer
/// at least as large as the value returned in lpdwBufferLength.
///
///
///
///
///
///
/// WSCEnumProtocols32 is a strictly 32-bit version of WSCEnumProtocols. On a 64-bit computer, all calls not specifically
/// 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog. Processes that execute on a
/// 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog and preserve compatibility.
/// The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// This function is used to discover information about the collection of transport protocols installed on the local computer. This
/// function differs from its API counterpart (WSAEnumProtocols) in that WSAPROTOCOL_INFOW structures for all installed protocols
/// are returned. This includes protocols that the service provider has set the PFL_HIDDEN flag in the dwProviderFlags
/// member of the WSAPROTOCOL_INFOW structure to indicate to the Ws2_32.dll that this protocol should not be returned in the
/// result buffer generated by WSAEnumProtocols function. In addition, the WSCEnumProtocols32 also returns data for
/// WSAPROTOCOL_INFOW structures that have a chain length of zero ( a dummy LSP provider). The WSAEnumProtocols only
/// returns information on base protocols and protocol chains that lack the PFL_HIDDEN flag and don't have a protocol chain
/// length of zero.
///
///
/// **Note** Layered Service Providers are deprecated. Starting with Windows 8 and Windows Server 2012, use Windows Filtering Platform.
///
///
/// The lpiProtocols parameter can be used as a filter to constrain the amount of information provided. Typically, a NULL pointer is
/// supplied so the function will return information on all available transport protocols.
///
///
/// A WSAPROTOCOL_INFOW structure is provided in the buffer pointed to by lpProtocolBuffer for each requested protocol. If the
/// supplied buffer is not large enough (as indicated by the input value of lpdwBufferLength), the value pointed to by
/// lpdwBufferLength will be updated to indicate the required buffer size. The Windows Sockets SPI client should then obtain a large
/// enough buffer and call this function again. The WSCEnumProtocols32 function cannot enumerate over multiple calls; the
/// passed-in buffer must be large enough to hold all expected entries in order for the function to succeed. This reduces the
/// complexity of the function and should not pose a problem because the number of protocols loaded on a computer is typically small.
///
///
/// The order in which the WSAPROTOCOL_INFOW structures appear in the buffer coincides with the order in which the protocol entries
/// were registered by the service provider with the WS2_32.dll, or with any subsequent reordering that may have occurred through
/// the Windows Sockets applet supplied for establishing default transport providers.
///
/// Examples
///
/// The following example demonstrates the use of the WSCEnumProtocols32 function for use on 64-bit platforms to retrieve an
/// array of WSAPROTOCOL_INFOW structures for protocols installed on the local computer in the 32-bit catalog.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscenumprotocols32 int WSCEnumProtocols32( LPINT
// 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 WSRESULT WSCEnumProtocols32([Optional, MarshalAs(UnmanagedType.LPArray)] int[] lpiProtocols, IntPtr lpProtocolBuffer, ref uint lpdwBufferLength, out int lpErrno);
///
///
/// A pointer to a Unicode string that contains the load path to the executable image for the application. This string observes the
/// usual rules for path resolution and can contain embedded environment strings (such as %SystemRoot%).
///
/// The length, in characters, of the Path parameter. This length does not include the terminating NULL.
///
/// A pointer to a Unicode string which represents the command line arguments used when starting the application specified in the
/// Path parameter. The Extra parameter is used to distinguish between multiple, distinct instances of an application when launched
/// with a consistent command line. This is to support different application categorizations for different instances of Svchost.exe
/// or Rundll32.exe. If only the Path parameter is required and no command line arguments are needed to further distinguish between
/// instances of an application, then the Extra parameter should be set to NULL.
///
/// The length, in characters, of the Extra parameter. This length does not include the terminating NULL.
///
/// A pointer to a DWORD value of permitted LSP categories which are permitted for all instances of this application. The
/// application is identified by the combination of the values of the Path and Extra parameters.
///
/// A pointer to the error code if the function fails.
///
///
/// A pointer to a Unicode string that contains the load path to the executable image for the application. This string observes the
/// usual rules for path resolution and can contain embedded environment strings (such as %SystemRoot%).
///
/// The length, in characters, of the Path parameter. This length does not include the terminating NULL.
///
/// A pointer to a Unicode string which represents the command line arguments used when starting the application specified in the
/// Path parameter. The Extra parameter is used to distinguish between multiple, distinct instances of an application when launched
/// with a consistent command line. This is to support different application categorizations for different instances of Svchost.exe
/// or Rundll32.exe. If only the Path parameter is required and no command line arguments are needed to further distinguish between
/// instances of an application, then the Extra parameter should be set to NULL.
///
/// The length, in characters, of the Extra parameter. This length does not include the terminating NULL.
///
/// A pointer to a DWORD value of permitted LSP categories which are permitted for all instances of this application. The
/// application is identified by the combination of the values of the Path and Extra parameters.
///
/// A pointer to the error code if the function fails.
///
///
/// If no error occurs, WSCGetApplicationCategory returns ERROR_SUCCESS (zero). Otherwise, it returns
/// SOCKET_ERROR, and a specific error code is returned in the lpErrno parameter.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// One or more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSASERVICE_NOT_FOUND
///
/// The service could not be found based on the Path and Extra parameters. The error can also be returned if the application you are
/// querying does not exist in the registry. In this case, the error indicates that the application is not currently categorized.
///
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the
/// administrative privileges required to access the Winsock registry, or a failure occurred when opening a Winsock catalog entry or
/// an application ID entry.
///
///
///
///
///
///
/// WSCGetApplicationCategory is used to retrieve the LSP category flags associated with an application instance.
/// Applications can determine which LSP behaviors are acceptable within the application's context. Therefore, by specifying
/// permitted LSP categories, an application can permit only those layered service providers which implement acceptable behaviors to
/// be loaded.
///
///
/// The Extra parameter is required when the command line is used to distinguish between different instances of an application or
/// service hosted within the same executable. Each instance can have different application categorization needs. Svchost.exe and
/// Rundll32.exe are two examples where the command line is required to differentiate between different process instances. For
/// SvcHost.exe, the -k <svcinstance> switch defines the process instance.
///
///
/// For services, using the Service Name is not sufficient, since the Winsock Catalog is global to a given process, and a process
/// may host several services.
///
///
/// Window sockets determine an application's identity and retrieves the permitted LSP categories during the first call to
/// WSAStartup. This will be the set of permitted LSP categories for the duration of the application instance. Subsequent changes to
/// the permitted LSP categories for a given application identity will not be picked up until the next instance of the application.
/// The permitted LSP categories are not mutable during the lifetime of the application instance.
///
///
/// Winsock 2 accommodates layered protocols. A layered protocol is one that implements only higher level communications functions,
/// while relying on an underlying transport stack for the actual exchange of data with a remote endpoint. An example of a layered
/// protocol or layered service provider would be a security layer that adds protocol to the connection establishment process in
/// order to perform authentication and to establish a mutually agreed upon encryption scheme. Such a security protocol would
/// generally require the services of an underlying reliable transport protocol such as TCP or SPX. The term base protocol refers to
/// a protocol such as TCP or SPX which is capable of performing data communications with a remote endpoint. The term layered
/// protocol is used to describe a protocol that cannot stand alone.
///
///
/// During LSP initialization, the LSP must provide pointers to a number of Winsock SPI functions. These functions will be called
/// during normal processing by the layer directly above the LSP (either another LSP or Ws2_32.DLL).
///
///
/// An LSP that implements an installable file system (IFS) can selectively choose to provide pointers to functions which are
/// implemented by itself, or pass back the pointers provided by the layer directly below the LSP. Non-IFS LSPs, because they
/// provide their own handles, must implement all of the Winsock SPI functions. This is because each SPI will require the LSP to map
/// all of the socket handles it created to the socket handle of the lower provider (either another LSP or the base protocol).
///
/// However, all LSPs perform their specific work by doing extra processing on only a subset of the Winsock SPI functions.
///
/// It is possible to define LSP categories based upon the subset of SPI functions an LSP implements and the nature of the extra
/// processing performed for each of those functions.
///
///
/// By classifying LSPs, as well as classifying applications which use Winsock sockets, it becomes possible to selectively determine
/// if an LSP should be involved in a given process at runtime.
///
///
/// On Windows Vista and later, an LSP can be classified based on how it interacts with Windows Sockets calls and data. An LSP
/// category is an identifiable group of behaviors on a subset of Winsock SPI functions. For example, an HTTP content filter would
/// be categorized as a data inspector (the LSP_INSPECTOR category). The LSP_INSPECTOR category will inspect (but not alter)
/// parameters to data transfer SPI functions. An application can query for the category of an LSP and choose to not load the LSP
/// based on the LSP category and the application's set of permitted LSP categories.
///
/// The following table lists categories that an LSP can be classified into.
///
///
/// LSP Category
/// Description
///
/// -
/// **LSP_CRYPTO_COMPRESS**
/// The LSP is a cryptography or data compression provider.
///
/// -
/// **LSP_FIREWALL**
/// The LSP is a firewall provider.
///
/// -
/// **LSP_LOCAL_CACHE**
/// The LSP is a local cache provider.
///
/// -
/// **LSP_INBOUND_MODIFY**
/// The LSP modifies inbound data.
///
/// -
/// **LSP_INSPECTOR**
/// The LSP inspects or filters data.
///
/// -
/// **LSP_OUTBOUND_MODIFY**
/// The LSP modifies outbound data.
///
/// -
/// **LSP_PROXY**
/// The LSP acts as a proxy and redirects packets.
///
/// -
/// **LSP_REDIRECTOR**
/// The LSP is a network redirector.
///
/// -
/// **LSP_SYSTEM**
/// The LSP is acceptable for use in services and system processes.
///
///
///
/// An LSP may belong to more than one category. For example, a firewall/security LSP could belong to both the inspector (
/// LSP_INSPECTOR) and firewall ( LSP_FIREWALL) categories.
///
///
/// If an LSP does not have a category set, it is considered to be in the All Other category. This LSP category will not be loaded
/// in services or system processes (for example, lsass, winlogon, and many svchost processes).
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscgetapplicationcategory int WSCGetApplicationCategory(
// 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 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.
/// The information class that is requested for this LSP protocol entry.
///
/// A pointer to a buffer to receive the information class data for the requested LSP protocol entry. If this parameter is
/// NULL, then WSCGetProviderInfo returns failure and the size required for this buffer is returned in the InfoSize parameter.
///
///
/// The size, in bytes, of the buffer pointed to by the Info parameter. If the Info parameter is NULL, then
/// WSCGetProviderInfo returns failure and the InfoSize parameter will receive the size of the required buffer.
///
/// The flags used to modify the behavior of the WSCGetProviderInfo function call.
/// A pointer to the error code if the function fails.
///
/// A pointer to a globally unique identifier (GUID) for the provider.
/// The information class that is requested for this LSP protocol entry.
///
/// A pointer to a buffer to receive the information class data for the requested LSP protocol entry. If this parameter is
/// NULL, then WSCGetProviderInfo returns failure and the size required for this buffer is returned in the InfoSize parameter.
///
///
/// The size, in bytes, of the buffer pointed to by the Info parameter. If the Info parameter is NULL, then
/// WSCGetProviderInfo returns failure and the InfoSize parameter will receive the size of the required buffer.
///
/// The flags used to modify the behavior of the WSCGetProviderInfo function call.
/// A pointer to the error code if the function fails.
///
///
/// If no error occurs, WSCGetProviderInfo returns ERROR_SUCCESS (zero). Otherwise, it returns SOCKET_ERROR,
/// and a specific error code is returned in the lpErrno parameter.
///
///
///
/// Error code
/// Meaning
///
/// -
/// ERROR_CALL_NOT_IMPLEMENTED
/// The call is not implemented. This error is returned if **ProviderInfoAudit** is specified in the InfoType parameter.
///
/// -
/// WSAEFAULT
/// One or more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSAEINVALIDPROVIDER
/// The protocol entry could not be found for the specified lpProviderId.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the
/// administrative privileges required to access the Winsock registry, or a failure occurred when opening a Winsock catalog entry.
///
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// WSCGetProviderInfo is used to retrieve information class data for a layered service provider. When the InfoType parameter
/// is set to ProviderInfoLspCategories, on success WSCGetProviderInfo returns with the Info parameter set with
/// appropriate LSP category flags implemented by the LSP.
///
///
/// Winsock 2 accommodates layered protocols. A layered protocol is one that implements only higher level communications functions,
/// while relying on an underlying transport stack for the actual exchange of data with a remote endpoint. An example of a layered
/// protocol or layered service provider would be a security layer that adds protocol to the connection establishment process in
/// order to perform authentication and to establish a mutually agreed upon encryption scheme. Such a security protocol would
/// generally require the services of an underlying reliable transport protocol such as TCP or SPX. The term base protocol refers to
/// a protocol such as TCP or SPX which is capable of performing data communications with a remote endpoint. The term layered
/// protocol is used to describe a protocol that cannot stand alone. A protocol chain would then be defined as one or more layered
/// protocols strung together and anchored by a base protocol. A base protocol has the ChainLen member of the
/// WSAProtocol_Info structure set to BASE_PROTOCOL which is defined to be 1. A layered protocol has the ChainLen
/// member of the WSAPROTOCOL_INFO structure set to LAYERED_PROTOCOL which is defined to be zero. A protocol chain has
/// the ChainLen member of the WSAPROTOCOL_INFO structure set to greater than 1.
///
///
/// During LSP initialization, the LSP must provide pointers to a number of Winsock SPI functions. These functions will be called
/// during normal processing by the layer directly above the LSP (either another LSP or Ws2_32.DLL).
///
///
/// An LSP that implements an installable file system (IFS) can selectively choose to provide pointers to functions which are
/// implemented by itself, or pass back the pointers provided by the layer directly below the LSP. Non-IFS LSPs, because they
/// provide their own handles, must implement all of the Winsock SPI functions. This is because each SPI will require the LSP to map
/// all of the socket handles it created to the socket handle of the lower provider (either another LSP or the base protocol).
///
/// However, all LSPs perform their specific work by doing extra processing on only a subset of the Winsock SPI functions.
///
/// It is possible to define LSP categories based upon the subset of SPI functions an LSP implements and the nature of the extra
/// processing performed for each of those functions.
///
///
/// By classifying LSPs, as well as classifying applications which use Winsock sockets, it becomes possible to selectively determine
/// if an LSP should be involved in a given process at runtime.
///
///
/// On Windows Vista and later, an LSP can be classified based on how it interacts with Windows Sockets calls and data. An LSP
/// category is an identifiable group of behaviors on a subset of Winsock SPI functions. For example, an HTTP content filter would
/// be categorized as a data inspector (the LSP_INSPECTOR category). The LSP_INSPECTOR category will inspect (but not alter)
/// parameters to data transfer SPI functions. An application can query for the category of an LSP and choose to not load the LSP
/// based on the LSP category and the application's set of permitted LSP categories.
///
/// The following table lists categories into which an LSP can be classified.
///
///
/// LSP Category
/// Description
///
/// -
/// **LSP_CRYPTO_COMPRESS**
/// The LSP is a cryptography or data compression provider.
///
/// -
/// **LSP_FIREWALL**
/// The LSP is a firewall provider.
///
/// -
/// **LSP_LOCAL_CACHE**
/// The LSP is a local cache provider.
///
/// -
/// **LSP_INBOUND_MODIFY**
/// The LSP modifies inbound data.
///
/// -
/// **LSP_INSPECTOR**
/// The LSP inspects or filters data.
///
/// -
/// **LSP_OUTBOUND_MODIFY**
/// The LSP modifies outbound data.
///
/// -
/// **LSP_PROXY**
/// The LSP acts as a proxy and redirects packets.
///
/// -
/// **LSP_REDIRECTOR**
/// The LSP is a network redirector.
///
/// -
/// **LSP_SYSTEM**
/// The LSP is acceptable for use in services and system processes.
///
///
///
/// An LSP may belong to more than one category. For example, a firewall/security LSP could belong to both the inspector (
/// LSP_INSPECTOR) and firewall ( LSP_FIREWALL) categories.
///
///
/// If an LSP does not have a category set, it is considered to be in the All Other category. This LSP category will not be loaded
/// in services or system processes (for example, lsass, winlogon, and many svchost processes).
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscgetproviderinfo int WSCGetProviderInfo( LPGUID
// 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 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.
/// The information class that is requested for this LSP protocol entry.
///
/// A pointer to a buffer to receive the information class data for the requested LSP protocol entry. If this parameter is
/// NULL, then WSCGetProviderInfo32 returns failure and the size required for this buffer is returned in the InfoSize parameter.
///
///
/// The size, in bytes, of the buffer pointed to by the Info parameter. If the Info parameter is NULL, then
/// WSCGetProviderInfo32 returns failure and the InfoSize parameter will receive the size of the required buffer.
///
/// The flags used to modify the behavior of the WSCGetProviderInfo32 function call.
/// A pointer to the error code if the function fails.
///
/// A pointer to a globally unique identifier (GUID) for the provider.
/// The information class that is requested for this LSP protocol entry.
///
/// A pointer to a buffer to receive the information class data for the requested LSP protocol entry. If this parameter is
/// NULL, then WSCGetProviderInfo32 returns failure and the size required for this buffer is returned in the InfoSize parameter.
///
///
/// The size, in bytes, of the buffer pointed to by the Info parameter. If the Info parameter is NULL, then
/// WSCGetProviderInfo32 returns failure and the InfoSize parameter will receive the size of the required buffer.
///
/// The flags used to modify the behavior of the WSCGetProviderInfo32 function call.
/// A pointer to the error code if the function fails.
///
///
/// If no error occurs, WSCGetProviderInfo32 returns ERROR_SUCCESS (zero). Otherwise, it returns SOCKET_ERROR,
/// and a specific error code is returned in the lpErrno parameter.
///
///
///
/// Error code
/// Meaning
///
/// -
/// ERROR_CALL_NOT_IMPLEMENTED
/// The call is not implemented. This error is returned if **ProviderInfoAudit** is specified in the InfoType parameter.
///
/// -
/// WSAEFAULT
/// One or more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSAEINVALIDPROVIDER
/// The protocol entry could not be found for the specified lpProviderId.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the
/// administrative privileges required to access the Winsock registry, or a failure occurred when opening a Winsock catalog entry.
///
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// WSCGetProviderInfo32 is a strictly 32-bit version of WSCGetProviderInfo. On a 64-bit computer, all calls not specifically
/// 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog. Processes that execute on a
/// 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog and preserve compatibility.
/// The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// WSCGetProviderInfo32 is used to retrieve information class data for a protocol entry on a 32-bit layered service
/// provider. When the InfoType parameter is set to ProviderInfoLspCategories, on success WSCGetProviderInfo32 returns
/// with the Info parameter set with appropriate LSP category flags implemented by 32-bit LSP.
///
///
/// Winsock 2 accommodates layered protocols. A layered protocol is one that implements only higher level communications functions,
/// while relying on an underlying transport stack for the actual exchange of data with a remote endpoint. An example of a layered
/// protocol or layered service provider would be a security layer that adds protocol to the connection establishment process in
/// order to perform authentication and to establish a mutually agreed upon encryption scheme. Such a security protocol would
/// generally require the services of an underlying reliable transport protocol such as TCP or SPX. The term base protocol refers to
/// a protocol such as TCP or SPX which is capable of performing data communications with a remote endpoint. The term layered
/// protocol is used to describe a protocol that cannot stand alone. A protocol chain would then be defined as one or more layered
/// protocols strung together and anchored by a base protocol. A base protocol has the ChainLen member of the
/// WSAProtocol_Info structure set to BASE_PROTOCOL which is defined to be 1. A layered protocol has the ChainLen
/// member of the WSAPROTOCOL_INFO structure set to LAYERED_PROTOCOL which is defined to be zero. A protocol chain has
/// the ChainLen member of the WSAPROTOCOL_INFO structure set to greater than 1.
///
///
/// During LSP initialization, the LSP must provide pointers to a number of Winsock SPI functions. These functions will be called
/// during normal processing by the layer directly above the LSP (either another LSP or Ws2_32.DLL).
///
///
/// An LSP that implements an installable file system (IFS) can selectively choose to provide pointers to functions which are
/// implemented by itself, or pass back the pointers provided by the layer directly below the LSP. Non-IFS LSPs, because they
/// provide their own handles, must implement all of the Winsock SPI functions. This is because each SPI will require the LSP to map
/// all of the socket handles it created to the socket handle of the lower provider (either another LSP or the base protocol).
///
/// However, all LSPs perform their specific work by doing extra processing on only a subset of the Winsock SPI functions.
///
/// It is possible to define LSP categories based upon the subset of SPI functions an LSP implements and the nature of the extra
/// processing performed for each of those functions.
///
///
/// By classifying LSPs, as well as classifying applications which use Winsock sockets, it becomes possible to selectively determine
/// if an LSP should be involved in a given process at runtime.
///
///
/// On Windows Vista and later, an LSP can be classified based on how it interacts with Windows Sockets calls and data. An LSP
/// category is an identifiable group of behaviors on a subset of Winsock SPI functions. For example, an HTTP content filter would
/// be categorized as a data inspector (the LSP_INSPECTOR category). The LSP_INSPECTOR category will inspect, but not
/// alter, parameters to data transfer SPI functions. An application can query for the category of an LSP and choose to not load the
/// LSP based on the LSP category and the application's set of permitted LSP categories.
///
/// The following table lists categories into which an LSP can be classified.
///
///
/// LSP Category
/// Description
///
/// -
/// **LSP_CRYPTO_COMPRESS**
/// The LSP is a cryptography or data compression provider.
///
/// -
/// **LSP_FIREWALL**
/// The LSP is a firewall provider.
///
/// -
/// **LSP_LOCAL_CACHE**
/// The LSP is a local cache provider.
///
/// -
/// **LSP_INBOUND_MODIFY**
/// The LSP modifies inbound data.
///
/// -
/// **LSP_INSPECTOR**
/// The LSP inspects or filters data.
///
/// -
/// **LSP_OUTBOUND_MODIFY**
/// The LSP modifies outbound data.
///
/// -
/// **LSP_PROXY**
/// The LSP acts as a proxy and redirects packets.
///
/// -
/// **LSP_REDIRECTOR**
/// The LSP is a network redirector.
///
/// -
/// **LSP_SYSTEM**
/// The LSP is acceptable for use in services and system processes.
///
///
///
/// An LSP may belong to more than one category. For example, a firewall/security LSP could belong to both the inspector (
/// LSP_INSPECTOR) and firewall ( LSP_FIREWALL) categories.
///
///
/// If an LSP does not have a category set, it is considered to be in the All Other category. This LSP category will not be loaded
/// in services or system processes (for example, lsass, winlogon, and many svchost processes).
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscgetproviderinfo32 int WSCGetProviderInfo32( LPGUID
// 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 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.
///
/// A pointer to a globally unique identifier (GUID) for the provider. This value is obtained by using WSCEnumProtocols.
///
///
/// A pointer to a buffer into which the provider DLL's path string is returned. The path is a null-terminated string and any
/// embedded environment strings, such as %SystemRoot%, have not been expanded.
///
/// The size, in characters, of the buffer pointed to by the lpszProviderDllPath parameter.
/// A pointer to the error code if the function fails.
///
///
/// If no error occurs, WSCGetProviderPath returns zero. Otherwise, it returns SOCKET_ERROR. The specific error code is
/// available in lpErrno.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEINVAL
/// The lpProviderId parameter does not specify a valid provider.
///
/// -
/// WSAEFAULT
///
/// The lpszProviderDllPath or lpErrno parameter is not in a valid part of the user address space, or lpProviderDllPathLen is too small.
///
///
///
///
///
/// The WSCGetProviderPath function retrieves the DLL path for the specified provider. The DLL path can contain embedded
/// environment strings, such as %SystemRoot%, and thus should be expanded prior to being used with the Windows LoadLibrary
/// function. For more information, see LoadLibrary.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscgetproviderpath int WSCGetProviderPath( LPGUID
// 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 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.
///
/// Pointer to a buffer into which the provider DLL's path string is returned. The path is a null-terminated string and any embedded
/// environment strings, such as %SystemRoot%, have not been expanded.
///
/// Size of the buffer pointed to by the lpszProviderDllPath parameter, in characters.
/// Pointer to the error code.
///
///
/// If no error occurs, WSCGetProviderPath32 returns zero. Otherwise, it returns SOCKET_ERROR. The specific error code is
/// available in lpErrno.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEINVAL
/// The lpProviderId parameter does not specify a valid provider.
///
/// -
/// WSAEFAULT
///
/// The lpszProviderDllPath or lpErrno parameter is not in a valid part of the user address space, or lpProviderDllPathLen is too small.
///
///
///
///
///
///
/// WSCGetProviderPath32 is a strictly 32-bit version of WSCGetProviderPath. On a 64-bit computer, all calls not specifically
/// 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog. Processes that execute on a
/// 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog and preserve compatibility.
/// The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// The WSCGetProviderPath32 function retrieves the DLL path for the specified provider. The DLL path can contain embedded
/// environment strings, such as %SystemRoot%, and thus should be expanded prior to being used with the Windows LoadLibrary
/// function. For more information, see LoadLibrary.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscgetproviderpath32 int WSCGetProviderPath32( LPGUID
// 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 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
/// namespaces, this function must be called for each namespace supported, and a unique provider identifier must be supplied each time.
///
///
/// A pointer to a string that identifies the provider associated with the globally unique identifier (GUID) passed in the
/// lpProviderId parameter.
///
///
/// A pointer to a Unicode string that contains the load path to the provider DLL. This string observes the usual rules for path
/// resolution and can contain embedded environment strings (such as %SystemRoot%). Such environment strings are expanded when the
/// Ws2_32.dll must subsequently load the provider DLL on behalf of an application. After any embedded environment strings are
/// expanded, the Ws2_32.dll passes the resulting string to the LoadLibrary function which loads the provider into memory. For more
/// information, see LoadLibrary.
///
/// The namespace supported by this provider.
/// The version number of the provider.
/// A pointer to a GUID for the provider. This GUID should be generated by Uuidgen.exe.
///
///
/// If no error occurs, the WSCInstallNameSpace function returns NO_ERROR (zero). Otherwise, it returns
/// SOCKET_ERROR if the function fails, and you must retrieve the appropriate error code using the WSAGetLastError function.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEACCES
/// The calling routine does not have sufficient privileges to install a namespace.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the provider is
/// already installed, the user lacks the administrative privileges required to write to the Winsock registry, or a failure occurred
/// when creating or installing a catalog entry.
///
///
/// -
/// WSASYSCALLFAILURE
/// A system call that should never fail has failed.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// The namespace–configuration functions do not affect applications that are already running. Newly installed namespace providers
/// will not be visible to applications nor will the changes in a namespace provider's activation state. Applications launched after
/// the call to WSCInstallNameSpace will see the changes.
///
///
/// The WSCInstallNameSpace function can only be called by a user logged on as a member of the Administrators group. If
/// WSCInstallNameSpace is called by a user that is not a member of the Administrators group, the function call will fail.
/// For computers running on Windows Vista or Windows Server 2008, this function can also fail because of user account control
/// (UAC). If an application that contains this function is executed by a user logged on as a member of the Administrators group
/// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscinstallnamespace INT WSCInstallNameSpace( LPWSTR
// 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 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
/// multiple namespaces, this function must be called for each namespace supported, and a unique provider identifier must be
/// supplied each time.
///
///
/// A pointer to a string that identifies the provider associated with the globally unique identifier (GUID) passed in the
/// lpProviderId parameter.
///
///
/// A pointer to a string that contains the path to the provider's DLL image. The string observes the usual rules for path
/// resolution: this path can contain embedded environment strings (such as %SystemRoot%). Such environment strings are expanded
/// whenever the WS2_32.DLL must subsequently load the provider DLL on behalf of an application. After any embedded environment
/// strings are expanded, the Ws2_32.dll passes the resulting string into the LoadLibrary function to load the provider into memory.
/// For more information, see LoadLibrary.
///
/// A descriptor that specifies the namespace supported by this provider.
/// A descriptor that specifies the version number of the provider.
/// A unique identifier for this provider. This GUID should be generated by Uuidgen.exe.
///
///
/// If no error occurs, the WSCInstallNameSpace32 function returns NO_ERROR (zero). Otherwise, it returns SOCKET_ERROR if the
/// function fails, and you must retrieve the appropriate error code using the WSAGetLastError function.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEACCES
/// The calling routine does not have sufficient privileges to install a namespace.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the provider is
/// already installed, the user lacks the administrative privileges required to write to the Winsock registry, or a failure occurred
/// when creating or installing a catalog entry.
///
///
/// -
/// WSASYSCALLFAILURE
/// A system call that should never fail has failed.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// WSCInstallNameSpace32 is a strictly 32-bit version of WSCInstallNameSpace. On a 64-bit computer, all calls not
/// specifically 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog. Processes that
/// execute on a 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog and preserve
/// compatibility. The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// The namespace configuration functions do not affect applications that are already running. Newly installed namespace providers
/// will not be visible to applications nor will the changes in a namespace provider's activation state. Applications launched after
/// the call to WSCInstallNameSpace32 will recognize the changes.
///
///
/// The WSCInstallNameSpace32 function can only be called by a user logged on as a member of the Administrators group. If
/// WSCInstallNameSpace32 is called by a user that is not a member of the Administrators group, the function call will fail.
/// For computers running Windows Vista or Windows Server 2008, this function can also fail because of user account control (UAC).
/// If an application that contains this function is executed by a user logged on as a member of the Administrators group other than
/// the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator ( RunAs administrator) for this
/// function to succeed.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscinstallnamespace32 INT WSCInstallNameSpace32( LPWSTR
// 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 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
/// namespaces, this function must be called for each namespace supported, and a unique provider identifier must be supplied each time.
///
///
/// A pointer to a string that identifies the provider associated with the globally unique identifier (GUID) passed in the
/// lpProviderId parameter.
///
///
/// A pointer to a Unicode string that contains the load path to the provider DLL. This string observes the usual rules for path
/// resolution and can contain embedded environment strings (such as %SystemRoot%). Such environment strings are expanded when the
/// Ws2_32.dll must subsequently load the provider DLL on behalf of an application. After any embedded environment strings are
/// expanded, the Ws2_32.dll passes the resulting string to the LoadLibrary function which loads the provider into memory. For more
/// information, see LoadLibrary.
///
/// The namespace supported by this provider.
/// The version number of the provider.
/// A pointer to a GUID for the provider. This GUID should be generated by Uuidgen.exe.
/// A provider-specific data blob associated with namespace entry.
///
///
/// If no error occurs, the WSCInstallNameSpaceEx function returns NO_ERROR (zero). Otherwise, it returns
/// SOCKET_ERROR if the function fails, and you must retrieve the appropriate error code using the WSAGetLastError function.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEACCES
/// The calling routine does not have sufficient privileges to install a namespace.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the provider is
/// already installed, the user lacks the administrative privileges required to write to the Winsock registry, or a failure occurred
/// when creating or installing a catalog entry.
///
///
/// -
/// WSASYSCALLFAILURE
/// A system call that should never fail has failed.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// The namespace–configuration functions do not affect applications that are already running. Newly installed name-space providers
/// will not be visible to applications nor will the changes in a name-space provider's activation state. Applications launched
/// after the call to WSCInstallNameSpaceEx will see the changes.
///
///
/// The provider-specific data blob associated with namespace entry passed in the lpProviderInfo parameter can be queried using the
/// WSAEnumNameSpaceProvidersEx function.
///
///
/// Currently, the only namespace provider included with Windows that uses the lpProviderInfo parameter is the NS_EMAIL provider.
/// The format of the buffer pointed to by the lpProviderInfo parameter for an NS_EMAIL namespace provider is a
/// NAPI_PROVIDER_INSTALLATION_BLOB structure.
///
///
/// The WSCInstallNameSpaceEx function can only be called by a user logged on as a member of the Administrators group. If
/// WSCInstallNameSpaceEx is called by a user that is not a member of the Administrators group, the function call will fail.
/// For computers running on Windows Vista or Windows Server 2008, this function can also fail because of user account control
/// (UAC). If an application that contains this function is executed by a user logged on as a member of the Administrators group
/// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscinstallnamespaceex INT WSCInstallNameSpaceEx( LPWSTR
// 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 WSRESULT WSCInstallNameSpaceEx([MarshalAs(UnmanagedType.LPWStr)] string lpszIdentifier, [MarshalAs(UnmanagedType.LPWStr)] string lpszPathName, uint dwNameSpace, uint dwVersion, in Guid lpProviderId, in BLOB lpProviderSpecific);
///
///
/// The WSCInstallNameSpaceEx32 function installs a specified 32-bit namespace provider. For providers that are able to
/// support multiple names spaces, this function must be called for each namespace supported, and a unique provider identifier must
/// be supplied each time.
///
///
/// **Note** This call is a strictly 32-bit version of WSCInstallNameSpaceEx32 for use on 64-bit platforms. It is provided to allow
/// 64-bit processes to access the 32-bit catalogs.
///
///
///
/// A pointer to a string that identifies the provider associated with the globally unique identifier (GUID) passed in the
/// lpProviderId parameter.
///
///
/// A pointer to a Unicode string that contains the load path to the provider DLL. This string observes the usual rules for path
/// resolution and can contain embedded environment strings (such as %SystemRoot%). Such environment strings are expanded when the
/// Ws2_32.dll must subsequently load the provider DLL on behalf of an application. After any embedded environment strings are
/// expanded, the Ws2_32.dll passes the resulting string to the LoadLibrary function which loads the provider into memory. For more
/// information, see LoadLibrary.
///
/// The namespace supported by this provider.
/// The version number of the provider.
/// A pointer to a GUID for the provider. This GUID should be generated by Uuidgen.exe.
/// A provider-specific data blob associated with namespace entry.
///
///
/// If no error occurs, the WSCInstallNameSpaceEx32 function returns NO_ERROR (zero). Otherwise, it returns
/// SOCKET_ERROR if the function fails, and you must retrieve the appropriate error code using the WSAGetLastError function.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEACCES
/// The calling routine does not have sufficient privileges to install a namespace.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the provider is
/// already installed, the user lacks the administrative privileges required to write to the Winsock registry, or a failure occurred
/// when creating or installing a catalog entry.
///
///
/// -
/// WSASYSCALLFAILURE
/// A system call that should never fail has failed.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// WSCInstallNameSpaceEx32 is a strictly 32-bit version of WSCInstallNameSpaceEx. On a 64-bit computer, all calls not
/// specifically 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog. Processes that
/// execute on a 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog and preserve
/// compatibility. The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// The namespace–configuration functions do not affect applications that are already running. Newly installed name-space providers
/// will not be visible to applications nor will the changes in a name-space provider's activation state. Applications launched
/// after the call to WSCInstallNameSpaceEx32 will see the changes.
///
///
/// The provider-specific data blob associated with namespace entry passed in the lpProviderInfo parameter can be queried using
/// WSCEnumNameSpaceProvidersEx32 function.
///
///
/// Currently, the only namespace provider included with Windows that uses the lpProviderInfo parameter is the NS_EMAIL provider.
/// The format of the buffer pointed to by the lpProviderInfo parameter for an NS_EMAIL namespace provider is a
/// NAPI_PROVIDER_INSTALLATION_BLOB structure.
///
///
/// The WSCInstallNameSpaceEx32 function can only be called by a user logged on as a member of the Administrators group. If
/// WSCInstallNameSpaceEx32 is called by a user that is not a member of the Administrators group, the function call will
/// fail. For computers running on Windows Vista or Windows Server 2008, this function can also fail because of user account control
/// (UAC). If an application that contains this function is executed by a user logged on as a member of the Administrators group
/// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscinstallnamespaceex32 INT WSCInstallNameSpaceEx32( LPWSTR
// 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 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.
///
/// A pointer to a Unicode string that contains the load path to the provider DLL. This string observes the usual rules for path
/// resolution and can contain embedded environment strings (such as %SystemRoot%). Such environment strings are expanded when the
/// Ws2_32.dll must subsequently load the provider DLL on behalf of an application. After any embedded environment strings are
/// expanded, the Ws2_32.dll passes the resulting string to the LoadLibrary function which loads the provider into memory. For more
/// information, see LoadLibrary.
///
///
/// A pointer to an array of WSAProtocol_Info structures. Each structure defines a protocol, address family, and socket type
/// supported by the provider.
///
/// The number of entries in the lpProtocolInfoList array.
/// A pointer to the error code if the function fails.
///
/// A pointer to a globally unique identifier (GUID) for the provider.
///
/// A pointer to a Unicode string that contains the load path to the provider DLL. This string observes the usual rules for path
/// resolution and can contain embedded environment strings (such as %SystemRoot%). Such environment strings are expanded when the
/// Ws2_32.dll must subsequently load the provider DLL on behalf of an application. After any embedded environment strings are
/// expanded, the Ws2_32.dll passes the resulting string to the LoadLibrary function which loads the provider into memory. For more
/// information, see LoadLibrary.
///
///
/// A pointer to an array of WSAProtocol_Info structures. Each structure defines a protocol, address family, and socket type
/// supported by the provider.
///
/// The number of entries in the lpProtocolInfoList array.
/// A pointer to the error code if the function fails.
///
///
/// If WSCInstallProvider succeeds, it returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error code is
/// returned in the lpErrno parameter.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// One or more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSAENOBUFS
/// Memory cannot be allocated for buffers.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the provider is
/// already installed, the user lacks the administrative privileges required to write to the Winsock registry, or a failure occurred
/// when creating or installing a catalog entry.
///
///
/// -
/// WSASYSCALLFAILURE
/// A system call that should never fail has failed.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// WSCInstallProvider is used to install a single transport service provider. This routine creates the necessary common
/// Windows Sockets 2 configuration information for the specified provider. It is applicable to base protocols, layered protocols,
/// and protocol chains. If a layered service provider is being installed, then WSCInstallProviderAndChains should be used.
/// WSCInstallProviderAndChains can install a layered protocol and one or more protocol chains with a single function call.
/// To accomplish the same work using WSCInstallProvider would require multiple function calls.
///
///
/// Winsock 2 accommodates layered protocols. A layered protocol is one that implements only higher level communications functions
/// while relying on an underlying transport stack for the actual exchange of data with a remote endpoint. An example of a layered
/// protocol would be a security layer that adds a protocol to the connection establishment process in order to perform
/// authentication and to establish a mutually agreed upon encryption scheme. Such a security protocol would generally require the
/// services of an underlying reliable transport protocol such as TCP or SPX. The term base protocol refers to a protocol such as
/// TCP or SPX which is capable of performing data communications with a remote endpoint. The term layered protocol is used to
/// describe a protocol that cannot stand alone. A protocol chain would then be defined as one or more layered protocols strung
/// together and anchored by a base protocol. A base protocol has the ChainLen member of the WSAProtocol_Info structure set
/// to BASE_PROTOCOL which is defined to be 1. A layered protocol has the ChainLen member of the
/// WSAPROTOCOL_INFO structure set to LAYERED_PROTOCOL which is defined to be zero. A protocol chain has the
/// ChainLen member of the WSAPROTOCOL_INFO structure set to greater than 1.
///
///
/// The lpProtocolInfoList parameter contains a list of protocol entries to install. Callers of WSCInstallProvider are
/// responsible for setting up the proper protocol entries. The lpProtocolInfoList parameter must not be NULL.
///
///
/// Upon successful completion of this call, any subsequent calls to WSAEnumProtocols or WSCEnumProtocols will return the
/// newly-created protocol entries. Be aware that in Windows environments, only instances of Ws_32.dll created by calling WSAStartup
/// after the successful completion of WSCInstallProvider will include the new entries when WSAEnumProtocols and
/// WSCEnumProtocols returns.
///
///
/// On success, WSCInstallProvider will attempt to alert all interested applications that have registered for notification of
/// the change by calling WSAProviderConfigChange.
///
///
/// The WSCInstallProvider function can only be called by a user logged on as a member of the Administrators group. If
/// WSCInstallProvider is called by a user that is not a member of the Administrators group, the function call will fail and
/// WSANO_RECOVERY is returned in the lpErrno parameter. For computers running Windows Vista or Windows Server 2008, this function
/// can also fail because of user account control (UAC). If an application that contains this function is executed by a user logged
/// on as a member of the Administrators group other than the built-in Administrator, this call will fail unless the application has
/// been marked in the manifest file with a requestedExecutionLevel set to requireAdministrator. If the application on
/// Windows Vista or Windows Server 2008 lacks this manifest file, a user logged on as a member of the Administrators group other
/// than the built-in Administrator must then be executing the application in an enhanced shell as the built-in Administrator (
/// RunAs administrator) for this function to succeed.
///
/// Any file installation or service provider-specific configuration must be performed by the caller.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscinstallprovider int WSCInstallProvider( LPGUID
// lpProviderId, const WCHAR *lpszProviderDllPath, const LPWSAPROTOCOL_INFOW lpProtocolInfoList, DWORD dwNumberOfEntries, LPINT
// lpErrno );
[DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ws2spi.h", MSDNShortId = "c0736018-2bcf-4281-aa73-3e1ff9eac92e")]
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.]
///
/// The WSCInstallProvider64_32 function installs the specified transport service provider into the 32-bit and 64-bit system
/// configuration databases on a 64-bit computer.
///
///
/// A pointer to a globally unique identifier (GUID) for the provider.
///
/// A pointer to a Unicode string that contains the load path to the provider 64-bit DLL. This string observes the usual rules for
/// path resolution and can contain embedded environment strings (such as %SystemRoot%). Such environment strings are expanded when
/// the Ws2_32.dll must subsequently load the provider DLL on behalf of an application. After any embedded environment strings are
/// expanded, the Ws2_32.dll passes the resulting string to the LoadLibrary function which loads the provider into memory. For more
/// information, see LoadLibrary.
///
///
/// A pointer to an array of WSAProtocol_Info structures. Each structure defines a protocol, address family, and socket type
/// supported by the provider.
///
/// The number of entries in the lpProtocolInfoList array.
/// A pointer to the error code if the function fails.
///
///
/// If WSCInstallProvider64_32 succeeds, it returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error
/// code is returned in the lpErrno parameter.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// One or more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSAENOBUFS
/// Memory could not be allocated for buffers.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the provider is
/// already installed, the user lacks the administrative privileges required to write to the Winsock registry, or a failure occurred
/// when creating or installing a catalog entry.
///
///
/// -
/// WSASYSCALLFAILURE
/// A system call that should never fail has failed.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// WSCInstallProvider64_32 is a basic version of the WSCInstallProviderAndChains64_32 function that only installs a single
/// transport service provider. WSCInstallProvider64_32 can be used to install a base protocol, a layered protocol, or a
/// protocol chain. If a layered service provider is being installed, then WSCInstallProviderAndChains64_32 should be used
/// because this function allows a layered protocol and one or more protocol chains to be installed with a single function call. To
/// accomplish the same work using WSCInstallProvider64_32 would require multiple function calls to install each service
/// provider component.
///
///
/// Windows Sockets (Winsock) 2 accommodates the notion of a layered protocol. A layered protocol is one that implements only higher
/// level communications functions while relying on an underlying transport stack for the actual exchange of data with a remote
/// endpoint. An example of a layered protocol would be a security layer that adds a protocol to the connection establishment
/// process to perform authentication and to establish a mutually agreed upon encryption scheme. Such a security protocol would
/// generally require the services of an underlying reliable transport protocol such as TCP or SPX. The term base protocol refers to
/// a protocol such as TCP or SPX which is fully capable of performing data communications with a remote endpoint. The term layered
/// protocol is used to describe a protocol that cannot stand alone. A protocol chain would then be defined as one or more layered
/// protocols strung together and anchored by a base protocol. A base protocol has the ChainLen member of the
/// WSAProtocol_Info structure set to BASE_PROTOCOL which is defined to be 1. A layered protocol has the ChainLen
/// member of the WSAPROTOCOL_INFO structure set to LAYERED_PROTOCOL which is defined to be zero. A protocol chain has
/// the ChainLen member of the WSAPROTOCOL_INFO structure set to greater than 1.
///
///
/// WSCInstallProvider64_32 is the 64-bit version of WSCInstallProvider that installs the provider into both the 32-bit and
/// 64-bit catalogs on 64-bit platforms. That is, on 64-bit platforms, two Winsock catalogs are maintained, and both 32-bit and
/// 64-bit processes are able to load the transport provider installed with this function. On 64-bit platforms,
/// WSCInstallProvider installs only to the 64-bit Winsock catalog.
///
///
/// On a 64-bit computer, all calls not specifically designed for 32-bit (for example, all functions that do not end in "32")
/// operate on the native 64-bit catalog. Processes that execute on a 64-bit computer must use WSCInstallProvider64_32 to
/// operate on both the 32-bit catalog as well as the 64-bit catalog, preserving compatibility. The definitions and semantics of the
/// specific 32-bit calls are the same as their native counterparts.
///
///
/// This routine creates the necessary common Winsock 2 configuration information for the specified provider. It is applicable to
/// base protocols, layered protocols, and protocol chains.
///
///
/// The lpProtocolInfoList parameter contains a list of protocol entries to install. Callers of WSCInstallProvider64_32 are
/// responsible for setting up the proper protocol entries. The lpProtocolInfoList parameter must not be NULL.
///
///
/// After this routine completes successfully, the protocol information provided in lpProtocolInfoList will be returned by
/// WSAEnumProtocols, WSCEnumProtocols, or WSCEnumProtocols32. Be aware that in Windows, only instances of the Ws2_32.dll created by
/// calling WSAStartup after a successful completion of this function will include the new entries in WSAEnumProtocols,
/// WSCEnumProtocols, and WSCEnumProtocols32.
///
///
/// On success, WSCInstallProvider64_32 will attempt to alert all interested applications that have registered for
/// notification of the change by calling WSAProviderConfigChange.
///
///
/// The WSCInstallProvider64_32 function can only be called by a user logged on as a member of the Administrators group. If
/// WSCInstallProvider64_32 is called by a user that is not a member of the Administrators group, the function call will fail
/// and WSANO_RECOVERY is returned in the lpErrno parameter. For computers running Windows Vista or Windows Server 2008, this
/// function can also fail because of user account control (UAC). If an application that contains this function is executed by a
/// user logged on as a member of the Administrators group other than the built-in Administrator, this call will fail unless the
/// application has been marked in the manifest file with a requestedExecutionLevel set to requireAdministrator. If
/// the application on Windows Vista or Windows Server 2008 lacks this manifest file, a user logged on as a member of the
/// Administrators group other than the built-in Administrator must then be executing the application in an enhanced shell as the
/// built-in Administrator ( RunAs administrator) for this function to succeed.
///
/// Any file installation or service provider-specific configuration must be performed by the calling application.
///
/// If the WSCInstallProvider or WSCInstallProviderAndChains function is used, the function must be called once to install the
/// provider in the 32-bit catalog and once to install the provider in the 64-bit catalog on a 64-bit platform.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscinstallprovider64_32 int WSCInstallProvider64_32( LPGUID
// lpProviderId, const WCHAR *lpszProviderDllPath, const LPWSAPROTOCOL_INFOW lpProtocolInfoList, DWORD dwNumberOfEntries, LPINT
// lpErrno );
[DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ws2spi.h", MSDNShortId = "50d3a5d1-18f2-439e-a16c-6f31becb1e65")]
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).
///
/// A pointer to a Unicode string containing the load path to the provider's DLL. This string observes the usual rules for path
/// resolution and can contain embedded environment strings (%SystemRoot%, for example). Such environment strings are expanded
/// whenever Ws2_32.dll subsequently loads the provider DLL on behalf of an application. After any embedded environment strings are
/// expanded, Ws2_32.dll passes the resulting string into the LoadLibrary function to load the provider into memory. For more
/// information, see LoadLibrary.
///
/// A pointer to a Unicode string that contains the name of the socket provider.
/// The service flags for the type of "dummy" catalog entry to be created.
///
/// A dummy entry is a WSAProtocol_Info structure with the ChainLen member set to 0. The actual LSP catalog entry will
/// reference the ID of this dummy entry in its ProtocolChain member.
///
/// The possible flags that can be set for this parameter are as follows:
///
///
/// Value
/// Meaning
///
/// -
/// XP1_IFS_HANDLES
///
/// The catalog entry is for an Installable File System (IFS) LSP, which returns IFS-specific socket handles. These handles are
/// returned directly to the calling application. An IFS LSP cannot intercept the completion of Winsock calls, and does not have to
/// have all Winsock functions implemented or available on it.
///
///
///
///
/// A pointer to an array of WSAProtocol_Info structures. Each structure defines a protocol, address family, and socket type
/// supported by the provider. The members of the WSAPROTOCOL_INFO structure that are examined are iProtocol,
/// iAddressFamily, and iSocketType.
///
/// The number of entries in the lpProtocolInfoList array.
///
/// Receives a pointer to the newly-installed "dummy" entry for the transport provider in the Winsock 2 system configuration
/// database. This ID is used to install the catalog entries for the LSP.
///
/// A pointer that receives an error code generated by the call if the function fails.
///
/// A pointer to a provider-specific, globally unique identifier (GUID).
///
/// A pointer to a Unicode string containing the load path to the provider's DLL. This string observes the usual rules for path
/// resolution and can contain embedded environment strings (%SystemRoot%, for example). Such environment strings are expanded
/// whenever Ws2_32.dll subsequently loads the provider DLL on behalf of an application. After any embedded environment strings are
/// expanded, Ws2_32.dll passes the resulting string into the LoadLibrary function to load the provider into memory. For more
/// information, see LoadLibrary.
///
/// A pointer to a Unicode string that contains the name of the socket provider.
///
/// The service flags for the type of "dummy" catalog entry to be created.
///
/// A dummy entry is a WSAProtocol_Info structure with the ChainLen member set to 0. The actual LSP catalog entry will
/// reference the ID of this dummy entry in its ProtocolChain member.
///
/// The possible flags that can be set for this parameter are as follows:
///
///
/// Value
/// Meaning
///
/// -
/// XP1_IFS_HANDLES
///
/// The catalog entry is for an Installable File System (IFS) LSP, which returns IFS-specific socket handles. These handles are
/// returned directly to the calling application. An IFS LSP cannot intercept the completion of Winsock calls, and does not have to
/// have all Winsock functions implemented or available on it.
///
///
///
///
///
/// A pointer to an array of WSAProtocol_Info structures. Each structure defines a protocol, address family, and socket type
/// supported by the provider. The members of the WSAPROTOCOL_INFO structure that are examined are iProtocol,
/// iAddressFamily, and iSocketType.
///
/// The number of entries in the lpProtocolInfoList array.
///
/// Receives a pointer to the newly-installed "dummy" entry for the transport provider in the Winsock 2 system configuration
/// database. This ID is used to install the catalog entries for the LSP.
///
/// A pointer that receives an error code generated by the call if the function fails.
///
///
/// If WSCInstallProviderAndChains succeeds, it returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error
/// code is returned in the lpErrno parameter.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// One or more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
///
/// One or more of the arguments are invalid. This error is returned for the following conditions: the lpProviderId parameter is
/// **NULL**, the lpszProviderDllPath parameter is invalid or the path length is too large (**MAX_PATH** was exceeded), the
/// lpszLspName parameter is invalid or the name length is too large (**WSAPROTOCOL_LEN** is exceeded), the lpProtocolInfoList is
/// set to a non-**NULL** and the dwNumberOfEntries parameter is zero, a duplicate provider ID or the layered service provider name
/// already exist in the catalog, or a match cannot be found for the specified protocol, address family, and socket type.
///
///
/// -
/// WSAEINPROGRESS
/// A provider installation is already in progress.
///
/// -
/// WSAEINVALIDPROCTABLE
/// The provider is missing required functionality.
///
/// -
/// WSAENOBUFS
/// Memory cannot be allocated for buffers.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the provider is
/// already installed, the lpProtocolInfoList parameter was **NULL** and there was no base provider found, the maximum protocol
/// chain length (**MAX_PROTOCOL_CHAIN**) was reached, the user lacks the administrative privileges required to write to the Winsock
/// registry, or a failure occurred when creating or installing a catalog entry.
///
///
/// -
/// WSASYSCALLFAILURE
/// A system call that should never fail has failed.
///
///
///
///
///
/// WSCInstallProviderAndChains is an enhanced version of the basic WSCInstallProvider function used to install a single
/// transport service provider. If a layered service provider is being installed, then WSCInstallProviderAndChains should be
/// used. WSCInstallProviderAndChains can install a layered protocol and one or more protocol chains with a single function
/// call. To accomplish the same work using WSCInstallProvider would require multiple function calls.
///
///
/// Winsock 2 accommodates layered protocols. A layered protocol is one that implements only higher level communications functions
/// while relying on an underlying transport stack for the actual exchange of data with a remote endpoint. An example of a layered
/// protocol would be a security layer that adds a protocol to the connection establishment process in order to perform
/// authentication and to establish a mutually agreed upon encryption scheme. Such a security protocol would generally require the
/// services of an underlying reliable transport protocol such as TCP or SPX. The term base protocol refers to a protocol such as
/// TCP or SPX which is capable of performing data communications with a remote endpoint. The term layered protocol is used to
/// describe a protocol that cannot stand alone. A protocol chain would then be defined as one or more layered protocols strung
/// together and anchored by a base protocol. A base protocol has the ChainLen member of the WSAProtocol_Info structure set
/// to BASE_PROTOCOL which is defined to be 1. A layered protocol has the ChainLen member of the
/// WSAPROTOCOL_INFO structure set to LAYERED_PROTOCOL which is defined to be zero. A protocol chain has the
/// ChainLen member of the WSAPROTOCOL_INFO structure set to greater than 1.
///
///
/// If lpProtocolInfoList is set to NULL, this function creates protocol chains where the provider is layered over the base
/// protocol for each unique protocol type as defined by the address family, socket type, and protocol. This eliminates the creation
/// of any inaccessible duplicate provider entries.
///
///
/// If lpProtocolInfoList is set to a non- NULL value, this function creates protocol chains by obtaining the top-most entry
/// in the configuration information that matches the address family, socket type, and protocol from each element in the provided
/// array. Again, only the address family, socket type, and protocol are considered; all other members and duplicates are ignored.
///
///
/// Upon successful completion of this call, any subsequent calls to WSAEnumProtocols or WSCEnumProtocols will return the
/// newly-created protocol chain entries. Be aware that in Windows environments, only instances of Ws_32.dll created by calling
/// WSAStartup after the successful completion of WSCInstallProviderAndChains will include the new entries when
/// WSAEnumProtocols and WSCEnumProtocols returns.
///
///
/// On success, WSCInstallProviderAndChains will attempt to alert all interested applications that have registered for
/// notification of the change by calling WSAProviderConfigChange.
///
///
/// The WSCInstallProviderAndChains function can only be called by a user logged on as a member of the Administrators group.
/// If WSCInstallProviderAndChains is called by a user that is not a member of the Administrators group, the function call
/// will fail and WSANO_RECOVERY is returned in the lpErrno parameter. For computers running Windows Vista or Windows Server 2008,
/// this function can also fail because of user account control (UAC). If an application that contains this function is executed by
/// a user logged on as a member of the Administrators group other than the built-in Administrator, this call will fail unless the
/// application has been marked in the manifest file with a requestedExecutionLevel set to requireAdministrator. If
/// the application on Windows Vista or Windows Server 2008 lacks this manifest file, a user logged on as a member of the
/// Administrators group other than the built-in Administrator must then be executing the application in an enhanced shell as the
/// built-in Administrator ( RunAs administrator) for this function to succeed.
///
/// Any file installation or provider-specific configuration must be performed by the calling application.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscinstallproviderandchains int WSCInstallProviderAndChains(
// LPGUID lpProviderId, const LPWSTR lpszProviderDllPath, const LPWSTR lpszLspName, DWORD dwServiceFlags, LPWSAPROTOCOL_INFOW
// 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 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);
///
///
/// A pointer to a Unicode string that contains the load path to the executable image for the application. This string observes the
/// usual rules for path resolution and can contain embedded environment strings (such as %SystemRoot%).
///
/// The length, in characters, of the Path parameter. This length does not include the terminating NULL.
///
/// A pointer to a Unicode string which represents the command line arguments used when starting the application specified in the
/// Path parameter. The Extra parameter is used to distinguish between multiple, distinct instances of an application when launched
/// with a consistent command line. This is to support different application categorizations for different instances of Svchost.exe
/// or Rundll32.exe. If only the Path parameter is required and no command line arguments are needed to further distinguish between
/// instances of an application, then the Extra parameter should be set to NULL.
///
/// The length, in characters, of the Extra parameter. This length does not include the terminating NULL.
///
/// A DWORD value of the LSP categories which are permitted for all instances of this application. The application is identified by
/// the combination of the values of the Path and Extra parameters.
///
///
/// A pointer to receive the previous set of permitted LSP categories which were permitted for all instances of this application.
/// This parameter is optional can be NULL.
///
/// A pointer to the error code if the function fails.
///
///
/// A pointer to a Unicode string that contains the load path to the executable image for the application. This string observes the
/// usual rules for path resolution and can contain embedded environment strings (such as %SystemRoot%).
///
/// The length, in characters, of the Path parameter. This length does not include the terminating NULL.
///
/// A pointer to a Unicode string which represents the command line arguments used when starting the application specified in the
/// Path parameter. The Extra parameter is used to distinguish between multiple, distinct instances of an application when launched
/// with a consistent command line. This is to support different application categorizations for different instances of Svchost.exe
/// or Rundll32.exe. If only the Path parameter is required and no command line arguments are needed to further distinguish between
/// instances of an application, then the Extra parameter should be set to NULL.
///
/// The length, in characters, of the Extra parameter. This length does not include the terminating NULL.
///
/// A DWORD value of the LSP categories which are permitted for all instances of this application. The application is identified by
/// the combination of the values of the Path and Extra parameters.
///
///
/// A pointer to receive the previous set of permitted LSP categories which were permitted for all instances of this application.
/// This parameter is optional can be NULL.
///
/// A pointer to the error code if the function fails.
///
///
/// If no error occurs, WSCSetApplicationCategory returns ERROR_SUCCESS (zero). Otherwise, it returns
/// SOCKET_ERROR, and a specific error code is returned in the lpErrno parameter.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// One or more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the
/// administrative privileges required to access the Winsock registry, or a failure occurred when opening a Winsock catalog entry or
/// an application ID entry.
///
///
///
///
///
///
/// WSCSetApplicationCategory is used to set the LSP category flags associated with an application instance. Applications can
/// determine which LSP behaviors are acceptable within the application's context. Therefore, through specifying permitted LSP
/// categories, an application can permit only those layered service providers which implement acceptable behaviors to be loaded.
///
///
/// The Extra parameter is required when the command line is used to distinguish between different instances of an application or
/// service hosted within the same executable. Each instance can have different application categorization needs. Svchost.exe and
/// Rundll32.exe are two examples where the command line is required to differentiate between different process instances. For
/// SvcHost.exe, the -k <svcinstance> switch defines the process instance.
///
///
/// For services, using the Service Name is not sufficient, because the Winsock Catalog is global to a given process, and a process
/// may host several services.
///
///
/// If the WSCSetApplicationCategory function is called on the same application (the same fullpath, EXE name, and parameters)
/// multiple times, then the categories are ORed together. For example if you categorized "c:\foo.exe -param" with LSP_SYSTEM and
/// then called the WSCSetApplicationCategory function again with LSP_REDIRECTOR, the resulting entry for htis application
/// contains LSP_SYSTEM | LSP_REDIRECTOR. This behavior is designed to support a single executable file that hosts multiple
/// applications in a single EXE (the Windows system services svchost.exe, for example).
///
///
/// Window sockets determine an application's identity and retrieves the permitted LSP categories during the first call to
/// WSAStartup. This will be the set of permitted LSP categories for the duration of the application instance. Subsequent changes to
/// the permitted LSP categories for a given application identity will not be picked up until the next instance of the application.
/// The permitted LSP categories is not mutable during the lifetime of the application instance.
///
///
/// Winsock 2 accommodates layered protocols. A layered protocol is one that implements only higher level communications functions,
/// while relying on an underlying transport stack for the actual exchange of data with a remote endpoint. An example of a layered
/// protocol or layered service provider would be a security layer that adds protocol to the connection establishment process in
/// order to perform authentication and to establish a mutually agreed upon encryption scheme. Such a security protocol would
/// generally require the services of an underlying reliable transport protocol such as TCP or SPX. The term base protocol refers to
/// a protocol such as TCP or SPX which is capable of performing data communications with a remote endpoint. The term layered
/// protocol is used to describe a protocol that cannot stand alone.
///
///
/// During LSP initialization, the LSP must provide pointers to a number of Winsock SPI functions. These functions will be called
/// during normal processing by the layer directly above the LSP (either another LSP or Ws2_32.dll).
///
///
/// An LSP that implements an installable file system (IFS) can selectively choose to provide pointers to functions which are
/// implemented by itself, or pass back the pointers provided by the layer directly below the LSP. Non-IFS LSPs, because they
/// provide their own handles, must implement all of the Winsock SPI functions. This is because each SPI will require the LSP to map
/// all of the socket handles it created to the socket handle of the lower provider (either another LSP or the base protocol).
///
/// However, all LSPs perform their specific work by doing extra processing on only a subset of the Winsock SPI functions.
///
/// It is possible to define LSP categories based upon the subset of SPI functions an LSP implements and the nature of the extra
/// processing performed for each of those functions.
///
///
/// By classifying LSPs, as well as classifying applications which use Winsock sockets, it becomes possible to selectively determine
/// if an LSP should be involved in a given process at runtime.
///
///
/// On Windows Vista and later, an LSP can be classified based on how it interacts with Windows Sockets calls and data. An LSP
/// category is an identifiable group of behaviors on a subset of Winsock SPI functions. For example, an HTTP content filter would
/// be categorized as a data inspector (the LSP_INSPECTOR category). The LSP_INSPECTOR category will inspect (but not
/// alter) parameters to data transfer SPI functions. An application can query for the category of an LSP and choose to not load the
/// LSP based on the LSP category and the application's set of permitted LSP categories.
///
/// The following table lists categories into which an LSP can be classified.
///
///
/// LSP Category
/// Description
///
/// -
/// **LSP_CRYPTO_COMPRESS**
/// The LSP is a cryptography or data compression provider.
///
/// -
/// **LSP_FIREWALL**
/// The LSP is a firewall provider.
///
/// -
/// **LSP_LOCAL_CACHE**
/// The LSP is a local cache provider.
///
/// -
/// **LSP_INBOUND_MODIFY**
/// The LSP modifies inbound data.
///
/// -
/// **LSP_INSPECTOR**
/// The LSP inspects or filters data.
///
/// -
/// **LSP_OUTBOUND_MODIFY**
/// The LSP modifies outbound data.
///
/// -
/// **LSP_PROXY**
/// The LSP acts as a proxy and redirects packets.
///
/// -
/// **LSP_REDIRECTOR**
/// The LSP is a network redirector.
///
/// -
/// **LSP_SYSTEM**
/// The LSP is acceptable for use in services and system processes.
///
///
///
/// An LSP may belong to more than one category. For example, a firewall/security LSP could belong to both the inspector (
/// LSP_INSPECTOR) and firewall ( LSP_FIREWALL) categories.
///
///
/// If an LSP does not have a category set, it is considered to be in the All Other category. This LSP category will not be loaded
/// in services or system processes (for example, lsass, winlogon, and many svchost processes).
///
///
/// The WSCSetApplicationCategory function can only be called by a user logged on as a member of the Administrators group. If
/// WSCSetApplicationCategory is called by a user that is not a member of the Administrators group, the function call will
/// fail and WSANO_RECOVERY is returned in the lpErrno parameter. This function can also fail because of user account control
/// (UAC). If an application that contains this function is executed by a user logged on as a member of the Administrators group
/// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
/// Any file installation or service provider-specific configuration must be performed by the caller.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscsetapplicationcategory int WSCSetApplicationCategory(
// LPCWSTR Path, DWORD PathLength, LPCWSTR Extra, DWORD ExtraLength, DWORD PermittedLspCategories, DWORD *pPrevPermLspCat, LPINT
// lpErrno );
[DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ws2spi.h", MSDNShortId = "266c9424-f6ab-4630-843d-bc0833d74e4f")]
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.
/// The information class to be set for this LSP protocol entry.
/// A pointer to a buffer that contains the information class data to set for the LSP protocol entry.
/// The size, in bytes, of the buffer pointed to by the Info parameter.
/// The flags used to modify the behavior of the WSCSetProviderInfo function call.
/// A pointer to the error code if the function fails.
///
/// A pointer to a globally unique identifier (GUID) for the provider.
/// The information class to be set for this LSP protocol entry.
/// A pointer to a buffer that contains the information class data to set for the LSP protocol entry.
/// The size, in bytes, of the buffer pointed to by the Info parameter.
/// The flags used to modify the behavior of the WSCSetProviderInfo function call.
/// A pointer to the error code if the function fails.
///
///
/// If no error occurs, WSCSetProviderInfo returns ERROR_SUCCESS (zero). Otherwise, it returns SOCKET_ERROR,
/// and a specific error code is returned in the lpErrno parameter.
///
///
///
/// Error code
/// Meaning
///
/// -
/// ERROR_CALL_NOT_IMPLEMENTED
/// The call is not implemented. This error is returned if **ProviderInfoAudit** is specified in the InfoType parameter.
///
/// -
/// WSAEFAULT
/// One or more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the
/// administrative privileges required to write to the Winsock registry, or a failure occurred when opening a Winsock catalog entry.
///
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// WSCSetProviderInfo is used to set the information class data for a layered service provider. When the InfoType parameter
/// is set to ProviderInfoLspCategories, on success WSCSetProviderInfo sets appropriate LSP category flags implemented
/// by the provider based on the value passed in the Info parameter.
///
///
/// Winsock 2 accommodates layered protocols. A layered protocol is one that implements only higher level communications functions,
/// while relying on an underlying transport stack for the actual exchange of data with a remote endpoint. An example of a layered
/// protocol or layered service provider would be a security layer that adds protocol to the connection establishment process in
/// order to perform authentication and to establish a mutually agreed upon encryption scheme. Such a security protocol would
/// generally require the services of an underlying reliable transport protocol such as TCP or SPX. The term base protocol refers to
/// a protocol such as TCP or SPX which is capable of performing data communications with a remote endpoint. The term layered
/// protocol is used to describe a protocol that cannot stand alone. A protocol chain would then be defined as one or more layered
/// protocols strung together and anchored by a base protocol. A base protocol has the ChainLen member of the
/// WSAPROTOCOL_INFO structure set to BASE_PROTOCOL which is defined to be 1. A layered protocol has the ChainLen
/// member of the WSAPROTOCOL_INFO structure set to LAYERED_PROTOCOL which is defined to be zero. A protocol chain has
/// the ChainLen member of the WSAPROTOCOL_INFO structure set to greater than 1.
///
///
/// During LSP initialization, the LSP must provide pointers to a number of Winsock SPI functions. These functions will be called
/// during normal processing by the layer directly above the LSP (either another LSP or Ws2_32.dll).
///
///
/// An LSP that implements an installable file system (IFS) can selectively choose to provide pointers to functions which are
/// implemented by itself, or pass back the pointers provided by the layer directly below the LSP. Non-IFS LSPs, because they
/// provide their own handles, must implement all of the Winsock SPI functions. This is because each SPI will require the LSP to map
/// all of the socket handles it created to the socket handle of the lower provider (either another LSP or the base protocol).
///
/// However, all LSPs perform their specific work by doing extra processing on only a subset of the Winsock SPI functions.
///
/// It is possible to define LSP categories based upon the subset of SPI functions an LSP implements and the nature of the extra
/// processing performed for each of those functions.
///
///
/// By classifying LSPs, as well as classifying applications which use Winsock sockets, it becomes possible to selectively determine
/// if an LSP should be involved in a given process at runtime.
///
///
/// On Windows Vista and later, an LSP can be classified based on how it interacts with Windows Sockets calls and data. An LSP
/// category is an identifiable group of behaviors on a subset of Winsock SPI functions. For example, an HTTP content filter would
/// be categorized as a data inspector (the LSP_INSPECTOR category). The LSP_INSPECTOR category will inspect, but not
/// alter, parameters to data transfer SPI functions. An application can query for the category of an LSP and choose to not load the
/// LSP based on the LSP category and the application's set of permitted LSP categories.
///
/// The following table lists categories into which an LSP can be classified.
///
///
/// LSP Category
/// Description
///
/// -
/// **LSP_CRYPTO_COMPRESS**
/// The LSP is a cryptography or data compression provider.
///
/// -
/// **LSP_FIREWALL**
/// The LSP is a firewall provider.
///
/// -
/// **LSP_LOCAL_CACHE**
/// The LSP is a local cache provider.
///
/// -
/// **LSP_INBOUND_MODIFY**
/// The LSP modifies inbound data.
///
/// -
/// **LSP_INSPECTOR**
/// The LSP inspects or filters data.
///
/// -
/// **LSP_OUTBOUND_MODIFY**
/// The LSP modifies outbound data.
///
/// -
/// **LSP_PROXY**
/// The LSP acts as a proxy and redirects packets.
///
/// -
/// **LSP_REDIRECTOR**
/// The LSP is a network redirector.
///
/// -
/// **LSP_SYSTEM**
/// The LSP is acceptable for use in services and system processes.
///
///
///
/// An LSP may belong to more than one category. For example, firewall/security LSP could belong to both the inspector
/// (**LSP_INSPECTOR**) and firewall (**LSP_FIREWALL**) categories.
///
///
/// If an LSP does not have category set, it is considered to be in the All Other category. This LSP category will not be loaded in
/// services or system processes (for example, lsass, winlogon, and many svchost processes).
///
///
/// The WSCSetProviderInfo function can only be called by a user logged on as a member of the Administrators group. If
/// WSCSetProviderInfo is called by a user that is not a member of the Administrators group, the function call will fail and
/// WSANO_RECOVERY is returned in the lpErrno parameter. This function can also fail because of user account control (UAC).
/// If an application that contains this function is executed by a user logged on as a member of the Administrators group other than
/// the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
///
/// **Note** The TDI feature is deprecated and will be removed in future versions of Microsoft Windows. Depending on how you use
/// TDI, use either the Winsock Kernel (WSK) or Windows Filtering Platform (WFP). For more information about WFP and WSK, see
/// Windows Filtering Platform and Winsock Kernel. For a Windows Core Networking blog entry about WSK and TDI, see Introduction to
/// Winsock Kernel (WSK).
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscsetproviderinfo int WSCSetProviderInfo( LPGUID
// 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 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.
/// The information class to be set for this LSP protocol entry.
/// A pointer to a buffer that contains the information class data to set for the LSP protocol entry.
/// The size, in bytes, of the buffer pointed to by the Info parameter.
/// The flags used to modify the behavior of the WSCSetProviderInfo32 function call.
/// A pointer to the error code if the function fails.
///
/// A pointer to a globally unique identifier (GUID) for the provider.
/// The information class to be set for this LSP protocol entry.
/// A pointer to a buffer that contains the information class data to set for the LSP protocol entry.
/// The size, in bytes, of the buffer pointed to by the Info parameter.
/// The flags used to modify the behavior of the WSCSetProviderInfo32 function call.
/// A pointer to the error code if the function fails.
///
///
/// If no error occurs, WSCSetProviderInfo32 returns ERROR_SUCCESS (zero). Otherwise, it returns SOCKET_ERROR,
/// and a specific error code is returned in the lpErrno parameter.
///
///
///
/// Error code
/// Meaning
///
/// -
/// ERROR_CALL_NOT_IMPLEMENTED
/// The call is not implemented. This error is returned if **ProviderInfoAudit** is specified in the InfoType parameter.
///
/// -
/// WSAEFAULT
/// One or more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the
/// administrative privileges required to write to the Winsock registry, or a failure occurred when opening a Winsock catalog entry.
///
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// WSCSetProviderInfo32 is a strictly 32-bit version of WSCSetProviderInfo. On a 64-bit computer, all calls not specifically
/// 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog. Processes that execute on a
/// 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog and preserve compatibility.
/// The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// WSCSetProviderInfo32 is used to set the information class data for a 32-bit layered service provider. When the InfoType
/// parameter is set to ProviderInfoLspCategories, on success WSCSetProviderInfo32 sets appropriate LSP category flags
/// implemented by the provider based on the value passed in the Info parameter.
///
///
/// Winsock 2 accommodates layered protocols. A layered protocol is one that implements only higher level communications functions,
/// while relying on an underlying transport stack for the actual exchange of data with a remote endpoint. An example of a layered
/// protocol or layered service provider would be a security layer that adds protocol to the connection establishment process in
/// order to perform authentication and to establish a mutually agreed upon encryption scheme. Such a security protocol would
/// generally require the services of an underlying reliable transport protocol such as TCP or SPX. The term base protocol refers to
/// a protocol such as TCP or SPX which is capable of performing data communications with a remote endpoint. The term layered
/// protocol is used to describe a protocol that cannot stand alone. A protocol chain would then be defined as one or more layered
/// protocols strung together and anchored by a base protocol. A base protocol has the ChainLen member of the
/// WSAProtocol_Info structure set to BASE_PROTOCOL which is defined to be 1. A layered protocol has the ChainLen
/// member of the WSAPROTOCOL_INFO structure set to LAYERED_PROTOCOL which is defined to be zero. A protocol chain has
/// the ChainLen member of the WSAPROTOCOL_INFO structure set to greater than 1.
///
///
/// During LSP initialization, the LSP must provide pointers to a number of Winsock SPI functions. These functions will be called
/// during normal processing by the layer directly above the LSP (either another LSP or Ws2_32.dll).
///
///
/// An LSP that implements an installable file system (IFS) can selectively choose to provide pointers to functions which are
/// implemented by itself, or pass back the pointers provided by the layer directly below the LSP. Non-IFS LSPs, because they
/// provide their own handles, must implement all of the Winsock SPI functions. This is because each SPI will require the LSP to map
/// all of the socket handles it created to the socket handle of the lower provider (either another LSP or the base protocol).
///
/// However, all LSPs perform their specific work by doing extra processing on only a subset of the Winsock SPI functions.
///
/// It is possible to define LSP categories based upon the subset of SPI functions an LSP implements and the nature of the extra
/// processing performed for each of those functions.
///
///
/// By classifying LSPs, as well as classifying applications which use Winsock sockets, it becomes possible to selectively determine
/// if an LSP should be involved in a given process at runtime.
///
///
/// On Windows Vista and later, an LSP can be classified based on how it interacts with Windows Sockets calls and data. An LSP
/// category is an identifiable group of behaviors on a subset of Winsock SPI functions. For example, an HTTP content filter would
/// be categorized as a data inspector (the LSP_INSPECTOR category). The LSP_INSPECTOR category will inspect, but not
/// alter, parameters to data transfer SPI functions. An application can query for the category of an LSP and choose to not load the
/// LSP based on the LSP category and the application's set of permitted LSP categories.
///
/// The following table lists categories into which an LSP can be classified.
///
///
/// LSP Category
/// Description
///
/// -
/// **LSP_CRYPTO_COMPRESS**
/// The LSP is a cryptography or data compression provider.
///
/// -
/// **LSP_FIREWALL**
/// The LSP is a firewall provider.
///
/// -
/// **LSP_LOCAL_CACHE**
/// The LSP is a local cache provider.
///
/// -
/// **LSP_INBOUND_MODIFY**
/// The LSP modifies inbound data.
///
/// -
/// **LSP_INSPECTOR**
/// The LSP inspects or filters data.
///
/// -
/// **LSP_OUTBOUND_MODIFY**
/// The LSP modifies outbound data.
///
/// -
/// **LSP_PROXY**
/// The LSP acts as a proxy and redirects packets.
///
/// -
/// **LSP_REDIRECTOR**
/// The LSP is a network redirector.
///
/// -
/// **LSP_SYSTEM**
/// The LSP is acceptable for use in services and system processes.
///
///
///
/// An LSP may belong to more than one category. For example, firewall/security LSP could belong to both the inspector (
/// LSP_INSPECTOR) and firewall ( LSP_FIREWALL) categories.
///
///
/// If an LSP does not have category set, it is considered to be in the All Other category. This LSP category will not be loaded in
/// services or system processes (for example, lsass, winlogon, and many svchost processes).
///
///
/// The WSCSetProviderInfo32 function can only be called by a user logged on as a member of the Administrators group. If
/// WSCSetProviderInfo32 is called by a user that is not a member of the Administrators group, the function call will fail
/// and WSANO_RECOVERY is returned in the lpErrno parameter. This function can also fail because of user account control
/// (UAC). If an application that contains this function is executed by a user logged on as a member of the Administrators group
/// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscsetproviderinfo32 int WSCSetProviderInfo32( LPGUID
// 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 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.
///
///
/// If no error occurs, WSCUnInstallNameSpace returns NO_ERROR (zero). Otherwise, it returns SOCKET_ERROR if
/// the function fails, and you must retrieve the appropriate error code using the WSAGetLastError function.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// The lpProviderId parameter points to memory that is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// The specified namespace–provider identifier is invalid.
///
/// -
/// WSASYSCALLFAILURE
/// A system call that should never fail has failed.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// The namespace configuration functions do not affect applications that are already running. Newly installed name-space providers
/// will not be visible to applications nor will the changes in a name-space provider's activation state. Applications launched
/// after the call to WSCUnInstallNameSpace will see the changes.
///
///
/// On success, WSCUnInstallNameSpace will attempt to alert all interested applications that have registered for notification
/// of the change by calling WSAProviderConfigChange.
///
///
/// The WSCUnInstallNameSpace function can only be called by a user logged on as a member of the Administrators group. If
/// WSCUnInstallNameSpace is called by a user that is not a member of the Administrators group, the function call will fail
/// and WSANO_RECOVERY is returned in the lpErrno parameter.
///
///
/// For computers running on Windows Vista or Windows Server 2008, this function can also fail because of user account control
/// (UAC). If an application that contains this function is executed by a user logged on as a member of the Administrators group
/// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
///
/// The caller of this function must remove any additional files or service provider–specific configuration information that is
/// required to completely uninstall the service provider.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscuninstallnamespace INT WSCUnInstallNameSpace( LPGUID
// lpProviderId );
[DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("ws2spi.h", MSDNShortId = "5267f986-99fc-4e53-9fbb-3850bb9d24cf")]
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.
///
///
/// If no error occurs, WSCUnInstallNameSpace32 returns NO_ERROR (zero). Otherwise, it returns SOCKET_ERROR if
/// the function fails, and you must retrieve the appropriate error code using the WSAGetLastError function.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// The lpProviderId parameter points to memory that is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// The specified namespace–provider identifier is invalid.
///
/// -
/// WSASYSCALLFAILURE
/// A system call that should never fail has failed.
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// WSCUnInstallNameSpace32 is a strictly 32-bit version of WSCUnInstallNameSpace. On a 64-bit computer, all calls not
/// specifically 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog. Processes that
/// execute on a 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog and preserve
/// compatibility. The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// The namespace configuration functions do not affect applications that are already running. Newly installed name-space providers
/// will not be visible to applications nor will the changes in a name-space provider's activation state. Applications launched
/// after the call to WSCUnInstallNameSpace32 will recognize the changes.
///
///
/// On success, WSCUnInstallNameSpace32 will attempt to alert all interested applications that have registered for
/// notification of the change by calling WSAProviderConfigChange.
///
///
/// The WSCUnInstallNameSpace32 function can only be called by a user logged on as a member of the Administrators group. If
/// WSCUnInstallNameSpace32 is called by a user that is not a member of the Administrators group, the function call will fail
/// and WSANO_RECOVERY is returned in the lpErrno parameter.
///
///
/// For computers running on Windows Vista or Windows Server 2008, this function can also fail because of user account control
/// (UAC). If an application that contains this function is executed by a user logged on as a member of the Administrators group
/// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
///
/// The caller of this function must remove any additional files or service provider–specific configuration information that is
/// required to completely uninstall the service provider.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscuninstallnamespace32 INT WSCUnInstallNameSpace32( LPGUID
// lpProviderId );
[DllImport(Lib.Ws2_32, SetLastError = true, ExactSpelling = true)]
[PInvokeData("ws2spi.h", MSDNShortId = "a2a08159-6ac0-493d-8f9f-d19aa199a65f")]
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.
///
/// A pointer to a Unicode string that contains the load path to the provider 64-bit DLL. This string observes the usual rules for
/// path resolution and can contain embedded environment strings (such as %SystemRoot%). Such environment strings are expanded when
/// the Ws2_32.dll must subsequently load the provider DLL on behalf of an application. After any embedded environment strings are
/// expanded, the Ws2_32.dll passes the resulting string to the LoadLibrary function which loads the provider into memory. For more
/// information, see LoadLibrary.
///
///
/// A pointer to an array of WSAProtocol_Info structures. Each structure specifies or modifies a protocol, address family, and
/// socket type supported by the provider.
///
/// The number of entries in the lpProtocolInfoList array.
/// A pointer to the error code if the function fails.
///
///
/// If no error occurs, WSCUpdateProvider returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error code
/// is returned in the lpErrno parameter.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// One or more of the arguments are not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the
/// administrative privileges required to write to the Winsock registry, or a failure occurred when opening or writing a catalog entry.
///
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// The WSCUpdateProvider function modifies Windows Sockets 2 configuration information for the specified provider. It is
/// applicable to base protocols, layered protocols, and protocol chains.
///
///
/// Winsock 2 accommodates layered protocols. A layered protocol is one that implements only higher level communications functions,
/// while relying on an underlying transport stack for the actual exchange of data with a remote endpoint. An example of a layered
/// protocol would be a security layer that adds protocol to the connection establishment process in order to perform authentication
/// and to establish a mutually agreed upon encryption scheme. Such a security protocol would generally require the services of an
/// underlying reliable transport protocol such as TCP or SPX. The term base protocol refers to a protocol such as TCP or SPX which
/// is capable of performing data communications with a remote endpoint. The term layered protocol is used to describe a protocol
/// that cannot stand alone. A protocol chain would then be defined as one or more layered protocols strung together and anchored by
/// a base protocol. A base protocol has the ChainLen member of the WSAProtocol_Info structure set to BASE_PROTOCOL
/// which is defined to be 1. A layered protocol has the ChainLen member of the WSAPROTOCOL_INFO structure set to
/// LAYERED_PROTOCOL which is defined to be zero. A protocol chain has the ChainLen member of the
/// WSAPROTOCOL_INFO structure set to greater than 1.
///
///
/// On success, WSCUpdateProvider will attempt to alert all interested applications that have registered for notification of
/// the change by calling WSAProviderConfigChange.
///
///
/// The WSCUpdateProvider function can only be called by a user logged on as a member of the Administrators group. If
/// WSCUpdateProvider is called by a user that is not a member of the Administrators group, the function call will fail.
///
///
/// For computers running on Windows Vista or Windows Server 2008, this function can also fail because of user account control
/// (UAC). If an application that contains this function is executed by a user logged on as a member of the Administrators group
/// other than the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator (RunAs administrator) for this function to succeed.
///
/// Any file installation or service provider-specific configuration must be performed by the caller.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscupdateprovider int WSCUpdateProvider( LPGUID lpProviderId,
// 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 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.
///
/// A pointer to a globally unique identifier (GUID) for the provider.
///
/// A pointer to a Unicode string that contains the load path to the provider 64-bit DLL. This string observes the usual rules for
/// path resolution and can contain embedded environment strings (such as %SystemRoot%). Such environment strings are expanded when
/// the Ws2_32.dll must subsequently load the provider DLL on behalf of an application. After any embedded environment strings are
/// expanded, the Ws2_32.dll passes the resulting string to the LoadLibrary function which loads the provider into memory. For more
/// information, see LoadLibrary.
///
///
/// A pointer to an array of WSAProtocol_Info structures. Each structure specifies or modifies a protocol, address family, and
/// socket type supported by the provider.
///
/// The number of entries in the lpProtocolInfoList array.
/// A pointer to the error code if the function fails.
///
///
/// If no error occurs, WSCUpdateProvider32 returns zero. Otherwise, it returns SOCKET_ERROR, and a specific error code is
/// available in lpErrno.
///
///
///
/// Error code
/// Meaning
///
/// -
/// WSAEFAULT
/// One or more of the arguments is not in a valid part of the user address space.
///
/// -
/// WSAEINVAL
/// One or more of the arguments are invalid.
///
/// -
/// WSANO_RECOVERY
///
/// A nonrecoverable error occurred. This error is returned under several conditions including the following: the user lacks the
/// administrative privileges required to write to the Winsock registry, or a failure occurred when opening or writing a catalog entry.
///
///
/// -
/// WSA_NOT_ENOUGH_MEMORY
///
/// Insufficient memory was available. This error is returned when there is insufficient memory to allocate a new catalog entry.
///
///
///
///
///
///
/// WSCUpdateProvider32 is a strictly 32-bit version of WSCUpdateProvider. On a 64-bit computer, all calls not specifically
/// 32-bit (for example, all functions that do not end in "32") operate on the native 64-bit catalog. Processes that execute on a
/// 64-bit computer must use the specific 32-bit function calls to operate on a strictly 32-bit catalog and preserve compatibility.
/// The definitions and semantics of the specific 32-bit calls are the same as their native counterparts.
///
///
/// This function modifies Windows Sockets 2 configuration information for the specified 32-bit provider. It is applicable to base
/// protocols, layered protocols, and protocol chains.
///
///
/// Winsock 2 accommodates layered protocols. A layered protocol is one that implements only higher level communications functions,
/// while relying on an underlying transport stack for the actual exchange of data with a remote endpoint. An example of a layered
/// protocol would be a security layer that adds protocol to the connection establishment process in order to perform authentication
/// and to establish a mutually agreed upon encryption scheme. Such a security protocol would generally require the services of an
/// underlying reliable transport protocol such as TCP or SPX. The term base protocol refers to a protocol such as TCP or SPX which
/// is capable of performing data communications with a remote endpoint. The term layered protocol is used to describe a protocol
/// that cannot stand alone. A protocol chain would then be defined as one or more layered protocols strung together and anchored by
/// a base protocol. A base protocol has the ChainLen member of the WSAProtocol_Info structure set to BASE_PROTOCOL
/// which is defined to be 1. A layered protocol has the ChainLen member of the WSAPROTOCOL_INFO structure set to
/// LAYERED_PROTOCOL which is defined to be zero. A protocol chain has the ChainLen member of the
/// WSAPROTOCOL_INFO structure set to greater than 1.
///
///
/// On success, WSCUpdateProvider32 will attempt to alert all interested applications that have registered for notification
/// of the change by calling WSAProviderConfigChange.
///
///
/// The WSCUpdateProvider32 function can only be called by a user logged on as a member of the Administrators group. If
/// WSCUpdateProvider32 is called by a user that is not a member of the Administrators group, the function call will fail.
///
///
/// For computers running Windows Vista or Windows Server 2008, this function can also fail because of user account control (UAC).
/// If an application that contains this function is executed by a user logged on as a member of the Administrators group other than
/// the built-in Administrator, this call will fail unless the application has been marked in the manifest file with a
/// requestedExecutionLevel set to requireAdministrator. If the application on Windows Vista or Windows Server 2008
/// lacks this manifest file, a user logged on as a member of the Administrators group other than the built-in Administrator must
/// then be executing the application in an enhanced shell as the built-in Administrator ( RunAs administrator) for this
/// function to succeed.
///
/// Any file installation or service provider-specific configuration must be performed by the caller.
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nf-ws2spi-wscupdateprovider32 int WSCUpdateProvider32( LPGUID
// lpProviderId, const WCHAR *lpszProviderDllPath, const LPWSAPROTOCOL_INFOW lpProtocolInfoList, DWORD dwNumberOfEntries, LPINT
// lpErrno );
[DllImport(Lib.Ws2_32, SetLastError = false, ExactSpelling = true)]
[PInvokeData("ws2spi.h", MSDNShortId = "803ef58a-853b-491c-bed1-e02275fef258")]
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
/// AFPROTOCOLS structure is used for query purposes only.
///
///
/// The members of the AFPROTOCOLS structure are a functional pair, and only have meaning when used together, as protocol
/// values have meaning only within the context of an address family.
///
// https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-afprotocols typedef struct _AFPROTOCOLS { INT
// iAddressFamily; INT iProtocol; } AFPROTOCOLS, *PAFPROTOCOLS, *LPAFPROTOCOLS;
[PInvokeData("winsock2.h", MSDNShortId = "ffd43aa1-bbc4-46f1-ad77-26c48f9ac0b7")]
[StructLayout(LayoutKind.Sequential)]
public struct AFPROTOCOLS
{
/// Address family to which the query is to be constrained.
public int iAddressFamily;
/// Protocol to which the query is to be constrained.
public int iProtocol;
}
/// The BLOB structure, derived from Binary Large Object, contains information about a block of data.
///
/// The structure name BLOB comes from the acronym BLOB, which stands for Binary Large Object.
/// This structure does not describe the nature of the data pointed to by pBlobData.
///
/// Note Windows Sockets defines a similar BLOB structure in Wtypes.h. Using both header files in the same source code
/// file creates redefinition–compile time errors.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/nspapi/ns-nspapi-blob typedef struct _BLOB { ULONG cbSize; #if ... BYTE
// *pBlobData; #else BYTE *pBlobData; #endif } BLOB, *LPBLOB;
[PInvokeData("nspapi.h", MSDNShortId = "eb1ff7d1-79db-478f-9f3e-48507d333c76")]
[StructLayout(LayoutKind.Sequential)]
public struct BLOB
{
/// Size of the block of data pointed to by pBlobData, in bytes.
public uint cbSize;
/// Pointer to a block of data.
public IntPtr pBlobData;
}
///
/// The NSPV2_ROUTINE structure contains information on the functions implemented by a namespace service provider version-2
/// (NSPv2) provider.
///
///
///
/// The NSPV2_ROUTINE structure is used as part of the namespace service provider version-2 (NSPv2) architecture available on
/// Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the NSPV2_ROUTINE structure can only be used for operations on NS_EMAIL
/// namespace providers.
///
///
/// The WSAAdvertiseProvider function advertises an instance of a NSPv2 provider for clients to find. The
/// WSAAdvertiseProvider caller passes a pointer to an NSPV2_ROUTINE structure in the pNSPv2Routine parameter with the
/// NSPv2 entry points supported by the provider.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/ns-ws2spi-nspv2_routine typedef struct _NSPV2_ROUTINE { DWORD cbSize;
// DWORD dwMajorVersion; DWORD dwMinorVersion; LPNSPV2STARTUP NSPv2Startup; LPNSPV2CLEANUP NSPv2Cleanup; LPNSPV2LOOKUPSERVICEBEGIN
// NSPv2LookupServiceBegin; LPNSPV2LOOKUPSERVICENEXTEX NSPv2LookupServiceNextEx; LPNSPV2LOOKUPSERVICEEND NSPv2LookupServiceEnd;
// LPNSPV2SETSERVICEEX NSPv2SetServiceEx; LPNSPV2CLIENTSESSIONRUNDOWN NSPv2ClientSessionRundown; } NSPV2_ROUTINE, *PNSPV2_ROUTINE, *LPNSPV2_ROUTINE;
[PInvokeData("ws2spi.h", MSDNShortId = "22a4ee47-030b-4aee-b9b1-c9e33b3e4fce")]
[StructLayout(LayoutKind.Sequential)]
public struct NSPV2_ROUTINE
{
///
/// Type: DWORD
/// The size, in bytes, of the structure.
///
public uint cbSize;
///
/// Type: DWORD
/// The major version of the service provider specification supported by this provider.
///
public uint dwMajorVersion;
///
/// Type: DWORD
/// The minor version of the service provider specification supported by this provider.
///
public uint dwMinorVersion;
///
/// Type: ** LPNSPV2STARTUP**
/// A pointer to the NSPv2Startup function for this NSPv2 provider.
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public LPNSPV2STARTUP NSPv2Startup;
///
/// Type: LPNSPV2CLEANUP
/// A pointer to the NSPv2Cleanup function for this NSPv2 provider.
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public LPNSPV2CLEANUP NSPv2Cleanup;
///
/// Type: LPNSPV2LOOKUPSERVICEBEGIN
/// A pointer to the NSPv2LookupServiceBegin function for this NSPv2 provider.
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public LPNSPV2LOOKUPSERVICEBEGIN NSPv2LookupServiceBegin;
///
/// Type: LPNSPV2LOOKUPSERVICENEXTEX
/// A pointer to the NSPv2LookupServiceNextEx function for this NSPv2 provider.
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public LPNSPV2LOOKUPSERVICENEXTEX NSPv2LookupServiceNextEx;
///
/// Type: LPNSPV2LOOKUPSERVICEEND
/// A pointer to the NSPv2LookupServiceEnd function for this NSPv2 provider.
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public LPNSPV2LOOKUPSERVICEEND NSPv2LookupServiceEnd;
///
/// Type: LPNSPV2SETSERVICEEX
/// A pointer to the NSPv2SetServiceEx function for this NSPv2 provider.
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public LPNSPV2SETSERVICEEX NSPv2SetServiceEx;
///
/// Type: LPNSPV2CLIENTSESSIONRUNDOWN
/// A pointer to the NSPv2ClientSessionRundown function for this NSPv2 provider.
///
[MarshalAs(UnmanagedType.FunctionPtr)]
public LPNSPV2CLIENTSESSIONRUNDOWN NSPv2ClientSessionRundown;
}
/// Provides a handle to a WSA event.
[StructLayout(LayoutKind.Sequential)]
public struct WSAEVENT : ISyncHandle
{
private readonly IntPtr handle;
/// Initializes a new instance of the struct.
/// An object that represents the pre-existing handle to use.
public WSAEVENT(IntPtr preexistingHandle) => handle = preexistingHandle;
/// Represents an invalid event handle.
public static WSAEVENT WSA_INVALID_EVENT => new(IntPtr.Zero);
/// Returns an invalid handle by instantiating a object with .
public static WSAEVENT NULL => new(IntPtr.Zero);
/// Gets a value indicating whether this instance is invalid.
public bool IsInvalid => handle == IntPtr.Zero;
/// Gets a value indicating whether this instance is a null handle.
public bool IsNull => handle == IntPtr.Zero;
/// Performs an explicit conversion from to .
/// The handle.
/// The result of the conversion.
public static explicit operator IntPtr(WSAEVENT h) => h.handle;
/// Performs an implicit conversion from to .
/// The pointer to a handle.
/// The result of the conversion.
public static implicit operator WSAEVENT(IntPtr h) => new(h);
/// Implements the operator !=.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator !=(WSAEVENT h1, WSAEVENT h2) => !(h1 == h2);
/// Implements the operator ==.
/// The first handle.
/// The second handle.
/// The result of the operator.
public static bool operator ==(WSAEVENT h1, WSAEVENT h2) => h1.Equals(h2);
///
public override bool Equals(object obj) => obj is WSAEVENT h && handle == h.handle;
///
public override int GetHashCode() => handle.GetHashCode();
///
public IntPtr DangerousGetHandle() => handle;
}
/// The WSANAMESPACE_INFOEX structure contains all registration information for a namespace provider.
///
///
/// The WSANAMESPACE_INFOEX structure is an enhanced version of the WSANAMESPACE_INFO structure that is used by the
/// WSAEnumNameSpaceProvidersEx and the WSCEnumNameSpaceProvidersEx32 functions to return information on available namespace
/// providers. The WSANAMESPACE_INFOEX structure contains the provider-specific data blob associated with the namespace entry
/// passed in the lpProviderInfo parameter to the WSCInstallNameSpaceEx and WSCInstallNameSpaceEx32 functions.
///
///
/// Currently, the only namespace included with Windows that uses information in the ProviderSpecific member of the
/// WSANAMESPACE_INFOEX structure are namespace providers for the NS_EMAIL namespace. The format of the
/// ProviderSpecific member for an NS_EMAIL namespace provider is a NAPI_PROVIDER_INSTALLATION_BLOB structure.
///
///
/// When UNICODE or _UNICODE is defined, WSANAMESPACE_INFOEX is defined to WSANAMESPACE_INFOEXW, the Unicode version
/// of this structure and the lpszIdentifier string member is defined to the LPWSTR data type.
///
///
/// When UNICODE or _UNICODE is not defined, WSANAMESPACE_INFOEX is defined to WSANAMESPACE_INFOEXA, the ANSI version
/// of this structure and the lpszIdentifier string member is defined to the LPSTR data type.
///
/// The WSCEnumNameSpaceProvidersEx32 function is a Unicode only function and returns WSANAMESPACE_INFOEXW structures.
///
// https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-wsanamespace_infoexw typedef struct _WSANAMESPACE_INFOEXW
// { GUID NSProviderId; DWORD dwNameSpace; BOOL fActive; DWORD dwVersion; LPWSTR lpszIdentifier; BLOB ProviderSpecific; }
// WSANAMESPACE_INFOEXW, *PWSANAMESPACE_INFOEXW, *LPWSANAMESPACE_INFOEXW;
[PInvokeData("winsock2.h", MSDNShortId = "3f4a8916-9db9-4b65-982f-4cb4ec2205ed")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WSANAMESPACE_INFOEXW
{
///
/// Type: GUID
/// A unique GUID for this namespace provider.
///
public Guid NSProviderId;
///
/// Type: DWORD
/// The namespace supported by this provider.
///
/// Possible values for the dwNameSpace member are listed in the Winsock2.h include file. Several namespace providers are
/// included with Windows Vista and later. Other namespace providers can be installed, so the following possible values are only
/// those commonly available. Many other values are possible.
///
///
///
/// Value
/// Meaning
///
/// -
/// NS_BTH
/// The Bluetooth namespace. This namespace identifier is supported on Windows Vista and later.
///
/// -
/// NS_DNS
/// The domain name system (DNS) namespace.
///
/// -
/// NS_EMAIL
/// The email namespace. This namespace identifier is supported on Windows Vista and later.
///
/// -
/// NS_NLA
/// The network location awareness (NLA) namespace. This namespace identifier is supported on Windows XP and later.
///
/// -
/// NS_NTDS
/// The Windows NT directory service (NTDS) namespace.
///
/// -
/// NS_PNRPNAME
///
/// The peer-to-peer name space for a specific peer name. This namespace identifier is supported on Windows Vista and later.
///
///
/// -
/// NS_PNRPCLOUD
///
/// The peer-to-peer name space for a collection of peer names. This namespace identifier is supported on Windows Vista and later.
///
///
///
///
public NS dwNameSpace;
///
/// Type: BOOL
///
/// If TRUE, indicates that this namespace provider is active. If FALSE, the namespace provider is inactive and is
/// not accessible for queries, even if the query specifically references this namespace provider.
///
///
[MarshalAs(UnmanagedType.Bool)] public bool fActive;
///
/// Type: DWORD
/// The version number of the namespace provider.
///
public uint dwVersion;
///
/// Type: LPTSTR
/// A display string that identifies the namespace provider.
///
public StrPtrUni lpszIdentifier;
///
/// Type: BLOB
/// A provider-specific data blob associated with namespace entry.
///
public BLOB ProviderSpecific;
}
/// The WSANAMESPACE_INFO structure contains all registration information for a namespace provider.
///
///
/// The WSANAMESPACE_INFO structure is used by the WSAEnumNameSpaceProvidersand WSCEnumNameSpaceProviders32 functions to
/// return information on available namespace providers. The WSANAMESPACE_INFO structure contains the provider-specific
/// information on the namespace entry passed to the WSCInstallNameSpace and WSCInstallNameSpace32 functions when the namespace
/// provider was installed.
///
///
/// When UNICODE or _UNICODE is defined, WSANAMESPACE_INFO is defined to WSANAMESPACE_INFOW, the Unicode version of
/// this data structure and the lpszIdentifier string member is defined to the LPWSTR data type.
///
///
/// When UNICODE or _UNICODE is not defined, WSANAMESPACE_INFO is defined to WSANAMESPACE_INFOA, the ANSI version of
/// this data structure and the lpszIdentifier string member is defined to the LPSTR data type.
///
///
/// On Windows Vista and later, WSANAMESPACE_INFOEX, an enhanced version of the WSANAMESPACE_INFO structure, is returned by
/// calls to the WSAEnumNameSpaceProvidersEx and WSCEnumNameSpaceProvidersEx32 functions
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-wsanamespace_infow typedef struct _WSANAMESPACE_INFOW {
// GUID NSProviderId; DWORD dwNameSpace; BOOL fActive; DWORD dwVersion; LPWSTR lpszIdentifier; } WSANAMESPACE_INFOW,
// *PWSANAMESPACE_INFOW, *LPWSANAMESPACE_INFOW;
[PInvokeData("winsock2.h", MSDNShortId = "a5c76657-df62-471a-95e9-8017cad47b00")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WSANAMESPACE_INFOW
{
///
/// Type: GUID
/// A unique GUID for this namespace provider.
///
public Guid NSProviderId;
///
/// Type: DWORD
/// The namespace supported by this provider.
///
/// Possible values for the dwNameSpace member are listed in the Winsock2.h include file. Several namespace providers are
/// included with Windows Vista and later. Other namespace providers can be installed, so the following possible values are only
/// those commonly available. Many other values are possible.
///
///
///
/// Value
/// Meaning
///
/// -
/// NS_BTH
/// The Bluetooth namespace. This namespace identifier is supported on Windows Vista and later.
///
/// -
/// NS_DNS
/// The domain name system (DNS) namespace.
///
/// -
/// NS_EMAIL
/// The email namespace. This namespace identifier is supported on Windows Vista and later.
///
/// -
/// NS_NLA
/// The network location awareness (NLA) namespace. This namespace identifier is supported on Windows XP and later.
///
/// -
/// NS_NTDS
/// The Windows NT directory service (NTDS) namespace.
///
/// -
/// NS_PNRPNAME
///
/// The peer-to-peer name space for a specific peer name. This namespace identifier is supported on Windows Vista and later.
///
///
/// -
/// NS_PNRPCLOUD
///
/// The peer-to-peer name space for a collection of peer names. This namespace identifier is supported on Windows Vista and later.
///
///
///
///
public NS dwNameSpace;
///
/// Type: BOOL
///
/// If TRUE, indicates that this namespace provider is active. If FALSE, the namespace provider is inactive and is
/// not accessible for queries, even if the query specifically references this namespace provider.
///
///
[MarshalAs(UnmanagedType.Bool)] public bool fActive;
///
/// Type: DWORD
/// The version number of the namespace provider.
///
public uint dwVersion;
///
/// Type: LPTSTR
/// A display string that identifies the namespace provider.
///
public StrPtrUni lpszIdentifier;
}
///
/// The WSAOVERLAPPED structure provides a communication medium between the initiation of an overlapped I/O operation and its
/// subsequent completion. The WSAOVERLAPPED structure is compatible with the Windows OVERLAPPED structure.
///
// https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-wsaoverlapped typedef struct _WSAOVERLAPPED { DWORD
// Internal; DWORD InternalHigh; DWORD Offset; DWORD OffsetHigh; WSAEVENT hEvent; } WSAOVERLAPPED, *LPWSAOVERLAPPED;
[PInvokeData("winsock2.h", MSDNShortId = "91004241-e0ea-4bda-a0f5-71688ac83038")]
[StructLayout(LayoutKind.Sequential)]
public struct WSAOVERLAPPED
{
///
/// Type: ULONG_PTR
///
/// Reserved for internal use. The Internal member is used internally by the entity that implements overlapped I/O. For service
/// providers that create sockets as installable file system (IFS) handles, this parameter is used by the underlying operating
/// system. Other service providers (non-IFS providers) are free to use this parameter as necessary.
///
///
public uint Internal;
///
/// Type: ULONG_PTR
///
/// Reserved. Used internally by the entity that implements overlapped I/O. For service providers that create sockets as IFS
/// handles, this parameter is used by the underlying operating system. NonIFS providers are free to use this parameter as necessary.
///
///
public uint InternalHigh;
///
/// Type: DWORD
/// Reserved for use by service providers.
///
public uint Offset;
///
/// Type: DWORD
/// Reserved for use by service providers.
///
public uint OffsetHigh;
///
/// Type: HANDLE
///
/// If an overlapped I/O operation is issued without an I/O completion routine (the operation's lpCompletionRoutine parameter is
/// set to null), then this parameter should either contain a valid handle to a WSAEVENT object or be null. If the
/// lpCompletionRoutine parameter of the call is non-null then applications are free to use this parameter as necessary.
///
///
public WSAEVENT hEvent;
}
///
/// The WSAPROTOCOL_INFOW structure is used to store or retrieve complete information for a given protocol. The protocol name
/// is represented as an array of Unicode characters.
///
// https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-wsaprotocol_infow typedef struct _WSAPROTOCOL_INFOW {
// DWORD dwServiceFlags1; DWORD dwServiceFlags2; DWORD dwServiceFlags3; DWORD dwServiceFlags4; DWORD dwProviderFlags; GUID
// ProviderId; DWORD dwCatalogEntryId; WSAPROTOCOLCHAIN ProtocolChain; int iVersion; int iAddressFamily; int iMaxSockAddr; int
// iMinSockAddr; int iSocketType; int iProtocol; int iProtocolMaxOffset; int iNetworkByteOrder; int iSecurityScheme; DWORD
// dwMessageSize; DWORD dwProviderReserved; WCHAR szProtocol[WSAPROTOCOL_LEN + 1]; } WSAPROTOCOL_INFOW, *LPWSAPROTOCOL_INFOW;
[PInvokeData("winsock2.h", MSDNShortId = "be5f3e81-1442-43c7-9e4e-9eb2b2a05132")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WSAPROTOCOL_INFOW
{
///
/// Type: DWORD
///
/// A bitmask that describes the services provided by the protocol. The possible values for this member are defined in the
/// Winsock2.h header file.
///
/// The following values are possible.
///
///
/// Value
/// Meaning
///
/// -
/// XP1_CONNECTIONLESS 0x00000001
/// Provides connectionless (datagram) service. If not set, the protocol supports connection-oriented data transfer.
///
/// -
/// XP1_GUARANTEED_DELIVERY 0x00000002
/// Guarantees that all data sent will reach the intended destination.
///
/// -
/// XP1_GUARANTEED_ORDER 0x00000004
///
/// Guarantees that data only arrives in the order in which it was sent and that it is not duplicated. This characteristic does
/// not necessarily mean that the data is always delivered, but that any data that is delivered is delivered in the order in
/// which it was sent.
///
///
/// -
/// XP1_MESSAGE_ORIENTED 0x00000008
/// Honors message boundaries—as opposed to a stream-oriented protocol where there is no concept of message boundaries.
///
/// -
/// XP1_PSEUDO_STREAM 0x00000010
///
/// A message-oriented protocol, but message boundaries are ignored for all receipts. This is convenient when an application
/// does not desire message framing to be done by the protocol.
///
///
/// -
/// XP1_GRACEFUL_CLOSE 0x00000020
/// Supports two-phase (graceful) close. If not set, only abortive closes are performed.
///
/// -
/// XP1_EXPEDITED_DATA 0x00000040
/// Supports expedited (urgent) data.
///
/// -
/// XP1_CONNECT_DATA 0x00000080
/// Supports connect data.
///
/// -
/// XP1_DISCONNECT_DATA 0x00000100
/// Supports disconnect data.
///
/// -
/// XP1_SUPPORT_BROADCAST 0x00000200
/// Supports a broadcast mechanism.
///
/// -
/// XP1_SUPPORT_MULTIPOINT 0x00000400
/// Supports a multipoint or multicast mechanism. Control and data plane attributes are indicated below.
///
/// -
/// XP1_MULTIPOINT_CONTROL_PLANE 0x00000800
/// Indicates whether the control plane is rooted (value = 1) or nonrooted (value = 0).
///
/// -
/// XP1_MULTIPOINT_DATA_PLANE 0x00001000
/// Indicates whether the data plane is rooted (value = 1) or nonrooted (value = 0).
///
/// -
/// XP1_QOS_SUPPORTED 0x00002000
/// Supports quality of service requests.
///
/// -
/// XP1_INTERRUPT
/// Bit is reserved.
///
/// -
/// XP1_UNI_SEND 0x00008000
/// Protocol is unidirectional in the send direction.
///
/// -
/// XP1_UNI_RECV 0x00010000
/// Protocol is unidirectional in the recv direction.
///
/// -
/// XP1_IFS_HANDLES 0x00020000
/// Socket descriptors returned by the provider are operating system Installable File System (IFS) handles.
///
/// -
/// XP1_PARTIAL_MESSAGE 0x00040000
/// The MSG_PARTIAL flag is supported in WSASend and WSASendTo.
///
/// -
/// XP1_SAN_SUPPORT_SDP 0x00080000
/// The protocol provides support for SAN. This value is supported on Windows 7 and Windows Server 2008 R2.
///
///
///
/// Note Only one of XP1_UNI_SEND or XP1_UNI_RECV values may be set. If a protocol can be unidirectional in either
/// direction, two WSAPROTOCOL_INFOW structures should be used. When neither bit is set, the protocol is considered to be bidirectional.
///
///
public XP1 dwServiceFlags1;
///
/// Type: DWORD
/// Reserved for additional protocol-attribute definitions.
///
public uint dwServiceFlags2;
///
/// Type: DWORD
/// Reserved for additional protocol-attribute definitions.
///
public uint dwServiceFlags3;
///
/// Type: DWORD
/// Reserved for additional protocol-attribute definitions.
///
public uint dwServiceFlags4;
///
/// Type: DWORD
///
/// A set of flags that provides information on how this protocol is represented in the Winsock catalog. The possible values for
/// this member are defined in the Winsock2.h header file.
///
/// The following values are possible.
///
///
/// Value
/// Meaning
///
/// -
/// PFL_MULTIPLE_PROTO_ENTRIES 0x00000001
///
/// Indicates that this is one of two or more entries for a single protocol (from a given provider) which is capable of
/// implementing multiple behaviors. An example of this is SPX which, on the receiving side, can behave either as a
/// message-oriented or a stream-oriented protocol.
///
///
/// -
/// PFL_RECOMMENDED_PROTO_ENTRY 0x00000002
///
/// Indicates that this is the recommended or most frequently used entry for a protocol that is capable of implementing multiple behaviors.
///
///
/// -
/// PFL_HIDDEN 0x00000004
///
/// Set by a provider to indicate to the Ws2_32.dll that this protocol should not be returned in the result buffer generated by
/// WSAEnumProtocols. Obviously, a Windows Sockets 2 application should never see an entry with this bit set.
///
///
/// -
/// PFL_MATCHES_PROTOCOL_ZERO 0x00000008
/// Indicates that a value of zero in the protocol parameter of socket or WSASocket matches this protocol entry.
///
/// -
/// PFL_NETWORKDIRECT_PROVIDER 0x00000010
///
/// Set by a provider to indicate support for network direct access. This value is supported on Windows 7 and Windows Server
/// 2008 R2.
///
///
///
///
public PFL dwProviderFlags;
///
/// Type: GUID
///
/// A globally unique identifier (GUID) assigned to the provider by the service provider vendor. This value is useful for
/// instances where more than one service provider is able to implement a particular protocol. An application can use the
/// ProviderId member to distinguish between providers that might otherwise be indistinguishable.
///
///
public Guid ProviderId;
///
/// Type: DWORD
/// A unique identifier assigned by the WS2_32.DLL for each WSAPROTOCOL_INFO structure.
///
public uint dwCatalogEntryId;
///
/// Type: WSAPROTOCOLCHAIN
///
/// The WSAPROTOCOLCHAIN structure associated with the protocol. If the length of the chain is 0, this WSAPROTOCOL_INFO entry
/// represents a layered protocol which has Windows Sockets 2 SPI as both its top and bottom edges. If the length of the chain
/// equals 1, this entry represents a base protocol whose Catalog Entry identifier is in the dwCatalogEntryId member of
/// the WSAPROTOCOL_INFO structure. If the length of the chain is larger than 1, this entry represents a protocol chain
/// which consists of one or more layered protocols on top of a base protocol. The corresponding Catalog Entry identifiers are
/// in the ProtocolChain.ChainEntries array starting with the layered protocol at the top (the zero element in the
/// ProtocolChain.ChainEntries array) and ending with the base protocol. Refer to the Windows Sockets 2 Service Provider
/// Interface specification for more information on protocol chains.
///
///
public WSAPROTOCOLCHAIN ProtocolChain;
///
/// Type: int
/// The protocol version identifier.
///
public int iVersion;
///
/// Type: int
///
/// A value to pass as the address family parameter to the socket or WSASocket function in order to open a socket for this
/// protocol. This value also uniquely defines the structure of a protocol address for a sockaddr used by the protocol.
///
///
/// On the Windows SDK released for Windows Vista and later, the possible values for the address family are defined in the
/// Ws2def.h header file. Note that the Ws2def.h header file is automatically included in Winsock2.h, and should never be used directly.
///
///
/// On versions of the Platform SDK for Windows Server 2003 and older, the possible values for the address family are defined in
/// the Winsock2.h header file.
///
///
/// The values currently supported are AF_INET or AF_INET6, which are the Internet address family formats for IPv4 and IPv6.
/// Other options for address family (AF_NETBIOS for use with NetBIOS, for example) are supported if a Windows Sockets service
/// provider for the address family is installed. Note that the values for the AF_ address family and PF_ protocol family
/// constants are identical (for example, AF_INET and PF_INET), so either constant can be used.
///
/// The table below lists common values for address family although many other values are possible.
///
///
/// iAddressFamily
/// Meaning
///
/// -
/// AF_INET 2
/// The Internet Protocol version 4 (IPv4) address family.
///
/// -
/// AF_IPX 6
///
/// The IPX/SPX address family. This address family is only supported if the NWLink IPX/SPX NetBIOS Compatible Transport
/// protocol is installed. This address family is not supported on Windows Vista and later.
///
///
/// -
/// AF_APPLETALK 16
///
/// The AppleTalk address family. This address family is only supported if the AppleTalk protocol is installed. This address
/// family is not supported on Windows Vista and later.
///
///
/// -
/// AF_NETBIOS 17
///
/// The NetBIOS address family. This address family is only supported if the Windows Sockets provider for NetBIOS is installed.
/// The Windows Sockets provider for NetBIOS is supported on 32-bit versions of Windows. This provider is installed by default
/// on 32-bit versions of Windows. The Windows Sockets provider for NetBIOS is not supported on 64-bit versions of windows
/// including Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, or Windows XP. The Windows Sockets provider
/// for NetBIOS only supports sockets where the type parameter is set to SOCK_DGRAM. The Windows Sockets provider for NetBIOS is
/// not directly related to the NetBIOS programming interface. The NetBIOS programming interface is not supported on Windows
/// Vista, Windows Server 2008, and later.
///
///
/// -
/// AF_INET6 23
/// The Internet Protocol version 6 (IPv6) address family.
///
/// -
/// AF_IRDA 26
///
/// The Infrared Data Association (IrDA) address family. This address family is only supported if the computer has an infrared
/// port and driver installed.
///
///
/// -
/// AF_BTH 32
///
/// The Bluetooth address family. This address family is supported on Windows XP with SP2 or later if the computer has a
/// Bluetooth adapter and driver installed.
///
///
///
///
public int iAddressFamily;
///
/// Type: int
/// The maximum address length, in bytes.
///
public int iMaxSockAddr;
///
/// Type: int
/// The minimum address length, in bytes.
///
public int iMinSockAddr;
///
/// Type: int
///
/// A value to pass as the socket type parameter to the socket or WSASocket function in order to open a socket for this
/// protocol. Possible values for the socket type are defined in the Winsock2.h header file.
///
/// The following table lists the possible values for the iSocketType member supported for Windows Sockets 2:
///
///
/// iSocketType
/// Meaning
///
/// -
/// SOCK_STREAM 1
///
/// A socket type that provides sequenced, reliable, two-way, connection-based byte streams with an OOB data transmission
/// mechanism. This socket type uses the Transmission Control Protocol (TCP) for the Internet address family (AF_INET or AF_INET6).
///
///
/// -
/// SOCK_DGRAM 2
///
/// A socket type that supports datagrams, which are connectionless, unreliable buffers of a fixed (typically small) maximum
/// length. This socket type uses the User Datagram Protocol (UDP) for the Internet address family (AF_INET or AF_INET6).
///
///
/// -
/// SOCK_RAW 3
///
/// A socket type that provides a raw socket that allows an application to manipulate the next upper-layer protocol header. To
/// manipulate the IPv4 header, the IP_HDRINCL socket option must be set on the socket. To manipulate the IPv6 header, the
/// IPV6_HDRINCL socket option must be set on the socket.
///
///
/// -
/// SOCK_RDM 4
///
/// A socket type that provides a reliable message datagram. An example of this type is the Pragmatic General Multicast (PGM)
/// multicast protocol implementation in Windows, often referred to as reliable multicast programming. This value is only
/// supported if the Reliable Multicast Protocol is installed.
///
///
/// -
/// SOCK_SEQPACKET 5
/// A socket type that provides a pseudo-stream packet based on datagrams.
///
///
///
public SOCK iSocketType;
///
/// Type: int
///
/// A value to pass as the protocol parameter to the socket or WSASocket function in order to open a socket for this protocol.
/// The possible options for the iProtocol member are specific to the address family and socket type specified.
///
///
/// On the Windows SDK released for Windows Vista and later, this member can be one of the values from the IPPROTO
/// enumeration type defined in the Ws2def.h header file. Note that the Ws2def.h header file is automatically included in
/// Winsock2.h, and should never be used directly.
///
///
/// On versions of the Platform SDK for Windows Server 2003 and earlier, the possible values for the iProtocol member are
/// defined in the Winsock2.h and Wsrm.h header files.
///
/// The table below lists common values for the iProtocol although many other values are possible.
///
///
/// iProtocol
/// Meaning
///
/// -
/// IPPROTO_ICMP 1
/// The Internet Control Message Protocol (ICMP). This value is supported on Windows XP and later.
///
/// -
/// IPPROTO_IGMP 2
/// The Internet Group Management Protocol (IGMP). This value is supported on Windows XP and later.
///
/// -
/// BTHPROTO_RFCOMM 3
///
/// The Bluetooth Radio Frequency Communications (Bluetooth RFCOMM) protocol. This value is supported on Windows XP with SP2 or later.
///
///
/// -
/// IPPROTO_TCP 6
/// The Transmission Control Protocol (TCP).
///
/// -
/// IPPROTO_UDP 17
/// The User Datagram Protocol (UDP).
///
/// -
/// IPPROTO_ICMPV6 58
/// The Internet Control Message Protocol Version 6 (ICMPv6). This value is supported on Windows XP and later.
///
/// -
/// IPPROTO_RM 113
///
/// The PGM protocol for reliable multicast. On the Windows SDK released for Windows Vista and later, this protocol is also
/// called IPPROTO_PGM. This value is only supported if the Reliable Multicast Protocol is installed.
///
///
///
///
public IPPROTO iProtocol;
///
/// Type: int
///
/// The maximum value that may be added to iProtocol member when supplying a value for the protocol parameter to socket
/// and WSASocket. Not all protocols allow a range of values. When this is the case iProtocolMaxOffset is zero.
///
///
public int iProtocolMaxOffset;
///
/// Type: int
///
/// Currently these values are manifest constants (BIGENDIAN and LITTLEENDIAN) that indicate either big-endian or little-endian
/// with the values 0 and 1 respectively.
///
///
public int iNetworkByteOrder;
///
/// Type: int
///
/// The type of security scheme employed (if any). A value of SECURITY_PROTOCOL_NONE (0) is used for protocols that do not
/// incorporate security provisions.
///
///
public int iSecurityScheme;
///
/// Type: DWORD
///
/// The maximum message size, in bytes, supported by the protocol. This is the maximum size that can be sent from any of the
/// host's local interfaces. For protocols that do not support message framing, the actual maximum that can be sent to a given
/// address may be less. There is no standard provision to determine the maximum inbound message size. The following special
/// values are defined.
///
///
///
/// Value
/// Meaning
///
/// -
/// 0
/// The protocol is stream-oriented and hence the concept of message size is not relevant.
///
/// -
/// 0x1
///
/// The maximum outbound (send) message size is dependent on the underlying network MTU (maximum sized transmission unit) and
/// hence cannot be known until after a socket is bound. Applications should use getsockopt to retrieve the value of
/// SO_MAX_MSG_SIZE after the socket has been bound to a local address.
///
///
/// -
/// 0xFFFFFFFF
/// The protocol is message-oriented, but there is no maximum limit to the size of messages that may be transmitted.
///
///
///
public uint dwMessageSize;
///
/// Type: DWORD
/// Reserved for use by service providers.
///
public uint dwProviderReserved;
///
/// Type: WCHAR[WSAPROTOCOL_LEN+1]
///
/// An array of Unicode characters that contains a human-readable name identifying the protocol, for example "MSAFD Tcpip
/// [UDP/IP]". The maximum number of characters allowed is WSAPROTOCOL_LEN, which is defined to be 255.
///
///
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string szProtocol;
}
///
/// The WSAQUERYSET2 structure provides relevant information about a given service, including service class ID, service name
/// , applicable namespace identifier and protocol information, as well as a set of transport addresses at which the service listens.
///
///
///
/// The WSAQUERYSET2 structure is used as part of the namespace service provider version-2 (NSPv2) architecture available on
/// Windows Vista and later.
///
///
/// On Windows Vista and Windows Server 2008, the WSAQUERYSET2 structure can only be used for operations on NS_EMAIL
/// namespace providers.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-wsaqueryset2w typedef struct _WSAQuerySet2W { DWORD
// dwSize; LPWSTR lpszServiceInstanceName; LPWSAVERSION lpVersion; LPWSTR lpszComment; DWORD dwNameSpace; LPGUID lpNSProviderId;
// LPWSTR lpszContext; DWORD dwNumberOfProtocols; LPAFPROTOCOLS lpafpProtocols; LPWSTR lpszQueryString; DWORD dwNumberOfCsAddrs;
// LPCSADDR_INFO lpcsaBuffer; DWORD dwOutputFlags; LPBLOB lpBlob; } WSAQUERYSET2W, *PWSAQUERYSET2W, *LPWSAQUERYSET2W;
[PInvokeData("winsock2.h", MSDNShortId = "ffe71de0-3561-481f-b81f-835c6c3a3ee4")]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WSAQUERYSET2W
{
///
/// Type: DWORD
///
/// The size, in bytes, of the WSAQUERYSET2 structure. This member is used as a versioning mechanism since the size of
/// the WSAQUERYSET2 structure may change on later versions of Windows.
///
///
public uint dwSize;
///
/// Type: LPTSTR
///
/// A pointer to an optional NULL-terminated string that contains service name. The semantics for using wildcards within
/// the string are not defined, but can be supported by certain namespace providers.
///
///
[MarshalAs(UnmanagedType.LPTStr)] public string lpszServiceInstanceName;
///
/// Type: LPWSAVERSION
///
/// A pointer to an optional desired version number of the namespace provider. This member provides version comparison semantics
/// (that is, the version requested must match exactly, or version must be not less than the value supplied).
///
///
public IntPtr lpVersion;
///
/// Type: LPTSTR
/// This member is ignored for queries.
///
[MarshalAs(UnmanagedType.LPTStr)] public string lpszComment;
///
/// Type: DWORD
///
/// A namespace identifier that determines which namespace providers are queried. Passing a specific namespace identifier will
/// result in only namespace providers that support the specified namespace being queried. Specifying NS_ALL will result
/// in all installed and active namespace providers being queried.
///
///
/// Options for the dwNameSpace member are listed in the Winsock2.h include file. Several new namespace providers are
/// included with Windows Vista and later. Other namespace providers can be installed, so the following possible values are only
/// those commonly available. Many other values are possible.
///
///
///
/// Value
/// Meaning
///
/// -
/// NS_ALL
/// All installed and active namespaces.
///
/// -
/// NS_BTH
/// The Bluetooth namespace. This namespace identifier is supported on Windows Vista and later.
///
/// -
/// NS_DNS
/// The domain name system (DNS) namespace.
///
/// -
/// NS_EMAIL
/// The email namespace. This namespace identifier is supported on Windows Vista and later.
///
/// -
/// NS_NLA
/// The network location awareness (NLA) namespace. This namespace identifier is supported on Windows XP and later.
///
/// -
/// NS_PNRPNAME
///
/// The peer-to-peer name space for a specific peer name. This namespace identifier is supported on Windows Vista and later.
///
///
/// -
/// NS_PNRPCLOUD
///
/// The peer-to-peer name space for a collection of peer names. This namespace identifier is supported on Windows Vista and later.
///
///
///
///
public NS dwNameSpace;
///
/// Type: LPGUID
///
/// A pointer to an optional GUID of a specific namespace provider to query in the case where multiple namespace providers are
/// registered under a single namespace such as NS_DNS. Passing the GUID for a specific namespace provider will result in
/// only the specified namespace provider being queried. The WSAEnumNameSpaceProviders and WSAEnumNameSpaceProvidersEx functions
/// can be called to retrieve the GUID for a namespace provider.
///
///
public GuidPtr lpNSProviderId;
///
/// Type: LPTSTR
/// A pointer to an optional starting point of the query in a hierarchical namespace.
///
[MarshalAs(UnmanagedType.LPTStr)] public string lpszContext;
///
/// Type: DWORD
/// The size, in bytes, of the protocol constraint array. This member can be zero.
///
public uint dwNumberOfProtocols;
///
/// Type: LPAFPROTOCOLS
/// A pointer to an optional array of AFPROTOCOLS structures. Only services that utilize these protocols will be returned.
///
public IntPtr lpafpProtocols;
///
/// Type: LPTSTR
///
/// A pointer to an optional NULL-terminated query string. Some namespaces, such as Whois++, support enriched SQL-like
/// queries that are contained in a simple text string. This parameter is used to specify that string.
///
///
[MarshalAs(UnmanagedType.LPTStr)] public string lpszQueryString;
///
/// Type: DWORD
/// This member is ignored for queries.
///
public uint dwNumberOfCsAddrs;
///
/// Type: LPCSADDR_INFO
/// This member is ignored for queries.
///
public IntPtr lpcsaBuffer;
///
/// Type: DWORD
/// This member is ignored for queries.
///
public uint dwOutputFlags;
///
/// Type: LPBLOB
///
/// An optional pointer to data that is used to query or set provider-specific namespace information. The format of this
/// information is specific to the namespace provider.
///
///
public IntPtr lpBlob;
}
/// The WSAVERSION structure provides version comparison in Windows Sockets.
// https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-wsaversion typedef struct _WSAVersion { DWORD dwVersion;
// WSAECOMPARATOR ecHow; } WSAVERSION, *PWSAVERSION, *LPWSAVERSION;
[PInvokeData("winsock2.h", MSDNShortId = "27af3b20-9460-466d-bc58-5e31e08bb6c8")]
[StructLayout(LayoutKind.Sequential)]
public struct WSAVERSION
{
/// Version of Windows Sockets.
public uint dwVersion;
/// WSAECOMPARATOR enumeration, used in the comparison.
public WSAECOMPARATOR ecHow;
}
}
}