using System;
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
{
/// Items from the P2P.dll
public static partial class P2P
{
///
/// The PeerCreatePeerName function creates a new name based on the existing name of the specified peer identity and
/// classifier. However, a new identity is not created by a call to PeerCreatePeerName.
///
///
///
/// Specifies the identity to use as the basis for the new peer name. If pwzIdentity is NULL, the name created is not based
/// on any peer identity, and is therefore an unsecured name.
///
/// This parameter can only be NULL if pwzClassifier is not NULL.
///
///
///
/// Pointer to the Unicode string that contains the new classifier. This classifier is appended to the existing authority portion of
/// the peer name of the specified identity. This string is 150 characters long, including the NULL terminator. Specify
/// NULL to return the peer name of the identity.
///
/// This parameter can only be NULL if pwzIdentity is not NULL.
///
///
/// Pointer that receives a pointer to the new peer name. When this string is not required anymore, free it by calling PeerFreeData.
///
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// One of the parameters is not valid.
///
/// -
/// E_OUTOFMEMORY
/// There is not enough memory to perform the specified operation.
///
///
///
/// The parameter ppwzPeername must be set to null before the PeerCreatePeerName function is called.
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peercreatepeername NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerCreatePeerName( PCWSTR pwzIdentity, PCWSTR pwzClassifier, PWSTR *ppwzPeerName );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCreatePeerName")]
public static extern HRESULT PeerCreatePeerName([Optional, MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pwzClassifier,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PeerStringMarshaler))] out string ppwzPeerName);
///
/// The PeerEnumGroups function creates and returns a peer enumeration handle used to enumerate all the peer groups
/// associated with a specific peer identity.
///
/// Specifies the peer identity to enumerate groups for.
///
/// Receives a handle to 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. Pass this handle to PeerGetNextItem to retrieve the items;
/// when finished, call PeerEndEnumeration release the memory.
///
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// One of the parameters is not valid.
///
/// -
/// E_OUTOFMEMORY
/// There is not enough memory to perform the specified operation.
///
/// -
/// PEER_E_NOT_FOUND
/// The specified peer identity cannot be found.
///
///
///
///
///
/// Once the application has obtained the enumeration handle, use PeerGetNextItem and PeerGetItemCount to enumerate the peer groups.
///
/// When enumerating peer groups, PeerGetNextItem returns an array of pointers to PEER_NAME_PAIR structures.
/// Call PeerEndEnumeration to free the peer enumeration handle when it is no longer required.
///
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerenumgroups NOT_BUILD_WINDOWS_DEPRECATE HRESULT PeerEnumGroups(
// 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);
/// The PeerEnumGroups function enumerates all the peer groups associated with a specific peer identity.
/// Specifies the peer identity to enumerate groups for.
///
/// 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.
///
// 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 SafePeerList PeerEnumGroups(string pwzIdentity) =>
PeerEnum(() => { PeerEnumGroups(pwzIdentity, out var h).ThrowIfFailed(); return h; });
///
/// The PeerEnumIdentities function creates and returns a peer enumeration handle used to enumerate all the peer identities
/// that belong to a specific user.
///
///
/// Receives a handle to the peer enumeration that contains the list of peer identities, with each item represented as a pointer to
/// a PEER_NAME_PAIR structure. Pass this handle to PeerGetNextItem to retrieve the items; when finished, call PeerEndEnumeration to
/// release the memory.
///
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// One of the parameters is not valid.
///
/// -
/// E_OUTOFMEMORY
/// There is not enough memory to perform the specified operation.
///
///
///
///
///
/// Once the application has obtained the peer enumeration handle, use PeerGetNextItem and PeerGetItemCount to enumerate the peer identities.
///
/// When enumerating peer identities, PeerGetNextItem returns an array of pointers to PEER_NAME_PAIR structures.
/// Call PeerEndEnumeration to free the enumeration handle when it is no longer required.
///
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peerenumidentities NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// 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);
/// The PeerEnumIdentities function enumerates all the peer identities that belong to a specific user.
///
/// The peer enumeration that contains the list of peer identities, with each item represented as a pointer to a PEER_NAME_PAIR
/// structure. ///
///
// 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 SafePeerList PeerEnumIdentities() =>
PeerEnum(() => { PeerEnumIdentities(out var h).ThrowIfFailed(); return h; });
///
/// The PeerIdentityCreate function creates a new peer identity and returns its name. The name of the peer identity must be
/// passed in all subsequent calls to the Peer Identity Manager, Peer Grouping, or PNRP functions that operate on behalf of the peer
/// identity. The peer identity name specifies which peer identity is being used.
///
///
/// Specifies the classifier to append to the published peer identity name. This string is a Unicode string, and can be NULL.
/// This string can only be 150 characters long, including the NULL terminator.
///
///
/// Specifies the friendly name of the peer identity. This is a Unicode string, and can be NULL. This string can only be 256
/// characters long, including the NULL terminator. If pwzFriendlyName is NULL, the name of the identity is the
/// friendly name. The friendly name is optional, and it does not have to be unique.
///
///
///
/// Handle to the cryptographic service provider (CSP) that contains an AT_KEYEXCHANGE key pair of at least 1024 bits in length.
/// This key pair is used as the basis for a new peer identity. If hCryptProv is zero (0), a new key pair is generated for the peer identity.
///
///
/// Note The Identity Manager API does not support a CSP that has user protected keys. If a CSP that has user protected keys
/// is used, PeerIdentityCreate returns E_INVALIDARG.
///
///
///
/// Receives a pointer to the name of an peer identity that is created. This name must be used in all subsequent calls to the Peer
/// Identity Manager, Peer Grouping, or PNRP functions that operate on behalf of the peer identity. Returns NULL if the peer
/// identity cannot be created.
///
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// ERROR_INVALID_HANDLE
/// The handle to the key specified by hCryptProv is not valid.
///
/// -
/// E_INVALIDARG
/// One of the parameters is not valid.
///
/// -
/// E_OUTOFMEMORY
/// There is not enough memory to perform the specified operation.
///
/// -
/// PEER_E_ALREADY_EXISTS
/// The peer identity already exists. Only occurs if an peer identity based on the specified key and classifier already exists.
///
/// -
/// PEER_E_NO_KEY_ACCESS
///
/// Access to the peer identity or peer group keys is denied. Typically, this is caused by an incorrect access control list (ACL)
/// for the folder that contains the user or computer keys. This can happen when the ACL has been reset manually.
///
///
/// -
/// PEER_E_TOO_MANY_IDENTITIES
/// The peer identity cannot be created because there are too many peer identities.
///
///
///
///
///
/// The key pair and the classifier are used to generate the peer name of a new peer identity. After an peer identity is created, it
/// is automatically stored on the disk.
///
///
/// The name of the identity should be freed by using PeerFreeData. This does not delete the peer identity. To delete the identity,
/// use PeerIdentityDelete function.
///
/// If hCryptProv is not NULL, it can be released by using CryptReleaseContext after the call returns.
///
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peeridentitycreate NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerIdentityCreate( PCWSTR pwzClassifier, PCWSTR pwzFriendlyName, HCRYPTPROV hCryptProv, PWSTR *ppwzIdentity );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerIdentityCreate")]
public static extern HRESULT PeerIdentityCreate([Optional, MarshalAs(UnmanagedType.LPWStr)] string pwzClassifier,
[Optional, MarshalAs(UnmanagedType.LPWStr)] string pwzFriendlyName, [In, Optional] HCRYPTPROV hCryptProv,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PeerStringMarshaler))] out string ppwzIdentity);
///
/// The PeerIdentityDelete function permanently deletes a peer identity. This includes removing all certificates, private
/// keys, and all group information associated with a specified peer identity.
///
/// Specifies a peer identity to delete.
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// The parameter is not valid.
///
/// -
/// PEER_E_GROUPS_EXIST
///
/// The peer identity cannot be deleted because it has peer groups associated with it. All peer groups associated with the specified
/// identity must be deleted by using PeerGroupDelete before a call to PeerIdentityDelete can succeed.
///
///
/// -
/// PEER_E_NOT_FOUND
/// A peer identity that matches the specified name cannot be found.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peeridentitydelete NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerIdentityDelete( PCWSTR pwzIdentity );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerIdentityDelete")]
public static extern HRESULT PeerIdentityDelete([MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity);
///
/// The PeerIdentityExport function allows a user to export one peer identity. The user can then transfer the peer identity
/// to a different computer.
///
/// Specifies the peer identity to export. This parameter is required and does not have a default value.
///
/// Specifies the password to use to encrypt the peer identity. This parameter cannot be NULL. This password must also be
/// used to import the peer identity, or the import operation fails.
///
///
/// Receives a pointer to the exported peer identity in XML format. If the export operation is successful, the application must free
/// ppwzExportXML by calling PeerFreeData.
///
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// One of the parameters is not valid.
///
/// -
/// E_OUTOFMEMORY
/// There is not enough memory to perform the specified operation.
///
/// -
/// PEER_E_NO_KEY_ACCESS
///
/// Access to the peer identity or peer group keys was denied. This is typically caused by an incorrect access control list (ACL)
/// for the folder that contains the user or computer keys. This can happen when the ACL has been manually reset.
///
///
/// -
/// PEER_E_NOT_FOUND
/// The specified peer identity does not exist.
///
///
///
///
///
/// Peer-to-peer group membership credentials are not exported. Only one peer identity is exported. An exported peer identity can be
/// imported on another computer by using PeerIdentityImport.
///
///
/// Exporting a peer identity does not remove it from a local ccmputer, it makes a copy of it. The copy can be used to backup and
/// restore a peer identity.
///
/// The XML fragment used by PeerIdentityExport is as follows:
///
/// <PEERIDENTITYEXPORT VERSION="1.0"> <PEERNAME> <!-- UTF-8 encoded peer name of the identity --> </PEERNAME> <DATA xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64"> <!-- base64 encoded / PFX encoded and encrypted IDC with the private key --> </DATA> </PEERIDENTITYEXPORT>
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peeridentityexport NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerIdentityExport( PCWSTR pwzIdentity, PCWSTR pwzPassword, PWSTR *ppwzExportXML );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerIdentityExport")]
public static extern HRESULT PeerIdentityExport([MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity, [MarshalAs(UnmanagedType.LPWStr)] string pwzPassword,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PeerStringMarshaler))] out string ppwzExportXML);
/// The PeerIdentityGetCryptKey function retrieves a handle to a cryptographic service provider (CSP).
/// Specifies the peer identity to retrieve the key pair for.
///
/// Receives a pointer to the handle of the cryptographic service provider (CSP) that contains an AT_KEYEXCHANGE RSA key pair.
///
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// One of the parameters is not valid.
///
/// -
/// E_OUTOFMEMORY
/// There is not enough memory to perform the specified operation.
///
/// -
/// PEER_E_NO_KEY_ACCESS
///
/// Access to the peer identity or peer group keys is denied. Typically, this is caused by an incorrect access control list (ACL)
/// for the folder that contains the user or computer keys. This can happen when the ACL has been manually reset.
///
///
/// -
/// PEER_E_NOT_FOUND
/// An identity that matches the specified name cannot be found.
///
///
///
///
/// The key can be retrieved by calling CryptGetUserKey.
/// When the handle is not required anymore, the application is responsible for releasing the handle by using .
///
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peeridentitygetcryptkey NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerIdentityGetCryptKey( PCWSTR pwzIdentity, HCRYPTPROV *phCryptProv );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerIdentityGetCryptKey")]
public static extern HRESULT PeerIdentityGetCryptKey([MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity, out SafeHCRYPTPROV phCryptProv);
/// The PeerIdentityGetDefault function retrieves the default peer name set for the current user.
///
/// Pointer to the address of a zero-terminated Unicode string that contains the default name of the current user.
///
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// One of the parameters is not valid.
///
/// -
/// E_OUTOFMEMORY
/// There is not enough memory to perform the specified operation.
///
/// -
/// PEER_E_NOT_FOUND
/// A peer identity that matches the specified name cannot be found.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peeridentitygetdefault NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerIdentityGetDefault( PWSTR *ppwzPeerName );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerIdentityGetDefault")]
public static extern HRESULT PeerIdentityGetDefault([MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PeerStringMarshaler))] out string ppwzPeerName);
/// The PeerIdentityGetFriendlyName function returns the friendly name of the peer identity.
/// Specifies the peer identity to obtain a friendly name.
///
/// Receives a pointer to the friendly name. When ppwzFriendlyName is not required anymore, the application is responsible for
/// freeing this string by calling PeerFreeData.
///
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// One of the parameters is not valid.
///
/// -
/// E_OUTOFMEMORY
/// There is not enough memory to perform the specified operation.
///
/// -
/// PEER_E_NO_KEY_ACCESS
///
/// Access to the peer identity or peer group keys is denied. Typically, this is caused by an incorrect access control list (ACL)
/// for the folder that contains the user or computer keys. This can happen when the ACL has been reset manually.
///
///
/// -
/// PEER_E_NOT_FOUND
/// A peer identity that matches the specified name cannot be found.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peeridentitygetfriendlyname NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerIdentityGetFriendlyName( PCWSTR pwzIdentity, PWSTR *ppwzFriendlyName );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerIdentityGetFriendlyName")]
public static extern HRESULT PeerIdentityGetFriendlyName([MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PeerStringMarshaler))] out string ppwzFriendlyName);
///
/// The PeerIdentityGetXML function returns a description of the peer identity, which can then be passed to third parties and
/// used to invite a peer identity into a peer group. This information is returned as an XML fragment.
///
///
/// Specifies the peer identity to retrieve peer identity information for. When this parameter is passed as NULL, a "default"
/// identity will be generated for the user by the peer infrastructure.
///
///
/// Pointer to a pointer to a Unicode string that contains the XML fragment. When ppwzIdentityXML is no longer required, the
/// application is responsible for freeing this string by calling PeerFreeData.
///
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// E_HANDLE
/// The handle to the identity is invalid.
///
/// -
/// E_INVALIDARG
/// One of the parameters is not valid.
///
/// -
/// E_OUTOFMEMORY
/// There is not enough memory to perform the specified operation.
///
///
///
///
/// The XML fragment returned has the following structure:
///
/// <PEERIDENTITYINFO VERSION="1.0"> <IDC xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64"> Base 64 encoded certificate. </IDC> </PEERIDENTITYINFO>
///
/// This XML fragment is used when creating an invitation to join a group.
///
/// Applications are not allowed to add tags within the PEERIDENTITYINFO tag or modify this XML fragment in any way.
/// Applications are allowed to incorporate this XML fragment into other XML documents, but must strip out all application-specific
/// XML before passing this fragment to the PeerGroupCreateInvitation.
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peeridentitygetxml NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerIdentityGetXML( PCWSTR pwzIdentity, PWSTR *ppwzIdentityXML );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerIdentityGetXML")]
public static extern HRESULT PeerIdentityGetXML([MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PeerStringMarshaler))] out string ppwzIdentityXML);
///
/// The PeerIdentityImport function imports one peer identity. If the peer identity exists on a computer,
/// PEER_E_ALREADY_EXISTS is returned.
///
///
/// Pointer to the XML format peer identity to import, which is returned by PeerIdentityExport. This binary data must match the
/// exported data byte-for-byte. The XML must remain valid XML with no extra characters.
///
///
/// Specifies the password to use to de-crypt a peer identity. The password must be identical to the password supplied to
/// PeerIdentityExport. This parameter cannot be NULL.
///
///
/// Pointer to a string that represents a peer identity that is imported. If the import operation is successful, the application
/// must free ppwzIdentity by calling PeerFreeData.
///
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// One of the parameters is not valid, or the XML data in ppwzImportXML has been tampered with.
///
/// -
/// E_OUTOFMEMORY
/// There is not enough memory to perform the specified operation.
///
/// -
/// PEER_E_ALREADY_EXISTS
/// The peer identity already exists on this computer.
///
/// -
/// PEER_E_NO_KEY_ACCESS
///
/// Access to the peer identity or peer group keys is denied. Typically, this is caused by an incorrect access control list (ACL)
/// for the folder that contains the user or computer keys. This can happen when the ACL has been reset manually.
///
///
///
///
///
/// The XML fragment used by PeerIdentityImport is as follows:
///
/// <PEERIDENTITYEXPORT VERSION="1.0"> <IDENTITY> <!-- UTF-8 encoded peer name of the identity --> </IDENTITY> <IDENTITYDATA xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="bin.base64"> <!-- base64 encoded / PFX encoded and encrypted IDC with the private key --> </IDENTTYDATA> </PEERIDENTITYEXPORT>
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peeridentityimport NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerIdentityImport( PCWSTR pwzImportXML, PCWSTR pwzPassword, PWSTR *ppwzIdentity );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerIdentityImport")]
public static extern HRESULT PeerIdentityImport([MarshalAs(UnmanagedType.LPWStr)] string pwzImportXML, [MarshalAs(UnmanagedType.LPWStr)] string pwzPassword,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PeerStringMarshaler))] out string ppwzIdentity);
///
/// The PeerIdentitySetFriendlyName function modifies the friendly name for a specified peer identity. The friendly name is
/// the human-readable name.
///
/// Specifies a peer identity to modify.
///
/// Specifies a new friendly name. Specify NULL or an empty string to reset a friendly name to the default value, which is
/// the Unicode version of the peer name.
///
///
/// If the function call succeeds, the return value is S_OK. Otherwise, it returns one of the following values.
///
///
/// Return code
/// Description
///
/// -
/// E_INVALIDARG
/// One of the parameters is not valid.
///
/// -
/// E_OUTOFMEMORY
/// There is not enough memory to perform the specified operation.
///
/// -
/// PEER_E_NO_KEY_ACCESS
///
/// Access to the peer identity or peer group keys is denied. Typically, this is caused by an incorrect access control list (ACL)
/// for the folder that contains the user or computer keys. This can happen when the ACL has been reset manually.
///
///
/// -
/// PEER_E_NOT_FOUND
/// A peer identity that matches a specified name cannot be found.
///
///
///
// https://docs.microsoft.com/en-us/windows/win32/api/p2p/nf-p2p-peeridentitysetfriendlyname NOT_BUILD_WINDOWS_DEPRECATE HRESULT
// PeerIdentitySetFriendlyName( PCWSTR pwzIdentity, PCWSTR pwzFriendlyName );
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerIdentitySetFriendlyName")]
public static extern HRESULT PeerIdentitySetFriendlyName([MarshalAs(UnmanagedType.LPWStr)] string pwzIdentity, [Optional, MarshalAs(UnmanagedType.LPWStr)] string pwzFriendlyName);
}
}