Updated P2P functions to be more usable

pull/164/head
dahall 2020-08-28 14:35:20 -06:00
parent d214434cda
commit 8859b714c5
7 changed files with 931 additions and 494 deletions

View File

@ -562,29 +562,7 @@ namespace Vanara.PInvoke
// registrationType, HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumApplicationRegistrationInfo")]
public static extern HRESULT PeerCollabEnumApplicationRegistrationInfo(PEER_APPLICATION_REGISTRATION_TYPE registrationType, out SafeHPEERENUM phPeerEnum);
/// <summary>The <c>PeerCollabEnumApplicationRegistrationInfo</c> function enumerates peer application information.</summary>
/// <param name="registrationType">
/// A PEER_APPLICATION_REGISTRATION_TYPE value that specifies whether the peer's application is registered to the <c>current
/// user</c> or <c>all users</c> of the peer's machine.
/// </param>
/// <returns>A list of <see cref="PEER_APPLICATION_REGISTRATION_INFO"/> structures.</returns>
/// <remarks>
/// <para>
/// An application is a set of software or software features available on the peer's endpoint. Commonly, this refers to software
/// packages that support peer networking activities, like games or other collaborative applications.
/// </para>
/// <para>
/// A peer's application has a GUID representing a single specific application. When an application is registered for a peer, this
/// GUID and the corresponding application can be made available to all trusted contacts of the peer, indicating the activities the
/// peer can participate in. To unregister a peer's application, call PeerCollabUnregisterApplication with this GUID.
/// </para>
/// <para>Peer application registration information items are returned as individual PEER_APPLICATION_REGISTRATION_INFO structures.</para>
/// </remarks>
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumApplicationRegistrationInfo")]
public static IEnumerable<PEER_APPLICATION_REGISTRATION_INFO> PeerCollabEnumApplicationRegistrationInfo(PEER_APPLICATION_REGISTRATION_TYPE registrationType) =>
PeerEnum<PEER_APPLICATION_REGISTRATION_INFO>(() => { PeerCollabEnumApplicationRegistrationInfo(registrationType, out var h).ThrowIfFailed(); return h; });
public static extern HRESULT PeerCollabEnumApplicationRegistrationInfo(PEER_APPLICATION_REGISTRATION_TYPE registrationType, out SafeHPEERENUM<PEER_APPLICATION_REGISTRATION_INFO> phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumApplications</c> function returns the handle to an enumeration that contains the applications registered to
@ -653,7 +631,7 @@ namespace Vanara.PInvoke
// PeerCollabEnumApplications( PCPEER_ENDPOINT pcEndpoint, const GUID *pApplicationId, HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumApplications")]
public static extern HRESULT PeerCollabEnumApplications(in PEER_ENDPOINT pcEndpoint, in Guid pApplicationId, out SafeHPEERENUM phPeerEnum);
public static extern HRESULT PeerCollabEnumApplications(in PEER_ENDPOINT pcEndpoint, in Guid pApplicationId, out SafeHPEERENUM<PEER_APPLICATION> phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumApplications</c> function returns the handle to an enumeration that contains the applications registered to
@ -722,60 +700,7 @@ namespace Vanara.PInvoke
// PeerCollabEnumApplications( PCPEER_ENDPOINT pcEndpoint, const GUID *pApplicationId, HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumApplications")]
public static extern HRESULT PeerCollabEnumApplications([In, Optional] IntPtr pcEndpoint, [In, Optional] IntPtr pApplicationId, out SafeHPEERENUM phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumApplications</c> function returns the handle to an enumeration that contains the applications registered to
/// a specific peer's endpoint(s).
/// </summary>
/// <param name="pcEndpoint">
/// <para>A PEER_ENDPOINT structure that contains the endpoint information for a peer whose applications will be enumerated.</para>
/// <para>If this parameter is set to <c>NULL</c>, the published application information for the local peer's endpoint is enumerated.</para>
/// </param>
/// <param name="pApplicationId">
/// A GUID value that uniquely identifies a particular application of the supplied peer. If this parameter is supplied, the only
/// peer application returned is the one that matches this GUID.
/// </param>
/// <returns>
/// A list of <see cref="PEER_APPLICATION"/> structures that contains the applications registered to a specific peer's endpoint(s).
/// </returns>
/// <remarks>
/// <para>
/// In order to enumerate the applications for the specified endpoint successfully, application data must be available on the
/// endpoint. For application data to be available, one of the following must occur:
/// </para>
/// <list type="bullet">
/// <item>
/// <term>The endpoint must have been previously obtained by calling PeerCollabEnumEndpoints.</term>
/// </item>
/// <item>
/// <term>The local peer must have subscribed to the endpoint by calling PeerCollabSubscribeEndpointData.</term>
/// </item>
/// <item>
/// <term>The endpoint data must be refreshed by calling PeerCollabRefreshEndpointData successfully.</term>
/// </item>
/// </list>
/// <para>
/// The <c>PeerCollabEnumApplications</c> function returns an empty array for endpoints on the subnet that are not trusted contacts.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peercollabenumapplications NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerCollabEnumApplications( PCPEER_ENDPOINT pcEndpoint, const GUID *pApplicationId, HPEERENUM *phPeerEnum );
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumApplications")]
public static IEnumerable<PEER_APPLICATION> PeerCollabEnumApplications([In, Optional] PEER_ENDPOINT? pcEndpoint, [In, Optional] Guid? pApplicationId) =>
PeerEnum<PEER_APPLICATION>(() =>
{
SafeHPEERENUM h;
if (pcEndpoint.HasValue && pApplicationId.HasValue)
PeerCollabEnumApplications(pcEndpoint.Value, pApplicationId.Value, out h).ThrowIfFailed();
else
{
using var e = (SafeHGlobalStruct<PEER_ENDPOINT>)pcEndpoint;
using var a = (SafeHGlobalStruct<Guid>)pApplicationId;
PeerCollabEnumApplications(e, a, out h).ThrowIfFailed();
}
return h;
});
public static extern HRESULT PeerCollabEnumApplications([In, Optional] IntPtr pcEndpoint, [In, Optional] IntPtr pApplicationId, out SafeHPEERENUM<PEER_APPLICATION> phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumContacts</c> function returns a handle to an enumerated set that contains all of the peer collaboration
@ -815,17 +740,7 @@ namespace Vanara.PInvoke
// PeerCollabEnumContacts( HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumContacts")]
public static extern HRESULT PeerCollabEnumContacts(out SafeHPEERENUM phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumContacts</c> function returns an enumerated set that contains all of the peer collaboration network
/// contacts currently available on the calling peer.
/// </summary>
/// <returns>A list of <see cref="PEER_CONTACT"/> of all currently available contacts.</returns>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peercollabenumcontacts NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerCollabEnumContacts( HPEERENUM *phPeerEnum );
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumContacts")]
public static IEnumerable<PEER_CONTACT> PeerCollabEnumContacts() => PeerEnum<PEER_CONTACT>(() => { PeerCollabEnumContacts(out var h).ThrowIfFailed(); return h; });
public static extern HRESULT PeerCollabEnumContacts(out SafeHPEERENUM<PEER_CONTACT> phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumEndpoints</c> function returns the handle to an enumeration that contains the endpoints associated with a
@ -885,32 +800,7 @@ namespace Vanara.PInvoke
// PeerCollabEnumEndpoints( PCPEER_CONTACT pcContact, HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumEndpoints")]
public static extern HRESULT PeerCollabEnumEndpoints(in PEER_CONTACT pcContact, out SafeHPEERENUM phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumEndpoints</c> function returns an enumeration that contains the endpoints associated with a specific peer contact.
/// </summary>
/// <param name="pcContact">Pointer to a PEER_CONTACT structure that contains the contact information for a specific peer.</param>
/// <returns>
/// An enumeration of <see cref="PEER_ENDPOINT"/> structures that contain the endpoints associated with a specific peer contact.
/// </returns>
/// <remarks>
/// <para>
/// It is recommended that a contact record is updated using PeerCollabUpdateContact prior to calling
/// <c>PeerCollabEnumEndpoints</c>. Failure to do so can result in a return of E_INVALIDARG.
/// </para>
/// <para>
/// Endpoints will be available only for contacts with fWatch set to <c>true</c>. Only endpoints that have the "Me" contact of the
/// calling peer saved as a trusted contact and have WatcherPermissions set to <c>allow</c> will be available. A contact must also
/// be signed-in to the internet. In the event the contact is not signed-in, the error <c>E_INVALIDARG</c> will be returned.
/// </para>
/// <para>The limit for connections to a single contact is 50.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peercollabenumendpoints NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerCollabEnumEndpoints( PCPEER_CONTACT pcContact, HPEERENUM *phPeerEnum );
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumEndpoints")]
public static IEnumerable<PEER_ENDPOINT> PeerCollabEnumEndpoints(in PEER_CONTACT pcContact) =>
PeerEnum<PEER_ENDPOINT, PEER_CONTACT>(pcContact, i => { PeerCollabEnumEndpoints(i, out var h).ThrowIfFailed(); return h; });
public static extern HRESULT PeerCollabEnumEndpoints(in PEER_CONTACT pcContact, out SafeHPEERENUM<PEER_ENDPOINT> phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumObjects</c> function returns the handle to an enumeration that contains the peer objects associated with a
@ -989,7 +879,7 @@ namespace Vanara.PInvoke
// PeerCollabEnumObjects( PCPEER_ENDPOINT pcEndpoint, const GUID *pObjectId, HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumObjects")]
public static extern HRESULT PeerCollabEnumObjects(in PEER_ENDPOINT pcEndpoint, in Guid pObjectId, out SafeHPEERENUM phPeerEnum);
public static extern HRESULT PeerCollabEnumObjects(in PEER_ENDPOINT pcEndpoint, in Guid pObjectId, out SafeHPEERENUM<PEER_OBJECT> phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumObjects</c> function returns the handle to an enumeration that contains the peer objects associated with a
@ -1068,63 +958,7 @@ namespace Vanara.PInvoke
// PeerCollabEnumObjects( PCPEER_ENDPOINT pcEndpoint, const GUID *pObjectId, HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumObjects")]
public static extern HRESULT PeerCollabEnumObjects([In, Optional] IntPtr pcEndpoint, [In, Optional] IntPtr pObjectId, out SafeHPEERENUM phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumObjects</c> function returns an enumeration that contains the peer objects associated with a specific
/// peer's endpoint.
/// </summary>
/// <param name="pcEndpoint">
/// <para>A PEER_ENDPOINT structure that contains the endpoint information for a peer whose objects will be enumerated.</para>
/// <para>If this parameter is <see langword="null"/> the published objects of the local peer's contacts are returned.</para>
/// </param>
/// <param name="pObjectId">
/// A GUID value that uniquely identifies a peer object with the supplied peer. If this parameter is supplied, the only peer object
/// returned is the one that matches this GUID.
/// </param>
/// <returns>The enumerated set of peer objects that correspond to the GUID returned in pObjectId.</returns>
/// <remarks>
/// <para>
/// Peer objects are run-time data items associated with a particular application, such as a picture, an avatar, a certificate, or a
/// specific description. Each peer object must be smaller than 16K in size.
/// </para>
/// <para>
/// <c>PeerCollabEnumObjects</c> will return all of the objects published for the local peer. The objects can be published by more
/// than one application.
/// </para>
/// <para>To obtain a peer object successfully:</para>
/// <list type="bullet">
/// <item>
/// <term>The endpoint must have been previously obtained by calling PeerCollabEnumEndpoints.</term>
/// </item>
/// <item>
/// <term>The local peer must have subscribed to the endpoint by calling PeerCollabSubscribeEndpointData.</term>
/// </item>
/// <item>
/// <term>The endpoint data must be refreshed by calling PeerCollabRefreshEndpointData successfully.</term>
/// </item>
/// </list>
/// <para>
/// If the user is publishing a picture, the picture can be obtained by retrieving the corresponding object. The GUID for the
/// picture object is PEER_COLLAB_OBJECTID_USER_PICTURE.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peercollabenumobjects NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerCollabEnumObjects( PCPEER_ENDPOINT pcEndpoint, const GUID *pObjectId, HPEERENUM *phPeerEnum );
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumObjects")]
public static IEnumerable<PEER_OBJECT> PeerCollabEnumObjects([In, Optional] PEER_ENDPOINT? pcEndpoint, [In, Optional] Guid? pObjectId) => PeerEnum<PEER_OBJECT>(() =>
{
SafeHPEERENUM h;
if (pcEndpoint.HasValue && pObjectId.HasValue)
PeerCollabEnumObjects(pcEndpoint.Value, pObjectId.Value, out h).ThrowIfFailed();
else
{
using var e = (SafeHGlobalStruct<PEER_ENDPOINT>)pcEndpoint;
using var a = (SafeHGlobalStruct<Guid>)pObjectId;
PeerCollabEnumObjects(e, a, out h).ThrowIfFailed();
}
return h;
});
public static extern HRESULT PeerCollabEnumObjects([In, Optional] IntPtr pcEndpoint, [In, Optional] IntPtr pObjectId, out SafeHPEERENUM<PEER_OBJECT> phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumPeopleNearMe</c> function returns a handle to an enumerated set that contains all of the peer collaboration
@ -1168,20 +1002,7 @@ namespace Vanara.PInvoke
// PeerCollabEnumPeopleNearMe( HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumPeopleNearMe")]
public static extern HRESULT PeerCollabEnumPeopleNearMe(out SafeHPEERENUM phPeerEnum);
/// <summary>
/// The <c>PeerCollabEnumPeopleNearMe</c> function returns an enumerated set that contains all of the peer collaboration network
/// "people near me" endpoints currently available on the subnet of the calling peer.
/// </summary>
/// <returns>
/// An enumerated set that contains all of the peer collaboration network "people near me" endpoints currently available on the
/// subnet of the calling peer.
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peercollabenumpeoplenearme NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerCollabEnumPeopleNearMe( HPEERENUM *phPeerEnum );
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabEnumPeopleNearMe")]
public static IEnumerable<PEER_PEOPLE_NEAR_ME> PeerCollabEnumPeopleNearMe() => PeerEnum<PEER_PEOPLE_NEAR_ME>(() => { PeerCollabEnumPeopleNearMe(out var h).ThrowIfFailed(); return h; });
public static extern HRESULT PeerCollabEnumPeopleNearMe(out SafeHPEERENUM<PEER_PEOPLE_NEAR_ME> phPeerEnum);
/// <summary>
/// <para>

View File

@ -1,11 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using Vanara.Extensions;
using Vanara.InteropServices;
using static Vanara.PInvoke.AdvApi32;
using static Vanara.PInvoke.Crypt32;
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
namespace Vanara.PInvoke
{
@ -398,6 +395,291 @@ namespace Vanara.PInvoke
public static extern HRESULT PeerNameToPeerHostName([MarshalAs(UnmanagedType.LPWStr)] string pwzPeerName,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PeerStringMarshaler))] out string ppwzHostName);
/// <summary>
/// The <c>PeerPnrpEndResolve</c> function closes the handle for an asynchronous PNRP resolution operation initiated with a previous
/// call to PeerPnrpStartResolve.
/// </summary>
/// <param name="hResolve">The handle to the asynchronous peer name resolution operation returned by a previous call to PeerPnrpStartResolve.</param>
/// <returns>
/// <para>If the function call succeeds, the return value is <c>S_OK</c>. Otherwise, it returns one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>One of the parameters is not valid.</term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>There is not enough memory to perform the specified operation.</term>
/// </item>
/// </list>
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerpnrpendresolve NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerPnrpEndResolve( HRESOLUTION hResolve );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerPnrpEndResolve")]
public static extern HRESULT PeerPnrpEndResolve(HRESOLUTION hResolve);
/// <summary>
/// The <c>PeerPnrpCloudInfo</c> function retrieves information on the Peer Name Resolution Protocol (PNRP) clouds in which the
/// calling peer is participating.
/// </summary>
/// <param name="pcNumClouds">The number of PNRP clouds returned in ppCloudInfo.</param>
/// <param name="ppCloudInfo">
/// <para>
/// Pointer to a list of PEER_PNRP_CLOUD_INFO structures that contain information about the PNRP clouds in which the calling peer is participating.
/// </para>
/// <para>This data returned by this parameter must be freed by calling PeerFreeData.</para>
/// </param>
/// <returns>
/// <para>If the function call succeeds, the return value is <c>S_OK</c>. Otherwise, it returns one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>One of the parameters is not valid.</term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>There is not enough memory to perform the specified operation.</term>
/// </item>
/// </list>
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerpnrpgetcloudinfo NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerPnrpGetCloudInfo( ULONG *pcNumClouds, PPEER_PNRP_CLOUD_INFO *ppCloudInfo );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerPnrpGetCloudInfo")]
public static extern HRESULT PeerPnrpGetCloudInfo(out uint pcNumClouds,
[Out, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PeerStructMarshaler<PEER_PNRP_CLOUD_INFO>))] out PEER_PNRP_CLOUD_INFO ppCloudInfo);
/// <summary>
/// The <c>PeerPnrpGetEndpoint</c> function retrieves a peer endpoint address resolved during an asynchronous peer name resolution operation.
/// </summary>
/// <param name="hResolve">The handle to the asynchronous peer name resolution operation returned by a previous call to PeerPnrpStartResolve.</param>
/// <param name="ppEndpoint">
/// <para>
/// Pointer to the address of a PEER_PNRP_ENDPOINT_INFO structure that contains an endpoint address for the peer name supplied in
/// the previous call to PeerPnrpStartResolve.
/// </para>
/// <para>This data returned by this parameter must be freed by calling PeerFreeData.</para>
/// </param>
/// <returns>
/// <para>If the function call succeeds, the return value is <c>S_OK</c>. Otherwise, it returns one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>One of the parameters is not valid.</term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>There is not enough memory to perform the specified operation.</term>
/// </item>
/// <item>
/// <term>PEER_E_NO_MORE</term>
/// <term>All endpoint addresses have been retrieved for the peer.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>PeerPnrpStartResolve creates a handle to an asynchronous peer name resolution operation.</para>
/// <para>
/// Whenever an endpoint is found, the event handle provided in hEvent is signaled, and <c>PeerPnrpGetEndpoint</c> must be called
/// with the phResolve handle by the application to obtain that endpoint.
/// </para>
/// <para>
/// The last event specifies the PEER_E_NO_MORE error code, indicating that all endpoints corresponding to the peer name supplied to
/// PeerPnrpStartResolve have been found. At this time, the application must close the handle with a call to PeerPnrpEndResolve.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerpnrpgetendpoint NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerPnrpGetEndpoint( HRESOLUTION hResolve, PPEER_PNRP_ENDPOINT_INFO *ppEndpoint );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerPnrpGetEndpoint")]
public static extern HRESULT PeerPnrpGetEndpoint(HRESOLUTION hResolve,
[Out, MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PeerStructMarshaler<PEER_PNRP_ENDPOINT_INFO>))] out PEER_PNRP_ENDPOINT_INFO ppEndpoint);
/// <summary>
/// <para>
/// The <c>PeerPnrpRegister</c> function registers a peer with a PNRP cloud and returns a handle that can be used for registration updates.
/// </para>
/// <para><c>Note</c> When called, this function will block until the PNRP service has been initiated.</para>
/// </summary>
/// <param name="pcwzPeerName">
/// Pointer to a zero-terminated Unicode string that contains the peer name to register with the PNRP service.
/// </param>
/// <param name="pRegistrationInfo">
/// Pointer to a PEER_PNRP_REGISTRATION_INFO structure that contains the endpoint information for the registering peer node. If
/// <c>NULL</c>, the API will register the peer with all known PNRP clouds, and any registered addresses are automatically selected
/// by the infrastructure.
/// </param>
/// <param name="phRegistration">
/// Handle to the PNRP registration for the calling peer node. Use this handle to update the registration or to deregister with the
/// PNRP service.
/// </param>
/// <returns>
/// <para>If the function call succeeds, the return value is <c>S_OK</c>. Otherwise, it returns one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>One of the parameters is not valid.</term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>There is not enough memory to perform the specified operation.</term>
/// </item>
/// <item>
/// <term>PEER_E_IDENTITY_NOT_FOUND</term>
/// <term>The local peer is using an identity that does not exist.</term>
/// </item>
/// </list>
/// <para>Additionally, this function can return WSA values. For a complete list of possible values, see PNRP NSP Error Codes.</para>
/// </returns>
/// <remarks>
/// <para>
/// A handle must be registered in a process separate of the process it will be resolved in. If a handle is registered and resolved
/// within the same process it will not be recognized.
/// </para>
/// <para>A name cannot be registered with an endpoint more than once. When updates to a registered name are required, use PeerPnrpUpdateRegistration.</para>
/// <para>
/// When pRegistrationInfo is <c>NULL</c>, or PEER_PNRP_AUTO_ADDRESSES is specified for cAddresses, the infrastructure will keep the
/// addresses registered up to date as addresses change or cloud availability changes.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerpnrpregister NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerPnrpRegister( PCWSTR pcwzPeerName, PPEER_PNRP_REGISTRATION_INFO pRegistrationInfo, HREGISTRATION *phRegistration );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerPnrpRegister")]
public static extern HRESULT PeerPnrpRegister([MarshalAs(UnmanagedType.LPWStr)] string pcwzPeerName, in PEER_PNRP_REGISTRATION_INFO pRegistrationInfo, out HREGISTRATION phRegistration);
/// <summary>
/// <para>
/// The <c>PeerPnrpRegister</c> function registers a peer with a PNRP cloud and returns a handle that can be used for registration updates.
/// </para>
/// <para><c>Note</c> When called, this function will block until the PNRP service has been initiated.</para>
/// </summary>
/// <param name="pcwzPeerName">
/// Pointer to a zero-terminated Unicode string that contains the peer name to register with the PNRP service.
/// </param>
/// <param name="pRegistrationInfo">
/// Pointer to a PEER_PNRP_REGISTRATION_INFO structure that contains the endpoint information for the registering peer node. If
/// <c>NULL</c>, the API will register the peer with all known PNRP clouds, and any registered addresses are automatically selected
/// by the infrastructure.
/// </param>
/// <param name="phRegistration">
/// Handle to the PNRP registration for the calling peer node. Use this handle to update the registration or to deregister with the
/// PNRP service.
/// </param>
/// <returns>
/// <para>If the function call succeeds, the return value is <c>S_OK</c>. Otherwise, it returns one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>One of the parameters is not valid.</term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>There is not enough memory to perform the specified operation.</term>
/// </item>
/// <item>
/// <term>PEER_E_IDENTITY_NOT_FOUND</term>
/// <term>The local peer is using an identity that does not exist.</term>
/// </item>
/// </list>
/// <para>Additionally, this function can return WSA values. For a complete list of possible values, see PNRP NSP Error Codes.</para>
/// </returns>
/// <remarks>
/// <para>
/// A handle must be registered in a process separate of the process it will be resolved in. If a handle is registered and resolved
/// within the same process it will not be recognized.
/// </para>
/// <para>A name cannot be registered with an endpoint more than once. When updates to a registered name are required, use PeerPnrpUpdateRegistration.</para>
/// <para>
/// When pRegistrationInfo is <c>NULL</c>, or PEER_PNRP_AUTO_ADDRESSES is specified for cAddresses, the infrastructure will keep the
/// addresses registered up to date as addresses change or cloud availability changes.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerpnrpregister NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerPnrpRegister( PCWSTR pcwzPeerName, PPEER_PNRP_REGISTRATION_INFO pRegistrationInfo, HREGISTRATION *phRegistration );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerPnrpRegister")]
public static extern HRESULT PeerPnrpRegister([MarshalAs(UnmanagedType.LPWStr)] string pcwzPeerName, [In, Optional] IntPtr pRegistrationInfo, out HREGISTRATION phRegistration);
/// <summary>The <c>PeerPnrpResolve</c> function obtains the endpoint address(es) registered for a specific peer name.</summary>
/// <param name="pcwzPeerName">
/// Pointer to a zero-terminated string that contains the peer name for which endpoint addresses will be obtained.
/// </param>
/// <param name="pcwzCloudName">
/// Pointer to a zero-terminated string that contains the name of the PNRP cloud under which to resolve the peer name. If
/// <c>NULL</c>, the resolve is performed in all clouds. If PEER_PNRP_ALL_LINK_CLOUDS, the resolve is performed in all link local
/// clouds. When "GLOBAL_", resolve will only take place in the global cloud.
/// </param>
/// <param name="pcEndpoints">
/// The maximum number of endpoints to return in ppEndpoints. Upon return, this parameter contains the actual number of endpoints in ppEndpoints.
/// </param>
/// <param name="ppEndpoints">
/// Pointer to a list of PEER_PNRP_ENDPOINT_INFO structures that contain the endpoints for which the peer name successfully
/// resolved. Each endpoint contains one or more IP addresses at which the peer node can be reached.
/// </param>
/// <returns>
/// <para>If the function call succeeds, the return value is <c>S_OK</c>. Otherwise, it returns one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>One of the parameters is not valid.</term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>There is not enough memory to perform the specified operation.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>
/// This call is synchronous and will block until completed. For aysnchronous peer name resolution, call PeerPnrpStartResolve and
/// obtain the resolved endpoint address when the supplied event is raised.
/// </para>
/// <para>
/// A handle must be resolved in a process separate of the process it was registered in. If a handle is registered and resolved
/// within the same process it will not be recognized.
/// </para>
/// <para>
/// When resolution is performed for all clouds, it is issued to each cloud simultaneously. The method will return as soon as it has
/// received enough results from any combination of clouds.
/// </para>
/// <para>
/// The default resolve timeout used internally by this method is 30 seconds. If a specific timeout is required, the asynchronous
/// PeerPnrpStartResolve function should be used.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerpnrpresolve NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerPnrpResolve( PCWSTR pcwzPeerName, PCWSTR pcwzCloudName, ULONG *pcEndpoints, PPEER_PNRP_ENDPOINT_INFO *ppEndpoints );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerPnrpResolve")]
public static extern HRESULT PeerPnrpResolve([MarshalAs(UnmanagedType.LPWStr)] string pcwzPeerName, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pcwzCloudName,
ref uint pcEndpoints, [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] PEER_PNRP_ENDPOINT_INFO[] ppEndpoints);
/// <summary>
/// The <c>PeerPnrpShutdown</c> function shuts down a running instance of the Peer Name Resolution Protocol (PNRP) service and
/// releases all resources associated with it.
@ -424,6 +706,64 @@ namespace Vanara.PInvoke
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerPnrpShutdown")]
public static extern HRESULT PeerPnrpShutdown();
/// <summary>The <c>PeerPnrpStartResolve</c> function starts an asynchronous peer name resolution operation.</summary>
/// <param name="pcwzPeerName">
/// Pointer to a zero-terminated string that contains the peer name for which endpoint addresses will be obtained.
/// </param>
/// <param name="pcwzCloudName">
/// Pointer to a zero-terminated string that contains the name of the PNRP cloud under which to resolve the peer name. If
/// <c>NULL</c>, resolution is performed for all clouds. If PEER_PNRP_ALL_LINK_CLOUDS, resolution is performed for all link local
/// clouds. When "GLOBAL_" is specified, resolution takes place in the global cloud.
/// </param>
/// <param name="cMaxEndpoints">The maximum number of endpoints to return for the peer name.</param>
/// <param name="hEvent">
/// Handle to the event signaled when a peer endpoint is resolved for the supplied peer name and are ready for consumption by
/// calling PeerPnrpGetEndpoint. This event is signaled for every endpoint discovered by the PNRP service. If PEER_NO_MORE is
/// returned by a call to PeerPnrpGetEndpoint, then all endpoints have been found for that peer.
/// </param>
/// <param name="phResolve">
/// Handle to this peer name resolution request. This handle must be provided to PeerPnrpEndResolve after the resolution events are
/// raised and the endpoints are obtained with corresponding calls to PeerPnrpGetEndpoint, or if the operation fails.
/// </param>
/// <returns>
/// <para>If the function call succeeds, the return value is <c>S_OK</c>. Otherwise, it returns one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>One of the parameters is not valid.</term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>There is not enough memory to perform the specified operation.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para><c>PeerPnrpStartResolve</c> creates a handle to an asynchronous peer name resolution operation.</para>
/// <para>
/// Whenever an endpoint is found, the event handle provided in hEvent is signaled, and PeerPnrpGetEndpoint must be called with the
/// phResolve handle by the application to obtain that endpoint.
/// </para>
/// <para>
/// The last event specifies the PEER_E_NO_MORE error code, indicating that all endpoints corresponding to the peer name supplied to
/// <c>PeerPnrpStartResolve</c> have been found. At this time, the application must close the handle with a call to PeerPnrpEndResolve.
/// </para>
/// <para>
/// A handle must be resolved in a process separate from the process in which it was registered. If a handle is registered and
/// resolved within the same process it will not be recognized.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerpnrpstartresolve NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerPnrpStartResolve( PCWSTR pcwzPeerName, PCWSTR pcwzCloudName, ULONG cMaxEndpoints, HANDLE hEvent, HRESOLUTION *phResolve );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerPnrpStartResolve")]
public static extern HRESULT PeerPnrpStartResolve([MarshalAs(UnmanagedType.LPWStr)] string pcwzPeerName, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pcwzCloudName,
[Optional] uint cMaxEndpoints, HANDLE hEvent, out HRESOLUTION phResolve);
/// <summary>The <c>PeerPnrpStartup</c> function starts the Peer Name Resolution Protocol (PNRP) service for the calling peer.</summary>
/// <param name="wVersionRequested">The version of PNRP to use for this service instance. The default value is PNRP_VERSION (2).</param>
/// <returns>
@ -461,19 +801,65 @@ namespace Vanara.PInvoke
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerPnrpStartup")]
public static extern HRESULT PeerPnrpStartup(ushort wVersionRequested = PNRP_VERSION);
private static IEnumerable<T> PeerEnum<T, TIn>(TIn p1, Func<TIn, SafeHPEERENUM> setup) where T : struct where TIn : struct =>
PeerEnum<T>(() => setup(p1));
/// <summary>The <c>PeerPnrpUnregister</c> function deregisters a peer from a PNRP cloud.</summary>
/// <param name="hRegistration">Handle to a PNRP registration for the peer node obtained by a previous call to PeerPnrpRegister.</param>
/// <returns>
/// <para>If the function call succeeds, the return value is <c>S_OK</c>. Otherwise, it returns one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>One of the parameters is not valid.</term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>There is not enough memory to perform the specified operation.</term>
/// </item>
/// </list>
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerpnrpunregister NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerPnrpUnregister( HREGISTRATION hRegistration );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerPnrpUnregister")]
public static extern HRESULT PeerPnrpUnregister(HREGISTRATION hRegistration);
private static IEnumerable<T> PeerEnum<T>(Func<SafeHPEERENUM> setup) where T : struct
{
using var hEnum = setup();
if (hEnum.IsInvalid) return new T[0];
PeerGetItemCount(hEnum, out var count).ThrowIfFailed();
if (count == 0) return new T[0];
PeerGetNextItem(hEnum, ref count, out var items).ThrowIfFailed();
using (items)
return items.DangerousGetHandle().ToArray<T>((int)count);
}
/// <summary>The <c>PeerPnrpUpdateRegistration</c> function updates the PNRP registration information for a name.</summary>
/// <param name="hRegistration">Handle to a PNRP registration for the peer node obtained by a previous call to PeerPnrpRegister.</param>
/// <param name="pRegistrationInfo">
/// Pointer to a PEER_PNRP_REGISTRATION_INFO structure that contains the endpoint information for the registering peer node.
/// </param>
/// <returns>
/// <para>If the function call succeeds, the return value is <c>S_OK</c>. Otherwise, it returns one of the following values.</para>
/// <list type="table">
/// <listheader>
/// <term>Return code</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>E_INVALIDARG</term>
/// <term>One of the parameters is not valid.</term>
/// </item>
/// <item>
/// <term>E_OUTOFMEMORY</term>
/// <term>There is not enough memory to perform the specified operation.</term>
/// </item>
/// </list>
/// </returns>
/// <remarks>
/// <para>
/// The <c>pwzCloudName</c> and <c>cAddresses</c> members of the PEER_PNRP_REGISTRATION_INFO provided in the pRegistrationInfo
/// parameter cannot be changed with PeerPnrpUpdateRegistration. Attempting to do so will return an <c>E_INVALIDARG</c> error.
/// </para>
/// <para>PeerPnrpUpdateRegistration has a maximum payload of 4k.</para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerpnrpupdateregistration NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerPnrpUpdateRegistration( HREGISTRATION hRegistration, PPEER_PNRP_REGISTRATION_INFO pRegistrationInfo );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerPnrpUpdateRegistration")]
public static extern HRESULT PeerPnrpUpdateRegistration(HREGISTRATION hRegistration, in PEER_PNRP_REGISTRATION_INFO pRegistrationInfo);
/// <summary>Provides a handle to a peer enumeration.</summary>
[StructLayout(LayoutKind.Sequential)]
@ -523,33 +909,157 @@ namespace Vanara.PInvoke
public IntPtr DangerousGetHandle() => handle;
}
/// <summary>Provides a <see cref="SafeHandle"/> for <see cref="HPEERENUM"/> that is disposed using <see cref="PeerEndEnumeration"/>.</summary>
public class SafeHPEERENUM : SafeHANDLE
/// <summary>Provides a handle to the PNRP registration for the calling peer node.</summary>
[StructLayout(LayoutKind.Sequential)]
public struct HREGISTRATION : IHandle
{
/// <summary>Initializes a new instance of the <see cref="SafeHPEERENUM"/> class and assigns an existing handle.</summary>
private IntPtr handle;
/// <summary>Initializes a new instance of the <see cref="HREGISTRATION"/> struct.</summary>
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
public HREGISTRATION(IntPtr preexistingHandle) => handle = preexistingHandle;
/// <summary>Returns an invalid handle by instantiating a <see cref="HREGISTRATION"/> object with <see cref="IntPtr.Zero"/>.</summary>
public static HREGISTRATION NULL => new HREGISTRATION(IntPtr.Zero);
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
public bool IsNull => handle == IntPtr.Zero;
/// <summary>Performs an explicit conversion from <see cref="HREGISTRATION"/> to <see cref="IntPtr"/>.</summary>
/// <param name="h">The handle.</param>
/// <returns>The result of the conversion.</returns>
public static explicit operator IntPtr(HREGISTRATION h) => h.handle;
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HREGISTRATION"/>.</summary>
/// <param name="h">The pointer to a handle.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator HREGISTRATION(IntPtr h) => new HREGISTRATION(h);
/// <summary>Implements the operator !=.</summary>
/// <param name="h1">The first handle.</param>
/// <param name="h2">The second handle.</param>
/// <returns>The result of the operator.</returns>
public static bool operator !=(HREGISTRATION h1, HREGISTRATION h2) => !(h1 == h2);
/// <summary>Implements the operator ==.</summary>
/// <param name="h1">The first handle.</param>
/// <param name="h2">The second handle.</param>
/// <returns>The result of the operator.</returns>
public static bool operator ==(HREGISTRATION h1, HREGISTRATION h2) => h1.Equals(h2);
/// <inheritdoc/>
public override bool Equals(object obj) => obj is HREGISTRATION h && handle == h.handle;
/// <inheritdoc/>
public override int GetHashCode() => handle.GetHashCode();
/// <inheritdoc/>
public IntPtr DangerousGetHandle() => handle;
}
/// <summary>Provides a handle to an asynchronous peer name resolution operation.</summary>
[StructLayout(LayoutKind.Sequential)]
public struct HRESOLUTION : IHandle
{
private IntPtr handle;
/// <summary>Initializes a new instance of the <see cref="HRESOLUTION"/> struct.</summary>
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
public HRESOLUTION(IntPtr preexistingHandle) => handle = preexistingHandle;
/// <summary>Returns an invalid handle by instantiating a <see cref="HRESOLUTION"/> object with <see cref="IntPtr.Zero"/>.</summary>
public static HRESOLUTION NULL => new HRESOLUTION(IntPtr.Zero);
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
public bool IsNull => handle == IntPtr.Zero;
/// <summary>Performs an explicit conversion from <see cref="HRESOLUTION"/> to <see cref="IntPtr"/>.</summary>
/// <param name="h">The handle.</param>
/// <returns>The result of the conversion.</returns>
public static explicit operator IntPtr(HRESOLUTION h) => h.handle;
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HRESOLUTION"/>.</summary>
/// <param name="h">The pointer to a handle.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator HRESOLUTION(IntPtr h) => new HRESOLUTION(h);
/// <summary>Implements the operator !=.</summary>
/// <param name="h1">The first handle.</param>
/// <param name="h2">The second handle.</param>
/// <returns>The result of the operator.</returns>
public static bool operator !=(HRESOLUTION h1, HRESOLUTION h2) => !(h1 == h2);
/// <summary>Implements the operator ==.</summary>
/// <param name="h1">The first handle.</param>
/// <param name="h2">The second handle.</param>
/// <returns>The result of the operator.</returns>
public static bool operator ==(HRESOLUTION h1, HRESOLUTION h2) => h1.Equals(h2);
/// <inheritdoc/>
public override bool Equals(object obj) => obj is HRESOLUTION h && handle == h.handle;
/// <inheritdoc/>
public override int GetHashCode() => handle.GetHashCode();
/// <inheritdoc/>
public IntPtr DangerousGetHandle() => handle;
}
/// <summary>Provides a <see cref="SafeHandle"/> for <see cref="HPEERENUM"/> that is disposed using <see cref="PeerEndEnumeration"/>.</summary>
/// <typeparam name="T">The type of the structure that can be enumerated.</typeparam>
/// <seealso cref="Vanara.PInvoke.SafeHANDLE"/>
/// <seealso cref="System.Collections.Generic.IEnumerable{T}"/>
public class SafeHPEERENUM<T> : SafeHANDLE, IEnumerable<T> where T : struct
{
private uint count;
private SafePeerData data;
/// <summary>Initializes a new instance of the <see cref="SafeHPEERENUM{T}"/> class and assigns an existing handle.</summary>
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
/// <param name="ownsHandle">
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
/// </param>
public SafeHPEERENUM(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
/// <summary>Initializes a new instance of the <see cref="SafeHPEERENUM"/> class.</summary>
/// <summary>Initializes a new instance of the <see cref="SafeHPEERENUM{T}"/> class.</summary>
private SafeHPEERENUM() : base() { }
/// <summary>Performs an implicit conversion from <see cref="SafeHPEERENUM"/> to <see cref="HPEERENUM"/>.</summary>
/// <summary>Performs an implicit conversion from <see cref="SafeHPEERENUM{T}"/> to <see cref="HPEERENUM"/>.</summary>
/// <param name="h">The safe handle instance.</param>
/// <returns>The result of the conversion.</returns>
public static implicit operator HPEERENUM(SafeHPEERENUM h) => h.handle;
public static implicit operator HPEERENUM(SafeHPEERENUM<T> h) => h.handle;
IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable<T>)this).GetEnumerator();
IEnumerator<T> IEnumerable<T>.GetEnumerator() => ((IEnumerable<T>)GetData().DangerousGetHandle().ToArray<T>((int)count)).GetEnumerator();
/// <inheritdoc/>
protected override bool InternalReleaseHandle() => PeerEndEnumeration(handle).Succeeded;
protected override bool InternalReleaseHandle()
{
data?.Dispose();
return PeerEndEnumeration(handle).Succeeded;
}
private SafePeerData GetData()
{
if (IsInvalid) throw new InvalidOperationException("The enumeration has ended.");
if (data is null)
{
PeerGetItemCount(handle, out count).ThrowIfFailed();
if (count > 0)
PeerGetNextItem(handle, ref count, out data).ThrowIfFailed();
else
data = new SafePeerData();
}
return data;
}
}
/// <summary>Provides a <see cref="SafeHandle"/> for data that is disposed using <see cref="PeerFreeData"/>.</summary>
public class SafePeerData : SafeHANDLE
{
/// <summary>Initializes a new instance of the <see cref="SafePeerData"/> class.</summary>
protected SafePeerData() : base() { }
protected internal SafePeerData() : base() { }
/// <inheritdoc/>
protected override bool InternalReleaseHandle() { PeerFreeData(handle); return true; }
@ -618,14 +1128,6 @@ namespace Vanara.PInvoke
}
/*
PeerPnrpEndResolve
PeerPnrpGetCloudInfo
PeerPnrpGetEndpoint
PeerPnrpRegister
PeerPnrpResolve
PeerPnrpStartResolve
PeerPnrpUnregister
PeerPnrpUpdateRegistration
PeerGraphAddRecord
PeerGraphClose
PeerGraphCloseDirectConnection

View File

@ -840,25 +840,7 @@ namespace Vanara.PInvoke
// PeerGroupEnumConnections( HGROUP hGroup, DWORD dwFlags, HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerGroupEnumConnections")]
public static extern HRESULT PeerGroupEnumConnections(HGROUP hGroup, PEER_CONNECTION_FLAGS dwFlags, out SafeHPEERENUM phPeerEnum);
/// <summary>The <c>PeerGroupEnumConnections</c> function creates an enumeration of connections currently active on the peer.</summary>
/// <param name="hGroup">
/// Handle to the group that contains the connections to be enumerated. This handle is returned by the PeerGroupCreate,
/// PeerGroupOpen, or PeerGroupJoin function. This parameter is required.
/// </param>
/// <param name="dwFlags">
/// Specifies the flags that indicate the type of connection to enumerate. Valid values are specified by PEER_CONNECTION_FLAGS.
/// </param>
/// <returns>
/// The enumeration that contains the returned list of active connections, with each item represented as a pointer to a
/// PEER_CONNECTION_INFO structure.
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peergroupenumconnections NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerGroupEnumConnections( HGROUP hGroup, DWORD dwFlags, HPEERENUM *phPeerEnum );
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerGroupEnumConnections")]
public static IEnumerable<PEER_CONNECTION_INFO> PeerGroupEnumConnections(HGROUP hGroup, PEER_CONNECTION_FLAGS dwFlags) =>
PeerEnum<PEER_CONNECTION_INFO>(() => { PeerGroupEnumConnections(hGroup, dwFlags, out var h).ThrowIfFailed(); return h; });
public static extern HRESULT PeerGroupEnumConnections(HGROUP hGroup, PEER_CONNECTION_FLAGS dwFlags, out SafeHPEERENUM<PEER_CONNECTION_INFO> phPeerEnum);
/// <summary>
/// The <c>PeerGroupEnumMembers</c> function creates an enumeration of available peer group members and the associated membership information.
@ -932,54 +914,7 @@ namespace Vanara.PInvoke
// PeerGroupEnumMembers( HGROUP hGroup, DWORD dwFlags, PCWSTR pwzIdentity, HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerGroupEnumMembers")]
public static extern HRESULT PeerGroupEnumMembers(HGROUP hGroup, PEER_MEMBER_FLAGS dwFlags, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity, out SafeHPEERENUM phPeerEnum);
/// <summary>
/// The <c>PeerGroupEnumMembers</c> function creates an enumeration of available peer group members and the associated membership information.
/// </summary>
/// <param name="hGroup">
/// Handle to the peer group whose members are enumerated. This handle is returned by the PeerGroupCreate, PeerGroupOpen, or
/// PeerGroupJoin function. This parameter is required.
/// </param>
/// <param name="dwFlags">
/// <para>
/// Specifies the PEER_MEMBER_FLAGS flags that indicate which types of members to include in the enumeration. If this value is set
/// to zero, all members of the peer group are included.
/// </para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Meaning</term>
/// </listheader>
/// <item>
/// <term>PEER_MEMBER_PRESENT</term>
/// <term>Enumerate all members of the current peer group that are online.</term>
/// </item>
/// </list>
/// </param>
/// <param name="pwzIdentity">
/// String that contains the identity of a specific peer whose information is retrieved and returned in a one-item enumeration. If
/// this parameter is <see langword="null"/>, all members of the current peer group are retrieved.
/// </param>
/// <returns>
/// The enumeration that contains the returned list of peer group members, with each item represented as a pointer to a PEER_MEMBER structure.
/// </returns>
/// <remarks>
/// <para>
/// The local node is always the very first item in the enumeration if pwzIdentity is <see langword="null"/>, and dwFlags is set to
/// indicate that the local node is a member of the explicit subset.
/// </para>
/// <para>
/// By default, every member publishes membership information to the peer group. If PEER_MEMBER_DATA_OPTIONAL is set on the
/// PEER_MEMBER data for that peer, this information is only available when a peer performs an action within the group, for example,
/// publishing a record, updating presence, or issuing a GMC.
/// </para>
/// </remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peergroupenummembers NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerGroupEnumMembers( HGROUP hGroup, DWORD dwFlags, PCWSTR pwzIdentity, HPEERENUM *phPeerEnum );
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerGroupEnumMembers")]
public static IEnumerable<PEER_MEMBER> PeerGroupEnumMembers(HGROUP hGroup, PEER_MEMBER_FLAGS dwFlags, [Optional] string pwzIdentity) =>
PeerEnum<PEER_MEMBER>(() => { PeerGroupEnumMembers(hGroup, dwFlags, pwzIdentity, out var h).ThrowIfFailed(); return h; });
public static extern HRESULT PeerGroupEnumMembers(HGROUP hGroup, PEER_MEMBER_FLAGS dwFlags, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity, out SafeHPEERENUM<PEER_MEMBER> phPeerEnum);
/// <summary>The <c>PeerGroupEnumRecords</c> function creates an enumeration of peer group records.</summary>
/// <param name="hGroup">
@ -1024,25 +959,7 @@ namespace Vanara.PInvoke
// PeerGroupEnumRecords( HGROUP hGroup, const GUID *pRecordType, HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerGroupEnumRecords")]
public static extern HRESULT PeerGroupEnumRecords(HGROUP hGroup, in Guid pRecordType, out SafeHPEERENUM phPeerEnum);
/// <summary>The <c>PeerGroupEnumRecords</c> function creates an enumeration of peer group records.</summary>
/// <param name="hGroup">
/// Handle to the peer group whose records are enumerated. This handle is returned by the PeerGroupCreate, PeerGroupOpen, or
/// PeerGroupJoin function. This parameter is required.
/// </param>
/// <param name="pRecordType">
/// Pointer to a <c>GUID</c> value that uniquely identifies a specific record type. If this parameter is <c>NULL</c>, all records
/// are returned.
/// </param>
/// <returns>
/// The enumeration that contains the returned list of records, with each item represented as a pointer to a PEER_RECORD structure.
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peergroupenumrecords NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerGroupEnumRecords( HGROUP hGroup, const GUID *pRecordType, HPEERENUM *phPeerEnum );
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerGroupEnumRecords")]
public static IEnumerable<PEER_RECORD> PeerGroupEnumRecords(HGROUP hGroup, in Guid pRecordType) =>
PeerEnum<PEER_RECORD, Guid>(pRecordType, g => { PeerGroupEnumRecords(hGroup, g, out var h).ThrowIfFailed(); return h; });
public static extern HRESULT PeerGroupEnumRecords(HGROUP hGroup, in Guid pRecordType, out SafeHPEERENUM<PEER_RECORD> phPeerEnum);
/// <summary>
/// The <c>PeerGroupExportConfig</c> function exports the group configuration for a peer as an XML string that contains the
@ -2147,27 +2064,7 @@ namespace Vanara.PInvoke
// PeerGroupSearchRecords( HGROUP hGroup, PCWSTR pwzCriteria, HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerGroupSearchRecords")]
public static extern HRESULT PeerGroupSearchRecords(HGROUP hGroup, [MarshalAs(UnmanagedType.LPWStr)] string pwzCriteria, out SafeHPEERENUM phPeerEnum);
/// <summary>
/// The <c>PeerGroupSearchRecords</c> function searches the local peer group database for records that match the supplied criteria.
/// </summary>
/// <param name="hGroup">
/// Handle to the peer group whose local database is searched. This handle is returned by the PeerGroupCreate, PeerGroupOpen, or
/// PeerGroupJoin function. This parameter is required.
/// </param>
/// <param name="pwzCriteria">
/// Pointer to an XML string that contains the record search query. For information about formulating an XML query string to search
/// the peer group records database, see the Record Search Query Format documentation. This parameter is required.
/// </param>
/// <returns>
/// The enumeration that contains the returned list of records, with each item represented as a pointer to a PEER_RECORD structure.
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peergroupsearchrecords NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerGroupSearchRecords( HGROUP hGroup, PCWSTR pwzCriteria, HPEERENUM *phPeerEnum );
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerGroupSearchRecords")]
public static IEnumerable<PEER_RECORD> PeerGroupSearchRecords(HGROUP hGroup, string pwzCriteria) =>
PeerEnum<PEER_RECORD>(() => { PeerGroupSearchRecords(hGroup, pwzCriteria, out var h).ThrowIfFailed(); return h; });
public static extern HRESULT PeerGroupSearchRecords(HGROUP hGroup, [MarshalAs(UnmanagedType.LPWStr)] string pwzCriteria, out SafeHPEERENUM<PEER_RECORD> phPeerEnum);
/// <summary>The <c>PeerGroupSendData</c> function sends data to a member over a neighbor or direct connection.</summary>
/// <param name="hGroup">

View File

@ -101,19 +101,7 @@ namespace Vanara.PInvoke
// PCWSTR pwzIdentity, HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerEnumGroups")]
public static extern HRESULT PeerEnumGroups([MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity, out SafeHPEERENUM phPeerEnum);
/// <summary>The <c>PeerEnumGroups</c> function enumerates all the peer groups associated with a specific peer identity.</summary>
/// <param name="pwzIdentity">Specifies the peer identity to enumerate groups for.</param>
/// <returns>
/// The peer enumeration that contains the list of peer groups that the specified identity is a member of, with each item
/// represented as a pointer to a PEER_NAME_PAIR structure.
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerenumgroups NOT_BUILD_WINDOWS_DEPRECATE HRESULT PeerEnumGroups(
// PCWSTR pwzIdentity, HPEERENUM *phPeerEnum );
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerEnumGroups")]
public static IEnumerable<PEER_NAME_PAIR> PeerEnumGroups([MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity) =>
PeerEnum<PEER_NAME_PAIR>(() => { PeerEnumGroups(pwzIdentity, out var h).ThrowIfFailed(); return h; });
public static extern HRESULT PeerEnumGroups([MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity, out SafeHPEERENUM<PEER_NAME_PAIR> phPeerEnum);
/// <summary>
/// The <c>PeerEnumIdentities</c> function creates and returns a peer enumeration handle used to enumerate all the peer identities
@ -152,18 +140,7 @@ namespace Vanara.PInvoke
// PeerEnumIdentities( HPEERENUM *phPeerEnum );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerEnumIdentities")]
public static extern HRESULT PeerEnumIdentities(out SafeHPEERENUM phPeerEnum);
/// <summary>The <c>PeerEnumIdentities</c> function enumerates all the peer identities that belong to a specific user.</summary>
/// <returns>
/// The peer enumeration that contains the list of peer identities, with each item represented as a pointer to a PEER_NAME_PAIR
/// structure. ///
/// </returns>
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerenumidentities NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerEnumIdentities( HPEERENUM *phPeerEnum );
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerEnumIdentities")]
public static IEnumerable<PEER_NAME_PAIR> PeerEnumIdentities() =>
PeerEnum<PEER_NAME_PAIR>(() => { PeerEnumIdentities(out var h).ThrowIfFailed(); return h; });
public static extern HRESULT PeerEnumIdentities(out SafeHPEERENUM<PEER_NAME_PAIR> phPeerEnum);
/// <summary>
/// The <c>PeerIdentityCreate</c> function creates a new peer identity and returns its name. The name of the peer identity must be

View File

@ -554,149 +554,6 @@ namespace Vanara.PInvoke
PEER_WATCH_ALLOWED,
}
/// <summary>The <c>PNRP_CLOUD_FLAGS</c> enumeration specifies the validity of a cloud name.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/pnrpdef/ne-pnrpdef-pnrp_cloud_flags typedef enum _PNRP_CLOUD_FLAGS {
// PNRP_CLOUD_NO_FLAGS, PNRP_CLOUD_NAME_LOCAL, PNRP_CLOUD_RESOLVE_ONLY, PNRP_CLOUD_FULL_PARTICIPANT } PNRP_CLOUD_FLAGS;
[PInvokeData("pnrpdef.h", MSDNShortId = "NE:pnrpdef._PNRP_CLOUD_FLAGS")]
[Flags]
public enum PNRP_CLOUD_FLAGS
{
/// <summary>The cloud name is valid on the network.</summary>
PNRP_CLOUD_NO_FLAGS = 0x0,
/// <summary>The cloud name is not valid on other computers.</summary>
PNRP_CLOUD_NAME_LOCAL = 0x1,
/// <summary>The cloud is configured to be resolve only. Names cannot be published to the cloud from this computer.</summary>
PNRP_CLOUD_RESOLVE_ONLY = 0x2,
/// <summary>This machine is a full participant in the cloud, and can publish and resolve names.</summary>
PNRP_CLOUD_FULL_PARTICIPANT = 0x4,
}
/// <summary>The <c>PNRP_CLOUD_STATE</c> enumeration specifies the different states a PNRP cloud can be in.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/pnrpdef/ne-pnrpdef-pnrp_cloud_state typedef enum _PNRP_CLOUD_STATE {
// PNRP_CLOUD_STATE_VIRTUAL, PNRP_CLOUD_STATE_SYNCHRONISING, PNRP_CLOUD_STATE_ACTIVE, PNRP_CLOUD_STATE_DEAD,
// PNRP_CLOUD_STATE_DISABLED, PNRP_CLOUD_STATE_NO_NET, PNRP_CLOUD_STATE_ALONE } PNRP_CLOUD_STATE;
[PInvokeData("pnrpdef.h", MSDNShortId = "NE:pnrpdef._PNRP_CLOUD_STATE")]
public enum PNRP_CLOUD_STATE
{
/// <summary>The cloud is not yet initialized.</summary>
PNRP_CLOUD_STATE_VIRTUAL = 0,
/// <summary>The cloud is in the process of being initialized.</summary>
PNRP_CLOUD_STATE_SYNCHRONISING,
/// <summary>The cloud is active.</summary>
PNRP_CLOUD_STATE_ACTIVE,
/// <summary>The cloud is initialized, but has lost its connection to the network.</summary>
PNRP_CLOUD_STATE_DEAD,
/// <summary>The cloud is disabled in the registry.</summary>
PNRP_CLOUD_STATE_DISABLED,
/// <summary>
/// The cloud was active, but has lost access to the network. In this state the cloud can still be used for registration but it
/// is not capable of resolving addresses.
/// </summary>
PNRP_CLOUD_STATE_NO_NET,
/// <summary>
/// The local node bootstrapped, but found no other nodes in the cloud. This can also be the result of a network issue, like a
/// firewall, preventing the local node from locating other nodes within the cloud. It is also important to note that a cloud in
/// the PNRP_CLOUD_STATE_ALONE state may not have registered IP addresses.
/// </summary>
PNRP_CLOUD_STATE_ALONE,
}
/// <summary/>
[PInvokeData("pnrpdef.h")]
public enum PNRP_EXTENDED_PAYLOAD_TYPE
{
/// <summary/>
PNRP_EXTENDED_PAYLOAD_TYPE_NONE = 0,
/// <summary/>
PNRP_EXTENDED_PAYLOAD_TYPE_BINARY,
/// <summary/>
PNRP_EXTENDED_PAYLOAD_TYPE_STRING,
}
/// <summary>Registered name state.</summary>
[PInvokeData("pnrpdef.h")]
public enum PNRP_REGISTERED_ID_STATE
{
/// <summary>Id is active in cloud</summary>
PNRP_REGISTERED_ID_STATE_OK = 1,
/// <summary>Id is no longer registered in cloud</summary>
PNRP_REGISTERED_ID_STATE_PROBLEM = 2
}
/// <summary>The <c>PNRP_RESOLVE_CRITERIA</c> enumeration specifies the criteria that PNRP uses to resolve searches.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/pnrpdef/ne-pnrpdef-pnrp_resolve_criteria typedef enum _PNRP_RESOLVE_CRITERIA {
// PNRP_RESOLVE_CRITERIA_DEFAULT, PNRP_RESOLVE_CRITERIA_REMOTE_PEER_NAME, PNRP_RESOLVE_CRITERIA_NEAREST_REMOTE_PEER_NAME,
// PNRP_RESOLVE_CRITERIA_NON_CURRENT_PROCESS_PEER_NAME, PNRP_RESOLVE_CRITERIA_NEAREST_NON_CURRENT_PROCESS_PEER_NAME,
// PNRP_RESOLVE_CRITERIA_ANY_PEER_NAME, PNRP_RESOLVE_CRITERIA_NEAREST_PEER_NAME } PNRP_RESOLVE_CRITERIA;
[PInvokeData("pnrpdef.h", MSDNShortId = "NE:pnrpdef._PNRP_RESOLVE_CRITERIA")]
public enum PNRP_RESOLVE_CRITERIA
{
/// <summary>
/// Use the PNRP_RESOLVE_CRITERIA_NON_CURRENT_PROCESS_PEER_NAME criteria. This is also the default behavior if PNRPINFO is not specified.
/// </summary>
PNRP_RESOLVE_CRITERIA_DEFAULT = 0,
/// <summary>Match a peer name. The resolve request excludes any peer name registered locally on this computer.</summary>
PNRP_RESOLVE_CRITERIA_REMOTE_PEER_NAME,
/// <summary>
/// Match a peer name by finding the name with a service location closest to the supplied hint, or if no hint is supplied,
/// closest to the local IP address. The resolve request excludes any peer name registered locally on this computer.
/// </summary>
PNRP_RESOLVE_CRITERIA_NEAREST_REMOTE_PEER_NAME,
/// <summary>
/// Match a peer name. The matching peer name can be registered locally or remotely, but the resolve request excludes any peer
/// name registered by the process making the resolve request.
/// </summary>
PNRP_RESOLVE_CRITERIA_NON_CURRENT_PROCESS_PEER_NAME,
/// <summary>
/// Match a peer name by finding the name with a service location closest to the supplied hint, or if no hint is supplied,
/// closest to the local IP address. The matching peer name can be registered locally or remotely, but the resolve request
/// excludes any peer name registered by the process making the resolve request.
/// </summary>
PNRP_RESOLVE_CRITERIA_NEAREST_NON_CURRENT_PROCESS_PEER_NAME,
/// <summary>Match a peer name. The matching peer name can be registered locally or remotely.</summary>
PNRP_RESOLVE_CRITERIA_ANY_PEER_NAME,
/// <summary>
/// Match a peer name by finding the name with a service location closest to the supplied hint, or if no hint is supplied,
/// closest to the local IP address. The matching peer name can be registered locally or remotely.
/// </summary>
PNRP_RESOLVE_CRITERIA_NEAREST_PEER_NAME,
}
/// <summary>Specifies the scope under which the peer group was registered.</summary>
[PInvokeData("pnrpdef.h")]
public enum PNRP_SCOPE
{
/// <summary>Any scope.</summary>
PNRP_SCOPE_ANY = 0, // Any
/// <summary>Global scope, including the Internet.</summary>
PNRP_GLOBAL_SCOPE = 1, // global
/// <summary>Local scope.</summary>
PNRP_SITE_LOCAL_SCOPE = 2, // site local
/// <summary>Link-local scope.</summary>
PNRP_LINK_LOCAL_SCOPE = 3 // link local
}
/// <summary>Provides a handle to a Peer Graph.</summary>
[StructLayout(LayoutKind.Sequential)]
public struct HGRAPH : IHandle

208
PInvoke/P2P/Pnrpdef.cs Normal file
View File

@ -0,0 +1,208 @@
using System;
using System.Runtime.InteropServices;
namespace Vanara.PInvoke
{
/// <summary>Items from the P2P.dll</summary>
public static partial class P2P
{
/// <summary/>
public const int PNRP_MAX_ENDPOINT_ADDRESSES = 10;
/// <summary/>
public const int PNRP_MAX_EXTENDED_PAYLOAD_BYTES = 0x1000;
/// <summary/>
public const string WSZ_SCOPE_GLOBAL = "GLOBAL";
/// <summary/>
public const string WSZ_SCOPE_LINKLOCAL = "LINKLOCAL";
/// <summary/>
public const string WSZ_SCOPE_SITELOCAL = "SITELOCAL";
/// <summary>The <c>PNRP_CLOUD_FLAGS</c> enumeration specifies the validity of a cloud name.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/pnrpdef/ne-pnrpdef-pnrp_cloud_flags typedef enum _PNRP_CLOUD_FLAGS {
// PNRP_CLOUD_NO_FLAGS, PNRP_CLOUD_NAME_LOCAL, PNRP_CLOUD_RESOLVE_ONLY, PNRP_CLOUD_FULL_PARTICIPANT } PNRP_CLOUD_FLAGS;
[PInvokeData("pnrpdef.h", MSDNShortId = "NE:pnrpdef._PNRP_CLOUD_FLAGS")]
[Flags]
public enum PNRP_CLOUD_FLAGS
{
/// <summary>The cloud name is valid on the network.</summary>
PNRP_CLOUD_NO_FLAGS = 0x0,
/// <summary>The cloud name is not valid on other computers.</summary>
PNRP_CLOUD_NAME_LOCAL = 0x1,
/// <summary>The cloud is configured to be resolve only. Names cannot be published to the cloud from this computer.</summary>
PNRP_CLOUD_RESOLVE_ONLY = 0x2,
/// <summary>This machine is a full participant in the cloud, and can publish and resolve names.</summary>
PNRP_CLOUD_FULL_PARTICIPANT = 0x4,
}
/// <summary>The <c>PNRP_CLOUD_STATE</c> enumeration specifies the different states a PNRP cloud can be in.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/pnrpdef/ne-pnrpdef-pnrp_cloud_state typedef enum _PNRP_CLOUD_STATE {
// PNRP_CLOUD_STATE_VIRTUAL, PNRP_CLOUD_STATE_SYNCHRONISING, PNRP_CLOUD_STATE_ACTIVE, PNRP_CLOUD_STATE_DEAD,
// PNRP_CLOUD_STATE_DISABLED, PNRP_CLOUD_STATE_NO_NET, PNRP_CLOUD_STATE_ALONE } PNRP_CLOUD_STATE;
[PInvokeData("pnrpdef.h", MSDNShortId = "NE:pnrpdef._PNRP_CLOUD_STATE")]
public enum PNRP_CLOUD_STATE
{
/// <summary>The cloud is not yet initialized.</summary>
PNRP_CLOUD_STATE_VIRTUAL = 0,
/// <summary>The cloud is in the process of being initialized.</summary>
PNRP_CLOUD_STATE_SYNCHRONISING,
/// <summary>The cloud is active.</summary>
PNRP_CLOUD_STATE_ACTIVE,
/// <summary>The cloud is initialized, but has lost its connection to the network.</summary>
PNRP_CLOUD_STATE_DEAD,
/// <summary>The cloud is disabled in the registry.</summary>
PNRP_CLOUD_STATE_DISABLED,
/// <summary>
/// The cloud was active, but has lost access to the network. In this state the cloud can still be used for registration but it
/// is not capable of resolving addresses.
/// </summary>
PNRP_CLOUD_STATE_NO_NET,
/// <summary>
/// The local node bootstrapped, but found no other nodes in the cloud. This can also be the result of a network issue, like a
/// firewall, preventing the local node from locating other nodes within the cloud. It is also important to note that a cloud in
/// the PNRP_CLOUD_STATE_ALONE state may not have registered IP addresses.
/// </summary>
PNRP_CLOUD_STATE_ALONE,
}
/// <summary/>
[PInvokeData("pnrpdef.h")]
public enum PNRP_EXTENDED_PAYLOAD_TYPE
{
/// <summary/>
PNRP_EXTENDED_PAYLOAD_TYPE_NONE = 0,
/// <summary/>
PNRP_EXTENDED_PAYLOAD_TYPE_BINARY,
/// <summary/>
PNRP_EXTENDED_PAYLOAD_TYPE_STRING,
}
/// <summary>Registered name state.</summary>
[PInvokeData("pnrpdef.h")]
public enum PNRP_REGISTERED_ID_STATE
{
/// <summary>Id is active in cloud</summary>
PNRP_REGISTERED_ID_STATE_OK = 1,
/// <summary>Id is no longer registered in cloud</summary>
PNRP_REGISTERED_ID_STATE_PROBLEM = 2
}
/// <summary>The <c>PNRP_RESOLVE_CRITERIA</c> enumeration specifies the criteria that PNRP uses to resolve searches.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/pnrpdef/ne-pnrpdef-pnrp_resolve_criteria typedef enum _PNRP_RESOLVE_CRITERIA {
// PNRP_RESOLVE_CRITERIA_DEFAULT, PNRP_RESOLVE_CRITERIA_REMOTE_PEER_NAME, PNRP_RESOLVE_CRITERIA_NEAREST_REMOTE_PEER_NAME,
// PNRP_RESOLVE_CRITERIA_NON_CURRENT_PROCESS_PEER_NAME, PNRP_RESOLVE_CRITERIA_NEAREST_NON_CURRENT_PROCESS_PEER_NAME,
// PNRP_RESOLVE_CRITERIA_ANY_PEER_NAME, PNRP_RESOLVE_CRITERIA_NEAREST_PEER_NAME } PNRP_RESOLVE_CRITERIA;
[PInvokeData("pnrpdef.h", MSDNShortId = "NE:pnrpdef._PNRP_RESOLVE_CRITERIA")]
public enum PNRP_RESOLVE_CRITERIA
{
/// <summary>
/// Use the PNRP_RESOLVE_CRITERIA_NON_CURRENT_PROCESS_PEER_NAME criteria. This is also the default behavior if PNRPINFO is not specified.
/// </summary>
PNRP_RESOLVE_CRITERIA_DEFAULT = 0,
/// <summary>Match a peer name. The resolve request excludes any peer name registered locally on this computer.</summary>
PNRP_RESOLVE_CRITERIA_REMOTE_PEER_NAME,
/// <summary>
/// Match a peer name by finding the name with a service location closest to the supplied hint, or if no hint is supplied,
/// closest to the local IP address. The resolve request excludes any peer name registered locally on this computer.
/// </summary>
PNRP_RESOLVE_CRITERIA_NEAREST_REMOTE_PEER_NAME,
/// <summary>
/// Match a peer name. The matching peer name can be registered locally or remotely, but the resolve request excludes any peer
/// name registered by the process making the resolve request.
/// </summary>
PNRP_RESOLVE_CRITERIA_NON_CURRENT_PROCESS_PEER_NAME,
/// <summary>
/// Match a peer name by finding the name with a service location closest to the supplied hint, or if no hint is supplied,
/// closest to the local IP address. The matching peer name can be registered locally or remotely, but the resolve request
/// excludes any peer name registered by the process making the resolve request.
/// </summary>
PNRP_RESOLVE_CRITERIA_NEAREST_NON_CURRENT_PROCESS_PEER_NAME,
/// <summary>Match a peer name. The matching peer name can be registered locally or remotely.</summary>
PNRP_RESOLVE_CRITERIA_ANY_PEER_NAME,
/// <summary>
/// Match a peer name by finding the name with a service location closest to the supplied hint, or if no hint is supplied,
/// closest to the local IP address. The matching peer name can be registered locally or remotely.
/// </summary>
PNRP_RESOLVE_CRITERIA_NEAREST_PEER_NAME,
}
/// <summary>Specifies the scope under which the peer group was registered.</summary>
[PInvokeData("pnrpdef.h")]
public enum PNRP_SCOPE
{
/// <summary>Any scope.</summary>
PNRP_SCOPE_ANY = 0, // Any
/// <summary>Global scope, including the Internet.</summary>
PNRP_GLOBAL_SCOPE = 1, // global
/// <summary>Local scope.</summary>
PNRP_SITE_LOCAL_SCOPE = 2, // site local
/// <summary>Link-local scope.</summary>
PNRP_LINK_LOCAL_SCOPE = 3 // link local
}
/// <summary>The <c>PNRP_CLOUD_ID</c> structure contains the values that define a network cloud.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/pnrpdef/ns-pnrpdef-pnrp_cloud_id typedef struct _PNRP_CLOUD_ID { INT
// AddressFamily; PNRP_SCOPE Scope; ULONG ScopeId; } PNRP_CLOUD_ID, *PPNRP_CLOUD_ID;
[PInvokeData("pnrpdef.h", MSDNShortId = "NS:pnrpdef._PNRP_CLOUD_ID")]
[StructLayout(LayoutKind.Sequential)]
public struct PNRP_CLOUD_ID
{
/// <summary>Must be AF_INET6.</summary>
public System.Net.Sockets.AddressFamily AddressFamily;
/// <summary>
/// <para>Specifies the scope of the cloud. Use one of the following values:</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>PNRP_SCOPE_ANY</term>
/// <term>The cloud can be in any scope.</term>
/// </item>
/// <item>
/// <term>PNRP_GLOBAL_SCOPE</term>
/// <term>The cloud must be a global scope.</term>
/// </item>
/// <item>
/// <term>PNRP_SITE_LOCAL_SCOPE</term>
/// <term>The cloud must be a site-local scope.</term>
/// </item>
/// <item>
/// <term>PNRP_LINK_LOCAL_SCOPE</term>
/// <term>The cloud must be a link-local scope.</term>
/// </item>
/// </list>
/// </summary>
public PNRP_SCOPE Scope;
/// <summary>Specifies the ID for this scope.</summary>
public uint ScopeId;
}
}
}

175
PInvoke/P2P/Pnrpns.cs Normal file
View File

@ -0,0 +1,175 @@
using System;
using System.Runtime.InteropServices;
using Vanara.InteropServices;
namespace Vanara.PInvoke
{
/// <summary>Items from the P2P.dll</summary>
public static partial class P2P
{
/// <summary>Specifies the flags to use for the resolve operation.</summary>
[PInvokeData("pnrpns.h", MSDNShortId = "NS:pnrpns._PNRPINFO_V1")]
[Flags]
public enum PNRPINFO_FLAGS
{
/// <summary>
/// Indicates that the saHint member is used. The hint influences how the service location portion of the PNRP ID is generated;
/// it also influences how names are resolved, and specifies how to select between multiple peer names.
/// </summary>
PNRPINFO_HINT = 1
}
/// <summary>The <c>PNRPCLOUDINFO</c> structure is pointed to by the <c>lpBlob</c> member of the WSAQUERYSET structure.</summary>
// https://docs.microsoft.com/en-us/windows/win32/api/pnrpns/ns-pnrpns-pnrpcloudinfo typedef struct _PNRPCLOUDINFO { DWORD dwSize;
// PNRP_CLOUD_ID Cloud; PNRP_CLOUD_STATE enCloudState; PNRP_CLOUD_FLAGS enCloudFlags; } PNRPCLOUDINFO, *PPNRPCLOUDINFO;
[PInvokeData("pnrpns.h", MSDNShortId = "NS:pnrpns._PNRPCLOUDINFO")]
[StructLayout(LayoutKind.Sequential)]
public struct PNRPCLOUDINFO
{
/// <summary>Specifies the size of this structure.</summary>
public uint dwSize;
/// <summary>Specifies the network cloud information stored in a PNRP_CLOUD_ID structure.</summary>
public PNRP_CLOUD_ID Cloud;
/// <summary>Specifies the state of the network cloud. Valid values are specified by PNRP_CLOUD_STATE.</summary>
public PNRP_CLOUD_STATE enCloudState;
/// <summary>
/// Indicates if the cloud name is valid on the network or only valid on the current computer. Valid values are specified by PNRP_CLOUD_FLAGS.
/// </summary>
public PNRP_CLOUD_FLAGS enCloudFlags;
}
/// <summary>The <c>PNRPINFO_V1</c> structure is pointed to by the <c>lpBlob</c> member of the WSAQUERYSET structure.</summary>
/// <remarks>Starting with Windows Vista, please use the PNRPINFO_V2 structure.</remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/pnrpns/ns-pnrpns-pnrpinfo_v1 typedef struct _PNRPINFO_V1 { DWORD dwSize;
// LPWSTR lpwszIdentity; DWORD nMaxResolve; DWORD dwTimeout; DWORD dwLifetime; PNRP_RESOLVE_CRITERIA enResolveCriteria; DWORD
// dwFlags; SOCKET_ADDRESS saHint; PNRP_REGISTERED_ID_STATE enNameState; } PNRPINFO_V1, *PPNRPINFO_V1;
[PInvokeData("pnrpns.h", MSDNShortId = "NS:pnrpns._PNRPINFO_V1")]
[StructLayout(LayoutKind.Sequential)]
public struct PNRPINFO_V1
{
/// <summary>Specifies the size of this structure.</summary>
public uint dwSize;
/// <summary>Points to the Unicode string that contains the identity.</summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string lpwszIdentity;
/// <summary>Specifies the requested number of resolutions.</summary>
public uint nMaxResolve;
/// <summary>Specifies the time, in seconds, to wait for a response.</summary>
public uint dwTimeout;
/// <summary>Specifies the number of seconds between refresh operations. Must be 86400 (24 * 60 * 60 seconds).</summary>
public uint dwLifetime;
/// <summary>
/// Specifies the criteria used to resolve matches. PNRP can look for the first matching name, or attempt to find a name that is
/// numerically close to the service location. Valid values are specified by PNRP_RESOLVE_CRITERIA.
/// </summary>
public PNRP_RESOLVE_CRITERIA enResolveCriteria;
/// <summary>
/// <para>Specifies the flags to use for the resolve operation. The valid value is:</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>PNRPINFO_HINT</term>
/// <term>
/// Indicates that the saHint member is used. The hint influences how the service location portion of the PNRP ID is generated;
/// it also influences how names are resolved, and specifies how to select between multiple peer names.
/// </term>
/// </item>
/// </list>
/// </summary>
public PNRPINFO_FLAGS dwFlags;
/// <summary>Specifies the IPv6 address to use for the location. The <c>dwFlags</c> member must be PNRPINFO_HINT.</summary>
public Ws2_32.SOCKET_ADDRESS saHint;
/// <summary>Specifies the state of the registered ID. This value is reserved and must be set to zero (0).</summary>
public PNRP_REGISTERED_ID_STATE enNameState;
}
/// <summary>The <c>PNRPINFO_V1</c> structure is pointed to by the <c>lpBlob</c> member of the WSAQUERYSET structure.</summary>
/// <remarks>Starting with Windows Vista, please use the PNRPINFO_V2 structure.</remarks>
// https://docs.microsoft.com/en-us/windows/win32/api/pnrpns/ns-pnrpns-pnrpinfo_v2 typedef struct _PNRPINFO_V2 { DWORD dwSize;
// LPWSTR lpwszIdentity; DWORD nMaxResolve; DWORD dwTimeout; DWORD dwLifetime; PNRP_RESOLVE_CRITERIA enResolveCriteria; DWORD
// dwFlags; SOCKET_ADDRESS saHint; PNRP_REGISTERED_ID_STATE enNameState; PNRP_EXTENDED_PAYLOAD_TYPE enExtendedPayloadType; union {
// BLOB blobPayload; PWSTR pwszPayload; }; } PNRPINFO_V2, *PPNRPINFO_V2;
[PInvokeData("pnrpns.h", MSDNShortId = "NS:pnrpns._PNRPINFO_V2")]
[StructLayout(LayoutKind.Sequential)]
public struct PNRPINFO_V2
{
/// <summary>Specifies the size of this structure.</summary>
public uint dwSize;
/// <summary>Points to the Unicode string that contains the identity.</summary>
[MarshalAs(UnmanagedType.LPWStr)]
public string lpwszIdentity;
/// <summary>Specifies the requested number of resolutions.</summary>
public uint nMaxResolve;
/// <summary>Specifies the time, in seconds, to wait for a response.</summary>
public uint dwTimeout;
/// <summary>Specifies the number of seconds between refresh operations. Must be 86400 (24 * 60 * 60 seconds).</summary>
public uint dwLifetime;
/// <summary>
/// Specifies the criteria used to resolve matches. PNRP can look for the first matching name, or attempt to find a name that is
/// numerically close to the service location. Valid values are specified by PNRP_RESOLVE_CRITERIA.
/// </summary>
public PNRP_RESOLVE_CRITERIA enResolveCriteria;
/// <summary>
/// <para>Specifies the flags to use for the resolve operation. The valid value is:</para>
/// <list type="table">
/// <listheader>
/// <term>Value</term>
/// <term>Description</term>
/// </listheader>
/// <item>
/// <term>PNRPINFO_HINT</term>
/// <term>
/// Indicates that the saHint member is used. The hint influences how the service location portion of the PNRP ID is generated;
/// it also influences how names are resolved, and specifies how to select between multiple peer names.
/// </term>
/// </item>
/// </list>
/// </summary>
public PNRPINFO_FLAGS dwFlags;
/// <summary>Specifies the IPv6 address to use for the location. The <c>dwFlags</c> member must be PNRPINFO_HINT.</summary>
public Ws2_32.SOCKET_ADDRESS saHint;
/// <summary>Specifies the state of the registered ID. This value is reserved and must be set to zero (0).</summary>
public PNRP_REGISTERED_ID_STATE enNameState;
/// <summary/>
public PNRP_EXTENDED_PAYLOAD_TYPE enExtendedPayloadType;
private UNION union;
/// <summary/>
public Ws2_32.BLOB blobPayload { get => union.blob; set => union.blob = value; }
/// <summary/>
public StrPtrUni pwszPayload { get => union.str; set => union.str = value; }
[StructLayout(LayoutKind.Explicit)]
private struct UNION
{
[FieldOffset(0)] public Ws2_32.BLOB blob;
[FieldOffset(0)] public StrPtrUni str;
}
}
}
}