Skip to content

Commit 9cf553d

Browse files
author
dahall
committed
Added autogen handles to P2P, Pdh, PeerDist, PowrProf,Printing,ProjectedFSLib,QoS,SetupAPI,Shell32
1 parent 531e76e commit 9cf553d

34 files changed

+78
-2156
lines changed

PInvoke/ComCtl32/Vanara.PInvoke.ComCtl32.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ IImageList IImageList2
2727
<PropertyGroup Condition="'$(Configuration)'=='Release'">
2828
<NoWarn>1591</NoWarn>
2929
</PropertyGroup>
30-
<ItemGroup>
31-
<AdditionalFiles Include="handles.csv" />
32-
</ItemGroup>
3330
<ItemGroup>
3431
<ProjectReference Include="..\User32\Vanara.PInvoke.User32.csproj" />
3532
</ItemGroup>

PInvoke/ComCtl32/handles.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.

PInvoke/P2P/P2P.Collab.cs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,76 +2635,6 @@ public static extern HRESULT PeerCollabQueryContactData([In, Optional] IntPtr pc
26352635
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerCollabUpdateContact")]
26362636
public static extern HRESULT PeerCollabUpdateContact(in PEER_CONTACT pContact);
26372637

2638-
/// <summary>Provides a handle to a peer collaboration network event.</summary>
2639-
[StructLayout(LayoutKind.Sequential)]
2640-
public struct HPEEREVENT : IHandle
2641-
{
2642-
private IntPtr handle;
2643-
2644-
/// <summary>Initializes a new instance of the <see cref="HPEEREVENT"/> struct.</summary>
2645-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
2646-
public HPEEREVENT(IntPtr preexistingHandle) => handle = preexistingHandle;
2647-
2648-
/// <summary>Returns an invalid handle by instantiating a <see cref="HPEEREVENT"/> object with <see cref="IntPtr.Zero"/>.</summary>
2649-
public static HPEEREVENT NULL => new(IntPtr.Zero);
2650-
2651-
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
2652-
public bool IsNull => handle == IntPtr.Zero;
2653-
2654-
/// <summary>Performs an explicit conversion from <see cref="HPEEREVENT"/> to <see cref="IntPtr"/>.</summary>
2655-
/// <param name="h">The handle.</param>
2656-
/// <returns>The result of the conversion.</returns>
2657-
public static explicit operator IntPtr(HPEEREVENT h) => h.handle;
2658-
2659-
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HPEEREVENT"/>.</summary>
2660-
/// <param name="h">The pointer to a handle.</param>
2661-
/// <returns>The result of the conversion.</returns>
2662-
public static implicit operator HPEEREVENT(IntPtr h) => new(h);
2663-
2664-
/// <summary>Implements the operator !=.</summary>
2665-
/// <param name="h1">The first handle.</param>
2666-
/// <param name="h2">The second handle.</param>
2667-
/// <returns>The result of the operator.</returns>
2668-
public static bool operator !=(HPEEREVENT h1, HPEEREVENT h2) => !(h1 == h2);
2669-
2670-
/// <summary>Implements the operator ==.</summary>
2671-
/// <param name="h1">The first handle.</param>
2672-
/// <param name="h2">The second handle.</param>
2673-
/// <returns>The result of the operator.</returns>
2674-
public static bool operator ==(HPEEREVENT h1, HPEEREVENT h2) => h1.Equals(h2);
2675-
2676-
/// <inheritdoc/>
2677-
public override bool Equals(object? obj) => obj is HPEEREVENT h && handle == h.handle;
2678-
2679-
/// <inheritdoc/>
2680-
public override int GetHashCode() => handle.GetHashCode();
2681-
2682-
/// <inheritdoc/>
2683-
public IntPtr DangerousGetHandle() => handle;
2684-
}
2685-
2686-
/// <summary>Provides a <see cref="SafeHandle"/> for <see cref="HPEEREVENT"/> that is disposed using <see cref="PeerCollabUnregisterEvent"/>.</summary>
2687-
public class SafeCollabHPEEREVENT : SafeHANDLE
2688-
{
2689-
/// <summary>Initializes a new instance of the <see cref="SafeCollabHPEEREVENT"/> class and assigns an existing handle.</summary>
2690-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
2691-
/// <param name="ownsHandle">
2692-
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
2693-
/// </param>
2694-
public SafeCollabHPEEREVENT(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
2695-
2696-
/// <summary>Initializes a new instance of the <see cref="SafeCollabHPEEREVENT"/> class.</summary>
2697-
private SafeCollabHPEEREVENT() : base() { }
2698-
2699-
/// <summary>Performs an implicit conversion from <see cref="SafeCollabHPEEREVENT"/> to <see cref="HPEEREVENT"/>.</summary>
2700-
/// <param name="h">The safe handle instance.</param>
2701-
/// <returns>The result of the conversion.</returns>
2702-
public static implicit operator HPEEREVENT(SafeCollabHPEEREVENT h) => h.handle;
2703-
2704-
/// <inheritdoc/>
2705-
protected override bool InternalReleaseHandle() => PeerCollabUnregisterEvent(handle).Succeeded;
2706-
}
2707-
27082638
/// <summary>Provides a <see cref="SafeHandle"/> for P2P collaboration handle that is disposed using <see cref="PeerCollabCloseHandle"/>.</summary>
27092639
public class SafePeerCollabHandle : SafeHANDLE
27102640
{

PInvoke/P2P/P2P.Funcs.cs

Lines changed: 3 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -872,169 +872,8 @@ private static SafePeerList<T> PeerEnum<T>(Func<SafeHPEERENUM> setup) where T :
872872
return hEnum.GetItems<T>();
873873
}
874874

875-
/// <summary>Provides a handle to a peer enumeration.</summary>
876-
[StructLayout(LayoutKind.Sequential)]
877-
public struct HPEERENUM : IHandle
875+
public partial class SafeHPEERENUM
878876
{
879-
private IntPtr handle;
880-
881-
/// <summary>Initializes a new instance of the <see cref="HPEERENUM"/> struct.</summary>
882-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
883-
public HPEERENUM(IntPtr preexistingHandle) => handle = preexistingHandle;
884-
885-
/// <summary>Returns an invalid handle by instantiating a <see cref="HPEERENUM"/> object with <see cref="IntPtr.Zero"/>.</summary>
886-
public static HPEERENUM NULL => new(IntPtr.Zero);
887-
888-
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
889-
public bool IsNull => handle == IntPtr.Zero;
890-
891-
/// <summary>Performs an explicit conversion from <see cref="HPEERENUM"/> to <see cref="IntPtr"/>.</summary>
892-
/// <param name="h">The handle.</param>
893-
/// <returns>The result of the conversion.</returns>
894-
public static explicit operator IntPtr(HPEERENUM h) => h.handle;
895-
896-
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HPEERENUM"/>.</summary>
897-
/// <param name="h">The pointer to a handle.</param>
898-
/// <returns>The result of the conversion.</returns>
899-
public static implicit operator HPEERENUM(IntPtr h) => new(h);
900-
901-
/// <summary>Implements the operator !=.</summary>
902-
/// <param name="h1">The first handle.</param>
903-
/// <param name="h2">The second handle.</param>
904-
/// <returns>The result of the operator.</returns>
905-
public static bool operator !=(HPEERENUM h1, HPEERENUM h2) => !(h1 == h2);
906-
907-
/// <summary>Implements the operator ==.</summary>
908-
/// <param name="h1">The first handle.</param>
909-
/// <param name="h2">The second handle.</param>
910-
/// <returns>The result of the operator.</returns>
911-
public static bool operator ==(HPEERENUM h1, HPEERENUM h2) => h1.Equals(h2);
912-
913-
/// <inheritdoc/>
914-
public override bool Equals(object? obj) => obj is HPEERENUM h && handle == h.handle;
915-
916-
/// <inheritdoc/>
917-
public override int GetHashCode() => handle.GetHashCode();
918-
919-
/// <inheritdoc/>
920-
public IntPtr DangerousGetHandle() => handle;
921-
}
922-
923-
/// <summary>Provides a handle to the PNRP registration for the calling peer node.</summary>
924-
[StructLayout(LayoutKind.Sequential)]
925-
public struct HREGISTRATION : IHandle
926-
{
927-
private IntPtr handle;
928-
929-
/// <summary>Initializes a new instance of the <see cref="HREGISTRATION"/> struct.</summary>
930-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
931-
public HREGISTRATION(IntPtr preexistingHandle) => handle = preexistingHandle;
932-
933-
/// <summary>Returns an invalid handle by instantiating a <see cref="HREGISTRATION"/> object with <see cref="IntPtr.Zero"/>.</summary>
934-
public static HREGISTRATION NULL => new(IntPtr.Zero);
935-
936-
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
937-
public bool IsNull => handle == IntPtr.Zero;
938-
939-
/// <summary>Performs an explicit conversion from <see cref="HREGISTRATION"/> to <see cref="IntPtr"/>.</summary>
940-
/// <param name="h">The handle.</param>
941-
/// <returns>The result of the conversion.</returns>
942-
public static explicit operator IntPtr(HREGISTRATION h) => h.handle;
943-
944-
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HREGISTRATION"/>.</summary>
945-
/// <param name="h">The pointer to a handle.</param>
946-
/// <returns>The result of the conversion.</returns>
947-
public static implicit operator HREGISTRATION(IntPtr h) => new(h);
948-
949-
/// <summary>Implements the operator !=.</summary>
950-
/// <param name="h1">The first handle.</param>
951-
/// <param name="h2">The second handle.</param>
952-
/// <returns>The result of the operator.</returns>
953-
public static bool operator !=(HREGISTRATION h1, HREGISTRATION h2) => !(h1 == h2);
954-
955-
/// <summary>Implements the operator ==.</summary>
956-
/// <param name="h1">The first handle.</param>
957-
/// <param name="h2">The second handle.</param>
958-
/// <returns>The result of the operator.</returns>
959-
public static bool operator ==(HREGISTRATION h1, HREGISTRATION h2) => h1.Equals(h2);
960-
961-
/// <inheritdoc/>
962-
public override bool Equals(object? obj) => obj is HREGISTRATION h && handle == h.handle;
963-
964-
/// <inheritdoc/>
965-
public override int GetHashCode() => handle.GetHashCode();
966-
967-
/// <inheritdoc/>
968-
public IntPtr DangerousGetHandle() => handle;
969-
}
970-
971-
/// <summary>Provides a handle to an asynchronous peer name resolution operation.</summary>
972-
[StructLayout(LayoutKind.Sequential)]
973-
public struct HRESOLUTION : IHandle
974-
{
975-
private IntPtr handle;
976-
977-
/// <summary>Initializes a new instance of the <see cref="HRESOLUTION"/> struct.</summary>
978-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
979-
public HRESOLUTION(IntPtr preexistingHandle) => handle = preexistingHandle;
980-
981-
/// <summary>Returns an invalid handle by instantiating a <see cref="HRESOLUTION"/> object with <see cref="IntPtr.Zero"/>.</summary>
982-
public static HRESOLUTION NULL => new(IntPtr.Zero);
983-
984-
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
985-
public bool IsNull => handle == IntPtr.Zero;
986-
987-
/// <summary>Performs an explicit conversion from <see cref="HRESOLUTION"/> to <see cref="IntPtr"/>.</summary>
988-
/// <param name="h">The handle.</param>
989-
/// <returns>The result of the conversion.</returns>
990-
public static explicit operator IntPtr(HRESOLUTION h) => h.handle;
991-
992-
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HRESOLUTION"/>.</summary>
993-
/// <param name="h">The pointer to a handle.</param>
994-
/// <returns>The result of the conversion.</returns>
995-
public static implicit operator HRESOLUTION(IntPtr h) => new(h);
996-
997-
/// <summary>Implements the operator !=.</summary>
998-
/// <param name="h1">The first handle.</param>
999-
/// <param name="h2">The second handle.</param>
1000-
/// <returns>The result of the operator.</returns>
1001-
public static bool operator !=(HRESOLUTION h1, HRESOLUTION h2) => !(h1 == h2);
1002-
1003-
/// <summary>Implements the operator ==.</summary>
1004-
/// <param name="h1">The first handle.</param>
1005-
/// <param name="h2">The second handle.</param>
1006-
/// <returns>The result of the operator.</returns>
1007-
public static bool operator ==(HRESOLUTION h1, HRESOLUTION h2) => h1.Equals(h2);
1008-
1009-
/// <inheritdoc/>
1010-
public override bool Equals(object? obj) => obj is HRESOLUTION h && handle == h.handle;
1011-
1012-
/// <inheritdoc/>
1013-
public override int GetHashCode() => handle.GetHashCode();
1014-
1015-
/// <inheritdoc/>
1016-
public IntPtr DangerousGetHandle() => handle;
1017-
}
1018-
1019-
/// <summary>Provides a <see cref="SafeHandle"/> for <see cref="HPEERENUM"/> that is disposed using <see cref="PeerEndEnumeration"/>.</summary>
1020-
/// <seealso cref="Vanara.PInvoke.SafeHANDLE"/>
1021-
public class SafeHPEERENUM : SafeHANDLE
1022-
{
1023-
/// <summary>Initializes a new instance of the <see cref="SafeHPEERENUM"/> class and assigns an existing handle.</summary>
1024-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
1025-
/// <param name="ownsHandle">
1026-
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
1027-
/// </param>
1028-
public SafeHPEERENUM(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
1029-
1030-
/// <summary>Initializes a new instance of the <see cref="SafeHPEERENUM"/> class.</summary>
1031-
private SafeHPEERENUM() : base() { }
1032-
1033-
/// <summary>Performs an implicit conversion from <see cref="SafeHPEERENUM"/> to <see cref="HPEERENUM"/>.</summary>
1034-
/// <param name="h">The safe handle instance.</param>
1035-
/// <returns>The result of the conversion.</returns>
1036-
public static implicit operator HPEERENUM(SafeHPEERENUM h) => h.handle;
1037-
1038877
/// <summary>Gets the enumerated items.</summary>
1039878
/// <typeparam name="T">The type of the structure that can be enumerated.</typeparam>
1040879
/// <returns>A <see cref="SafePeerList{T}"/> that exposes the enumeration.</returns>
@@ -1051,32 +890,17 @@ public SafePeerList<T> GetItems<T>() where T : struct
1051890
else
1052891
return new SafePeerList<T>();
1053892
}
1054-
1055-
/// <inheritdoc/>
1056-
protected override bool InternalReleaseHandle() => PeerEndEnumeration(handle).Succeeded;
1057893
}
1058894

1059895
/// <summary>Provides a <see cref="SafeHandle"/> for data that is disposed using <see cref="PeerFreeData"/>.</summary>
1060-
public class SafePeerData : SafeHANDLE
896+
[AutoSafeHandle("{ PeerFreeData(handle); return true; }")]
897+
public partial class SafePeerData
1061898
{
1062-
/// <summary>Initializes a new instance of the <see cref="SafePeerData"/> class.</summary>
1063-
protected internal SafePeerData() : base() { }
1064-
1065-
/// <summary>Initializes a new instance of the <see cref="SafePeerData"/> class.</summary>
1066-
/// <param name="preexistingHandle">An <see cref="T:System.IntPtr"/> object that represents the pre-existing handle to use.</param>
1067-
/// <param name="ownsHandle">
1068-
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
1069-
/// </param>
1070-
protected SafePeerData(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
1071-
1072899
/// <summary>
1073900
/// Marshals data from an unmanaged block of memory to a newly allocated managed object of the type specified by a generic type parameter.
1074901
/// </summary>
1075902
/// <typeparam name="T">The type of the object to which the data is to be copied. This must be a structure.</typeparam>
1076903
public T ToStructure<T>() where T : struct => handle.ToStructure<T>();
1077-
1078-
/// <inheritdoc/>
1079-
protected override bool InternalReleaseHandle() { PeerFreeData(handle); return true; }
1080904
}
1081905

1082906
/// <summary>Provides a <see cref="SafeHandle"/> for an array that is disposed using <see cref="PeerFreeData"/>.</summary>

PInvoke/P2P/P2P.Group.cs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,74 +2605,4 @@ public static SafePeerList<PEER_RECORD> PeerGroupSearchRecords(HGROUP hGroup, st
26052605
[DllImport(Lib_P2P, SetLastError = false, ExactSpelling = true)]
26062606
[PInvokeData("p2p.h", MSDNShortId = "NF:p2p.PeerGroupUpdateRecord")]
26072607
public static extern HRESULT PeerGroupUpdateRecord(HGROUP hGroup, in PEER_RECORD pRecord);
2608-
2609-
/// <summary>Provides a handle to a peer group.</summary>
2610-
[StructLayout(LayoutKind.Sequential)]
2611-
public struct HGROUP : IHandle
2612-
{
2613-
private IntPtr handle;
2614-
2615-
/// <summary>Initializes a new instance of the <see cref="HGROUP"/> struct.</summary>
2616-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
2617-
public HGROUP(IntPtr preexistingHandle) => handle = preexistingHandle;
2618-
2619-
/// <summary>Returns an invalid handle by instantiating a <see cref="HGROUP"/> object with <see cref="IntPtr.Zero"/>.</summary>
2620-
public static HGROUP NULL => new(IntPtr.Zero);
2621-
2622-
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
2623-
public bool IsNull => handle == IntPtr.Zero;
2624-
2625-
/// <summary>Performs an explicit conversion from <see cref="HGROUP"/> to <see cref="IntPtr"/>.</summary>
2626-
/// <param name="h">The handle.</param>
2627-
/// <returns>The result of the conversion.</returns>
2628-
public static explicit operator IntPtr(HGROUP h) => h.handle;
2629-
2630-
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HGROUP"/>.</summary>
2631-
/// <param name="h">The pointer to a handle.</param>
2632-
/// <returns>The result of the conversion.</returns>
2633-
public static implicit operator HGROUP(IntPtr h) => new(h);
2634-
2635-
/// <summary>Implements the operator !=.</summary>
2636-
/// <param name="h1">The first handle.</param>
2637-
/// <param name="h2">The second handle.</param>
2638-
/// <returns>The result of the operator.</returns>
2639-
public static bool operator !=(HGROUP h1, HGROUP h2) => !(h1 == h2);
2640-
2641-
/// <summary>Implements the operator ==.</summary>
2642-
/// <param name="h1">The first handle.</param>
2643-
/// <param name="h2">The second handle.</param>
2644-
/// <returns>The result of the operator.</returns>
2645-
public static bool operator ==(HGROUP h1, HGROUP h2) => h1.Equals(h2);
2646-
2647-
/// <inheritdoc/>
2648-
public override bool Equals(object? obj) => obj is HGROUP h && handle == h.handle;
2649-
2650-
/// <inheritdoc/>
2651-
public override int GetHashCode() => handle.GetHashCode();
2652-
2653-
/// <inheritdoc/>
2654-
public IntPtr DangerousGetHandle() => handle;
2655-
}
2656-
2657-
/// <summary>Provides a <see cref="SafeHandle"/> for <see cref="HPEEREVENT"/> that is disposed using <see cref="PeerGroupUnregisterEvent"/>.</summary>
2658-
public class SafeGroupHPEEREVENT : SafeHANDLE
2659-
{
2660-
/// <summary>Initializes a new instance of the <see cref="SafeGroupHPEEREVENT"/> class and assigns an existing handle.</summary>
2661-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
2662-
/// <param name="ownsHandle">
2663-
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
2664-
/// </param>
2665-
public SafeGroupHPEEREVENT(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
2666-
2667-
/// <summary>Initializes a new instance of the <see cref="SafeGroupHPEEREVENT"/> class.</summary>
2668-
private SafeGroupHPEEREVENT() : base() { }
2669-
2670-
/// <summary>Performs an implicit conversion from <see cref="SafeGroupHPEEREVENT"/> to <see cref="HPEEREVENT"/>.</summary>
2671-
/// <param name="h">The safe handle instance.</param>
2672-
/// <returns>The result of the conversion.</returns>
2673-
public static implicit operator HPEEREVENT(SafeGroupHPEEREVENT h) => h.handle;
2674-
2675-
/// <inheritdoc/>
2676-
protected override bool InternalReleaseHandle() => PeerGroupUnregisterEvent(handle).Succeeded;
2677-
}
26782608
}

0 commit comments

Comments
 (0)