Added overloads with more precise params to WinSock2 functions

pull/350/head
David Hall 2022-10-27 21:36:32 -06:00
parent 326692ab25
commit 3b75625c80
3 changed files with 2587 additions and 459 deletions

View File

@ -387,5 +387,17 @@ namespace Vanara.PInvoke
/// <summary/>
WSA_FLAG_REGISTERED_IO = 0x100,
}
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
[PInvokeData("winsock2.h")]
public enum WSACOMPLETIONTYPE
{
NSP_NOTIFY_IMMEDIATELY,
NSP_NOTIFY_HWND,
NSP_NOTIFY_EVENT,
NSP_NOTIFY_PORT,
NSP_NOTIFY_APC,
}
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
}
}

View File

@ -6,11 +6,11 @@ using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
namespace Vanara.PInvoke
namespace Vanara.PInvoke;
/// <summary>Functions, structures and constants from ws2_32.h.</summary>
public static partial class Ws2_32
{
/// <summary>Functions, structures and constants from ws2_32.h.</summary>
public static partial class Ws2_32
{
/// <summary>
/// The <c>fd_set</c> structure is used by various Windows Sockets functions and service providers, such as the select function, to
/// place sockets into a "set" for various purposes, such as testing a given socket for readability using the readfds parameter of
@ -30,6 +30,137 @@ namespace Vanara.PInvoke
public SOCKET[] fd_array;
}
/// <summary>
/// The <c>WSACOMPLETION</c> structure specifies completion notification settings for I/O control calls made to a registered namespace.
/// </summary>
/// <remarks>
/// <para>
/// The <c>WSACOMPLETION</c> structure enables callbacks to be provided in any of the following formats, based on the value provided in <c>Type</c>:
/// </para>
/// <list type="table">
/// <listheader>
/// <term>Callback Format</term>
/// <term>Type value</term>
/// </listheader>
/// <item>
/// <term>Polling</term>
/// <term>NSP_NOTIFY_IMMEDIATELY</term>
/// </item>
/// <item>
/// <term>Window Message</term>
/// <term>NSP_NOTIFY_HWND</term>
/// </item>
/// <item>
/// <term>Event</term>
/// <term>NSP_NOTIFY_EVENT</term>
/// </item>
/// <item>
/// <term>APC</term>
/// <term>NSP_NOTIFY_APC</term>
/// </item>
/// <item>
/// <term>Completion Port</term>
/// <term>NSP_NOTIFY_PORT</term>
/// </item>
/// </list>
/// <para>For a blocking function, set the <c>WSACOMPLETION</c> structure to null.</para>
/// </remarks>
// https://learn.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-wsacompletion typedef struct _WSACOMPLETION {
// WSACOMPLETIONTYPE Type; union { struct { HWND hWnd; UINT uMsg; WPARAM context; } WindowMessage; struct { LPWSAOVERLAPPED lpOverlapped;
// } Event; struct { LPWSAOVERLAPPED lpOverlapped; LPWSAOVERLAPPED_COMPLETION_ROUTINE lpfnCompletionProc; } Apc; struct { LPWSAOVERLAPPED
// lpOverlapped; HANDLE hPort; ULONG_PTR Key; } Port; } Parameters; } WSACOMPLETION, *PWSACOMPLETION, *LPWSACOMPLETION;
[PInvokeData("winsock2.h", MSDNShortId = "NS:winsock2._WSACOMPLETION")]
[StructLayout(LayoutKind.Sequential)]
public struct WSACOMPLETION
{
/// <summary>
/// <para>Type: <c>WSACOMPLETIONTYPE</c></para>
/// <para>The type of completion notification required. See Remarks.</para>
/// </summary>
public WSACOMPLETIONTYPE Type;
/// <summary>
/// The parameters required to complete the callback. The structures within the Parameters union specify information required for
/// completing the callback of each given type. For example, the <c>WindowMessage</c> structure must be filled when <c>Type</c> is
/// set to NSP_NOTIFY_HWND.
/// </summary>
public UNION Parameters;
/// <summary>
/// The parameters required to complete the callback. The structures within the Parameters union specify information required for
/// completing the callback of each given type. For example, the <c>WindowMessage</c> structure must be filled when <c>Type</c> is
/// set to NSP_NOTIFY_HWND.
/// </summary>
[StructLayout(LayoutKind.Explicit)]
public struct UNION
{
/// <summary />
[FieldOffset(0)]
public WINDOWMESSAGE WindowMessage;
/// <summary />
[FieldOffset(0)]
public EVENT Event;
/// <summary />
[FieldOffset(0)]
public APC Apc;
/// <summary />
[FieldOffset(0)]
public PORT Port;
/// <summary />
[StructLayout(LayoutKind.Sequential)]
public struct WINDOWMESSAGE
{
/// <summary><c>Type: <c>HWND</c></c> Windows handle.</summary>
public HWND hWnd;
/// <summary><c>Type: <c>UINT</c></c> Message handle.</summary>
public uint uMsg;
/// <summary><c>Type: <c>WPARAM</c></c> Context of the message or handle.</summary>
public IntPtr context;
}
/// <summary/>
[StructLayout(LayoutKind.Sequential)]
public struct EVENT
{
/// <summary><c>Type: <c>LPWSAOVERLAPPED</c></c> A pointer to a WSAOVERLAPPED structure.</summary>
public IntPtr lpOverlapped;
}
/// <summary/>
[StructLayout(LayoutKind.Sequential)]
public struct APC
{
/// <summary><c>Type: <c>LPWSAOVERLAPPED</c></c> A pointer to a WSAOVERLAPPED structure.</summary>
public IntPtr lpOverlapped;
/// <summary>
/// <para>Type: _In_opt_ <c>LPWSAOVERLAPPED_COMPLETION_ROUTINE</c></para>
/// <para>A pointer to an application-provided completion routine.</para>
/// </summary>
[MarshalAs(UnmanagedType.FunctionPtr)]
public LPWSAOVERLAPPED_COMPLETION_ROUTINE lpfnCompletionProc;
}
/// <summary/>
[StructLayout(LayoutKind.Sequential)]
public struct PORT
{
/// <summary><c>Type: <c>LPWSAOVERLAPPED</c></c> A pointer to a WSAOVERLAPPED structure.</summary>
public IntPtr lpOverlapped;
/// <summary><c>Type: <c>HANDLE</c></c> A handle to the port.</summary>
public HANDLE hPort;
/// <summary><c>Type: <c>ULONG_PTR</c></c> A pointer to the key.</summary>
public IntPtr Key;
}
}
}
/// <summary>The <c>WSANETWORKEVENTS</c> structure is used to store a socket's internal information about network events.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-wsanetworkevents typedef struct _WSANETWORKEVENTS { long
// lNetworkEvents; int iErrorCode[FD_MAX_EVENTS]; } WSANETWORKEVENTS, *LPWSANETWORKEVENTS;
@ -484,5 +615,4 @@ namespace Vanara.PInvoke
void IDisposable.Dispose() => WSACleanup();
}
}
}

File diff suppressed because it is too large Load Diff