Skip to content

Commit f189b79

Browse files
author
dahall
committed
Completed autogen handle updates
1 parent 9cf553d commit f189b79

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+127
-2078
lines changed

CodeGen/SafeHandleTemplate.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#1#public static partial class ParentClassName
44
{
55
#1# SummaryText
6+
/// <seealso cref="BaseClassName"/>
67
public partial class ClassName : BaseClassName
78
{
89
/// <summary>Initializes a new instance of the <see cref="ClassName"/> class and assigns an existing handle.</summary>

PInvoke/IpHlpApi/IpHlpApi.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9694,7 +9694,6 @@ private static TRet GetTable<TRet>(FunctionHelper.PtrFunc<uint> func, Func<uint,
96949694
}
96959695

96969696
/// <summary>Provides a handle to a notification registration for a timestamp capability change.</summary>
9697-
[StructLayout(LayoutKind.Sequential)]
96989697
[AutoHandle]
96999698
public partial struct HIFTIMESTAMPCHANGE { }
97009699

PInvoke/ShlwApi/Shlwapi.cs

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -5847,54 +5847,6 @@ public static extern Win32Error SHRegQueryUSValue(HUSKEY hUSKey, string pszValue
58475847
[PInvokeData("shlwapi.h", MSDNShortId = "14af733b-81b4-40a2-b93b-6f387b181f12")]
58485848
public static extern SHELLPLATFORM WhichPlatform();
58495849

5850-
/// <summary>Provides a handle to a user specific registry key.</summary>
5851-
[StructLayout(LayoutKind.Sequential)]
5852-
public struct HUSKEY : IHandle
5853-
{
5854-
private readonly IntPtr handle;
5855-
5856-
/// <summary>Initializes a new instance of the <see cref="HUSKEY"/> struct.</summary>
5857-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
5858-
public HUSKEY(IntPtr preexistingHandle) => handle = preexistingHandle;
5859-
5860-
/// <summary>Returns an invalid handle by instantiating a <see cref="HUSKEY"/> object with <see cref="IntPtr.Zero"/>.</summary>
5861-
public static HUSKEY NULL => new(IntPtr.Zero);
5862-
5863-
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
5864-
public readonly bool IsNull => handle == IntPtr.Zero;
5865-
5866-
/// <summary>Performs an explicit conversion from <see cref="HUSKEY"/> to <see cref="IntPtr"/>.</summary>
5867-
/// <param name="h">The handle.</param>
5868-
/// <returns>The result of the conversion.</returns>
5869-
public static explicit operator IntPtr(HUSKEY h) => h.handle;
5870-
5871-
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HUSKEY"/>.</summary>
5872-
/// <param name="h">The pointer to a handle.</param>
5873-
/// <returns>The result of the conversion.</returns>
5874-
public static implicit operator HUSKEY(IntPtr h) => new(h);
5875-
5876-
/// <summary>Implements the operator !=.</summary>
5877-
/// <param name="h1">The first handle.</param>
5878-
/// <param name="h2">The second handle.</param>
5879-
/// <returns>The result of the operator.</returns>
5880-
public static bool operator !=(HUSKEY h1, HUSKEY h2) => !(h1 == h2);
5881-
5882-
/// <summary>Implements the operator ==.</summary>
5883-
/// <param name="h1">The first handle.</param>
5884-
/// <param name="h2">The second handle.</param>
5885-
/// <returns>The result of the operator.</returns>
5886-
public static bool operator ==(HUSKEY h1, HUSKEY h2) => h1.Equals(h2);
5887-
5888-
/// <inheritdoc/>
5889-
public override readonly bool Equals(object? obj) => obj is HUSKEY h && handle == h.handle;
5890-
5891-
/// <inheritdoc/>
5892-
public override int GetHashCode() => handle.GetHashCode();
5893-
5894-
/// <inheritdoc/>
5895-
public readonly IntPtr DangerousGetHandle() => handle;
5896-
}
5897-
58985850
/// <summary>
58995851
/// <para>Used by the QISearch function to describe a single interface.</para>
59005852
/// </summary>
@@ -5926,26 +5878,4 @@ public struct QITAB
59265878
/// </summary>
59275879
public uint dwOffset;
59285880
}
5929-
5930-
/// <summary>Provides a <see cref="SafeHandle"/> for <see cref="HUSKEY"/> that is disposed using <see cref="SHRegCloseUSKey"/>.</summary>
5931-
public class SafeHUSKEY : SafeHANDLE
5932-
{
5933-
/// <summary>Initializes a new instance of the <see cref="SafeHUSKEY"/> class and assigns an existing handle.</summary>
5934-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
5935-
/// <param name="ownsHandle">
5936-
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
5937-
/// </param>
5938-
public SafeHUSKEY(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
5939-
5940-
/// <summary>Initializes a new instance of the <see cref="SafeHUSKEY"/> class.</summary>
5941-
private SafeHUSKEY() : base() { }
5942-
5943-
/// <summary>Performs an implicit conversion from <see cref="SafeHUSKEY"/> to <see cref="HUSKEY"/>.</summary>
5944-
/// <param name="h">The safe handle instance.</param>
5945-
/// <returns>The result of the conversion.</returns>
5946-
public static implicit operator HUSKEY(SafeHUSKEY h) => h.handle;
5947-
5948-
/// <inheritdoc/>
5949-
protected override bool InternalReleaseHandle() => SHRegCloseUSKey(this).Succeeded;
5950-
}
59515881
}

PInvoke/ShlwApi/Vanara.PInvoke.ShlwApi.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ IQueryAssociations
2323
</PackageReleaseNotes>
2424
<PackageReadmeFile>pkgreadme.md</PackageReadmeFile>
2525
</PropertyGroup>
26+
<ItemGroup>
27+
<AdditionalFiles Include="handles.csv" />
28+
</ItemGroup>
2629
<ItemGroup>
2730
<ProjectReference Include="..\Kernel32\Vanara.PInvoke.Kernel32.csproj" />
2831
</ItemGroup>

PInvoke/ShlwApi/handles.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Namespace,ParentClassName,HandleName,InterfaceName,SummaryText,ClassName,BaseClassName,CloseCode,InheritedHandleName
2+
Vanara.PInvoke,ShlwApi,HUSKEY,IHandle,Provides a handle to a user specific registry key.,SafeHUSKEY,SafeHANDLE,SHRegCloseUSKey(this).Succeeded,

PInvoke/UserEnv/UserEnv.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,23 +1619,8 @@ public PROFILEINFO(string? userName, bool allowUI = true)
16191619
}
16201620

16211621
/// <summary>Provides a <see cref="SafeHandle"/> for <see cref="EnterCriticalPolicySection"/> that is disposed using <see cref="LeaveCriticalPolicySection"/>.</summary>
1622-
public class SafeCriticalPolicySectionHandle : SafeHANDLE
1623-
{
1624-
/// <summary>
1625-
/// Initializes a new instance of the <see cref="SafeCriticalPolicySectionHandle"/> class and assigns an existing handle.
1626-
/// </summary>
1627-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
1628-
/// <param name="ownsHandle">
1629-
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
1630-
/// </param>
1631-
public SafeCriticalPolicySectionHandle(IntPtr preexistingHandle, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) { }
1632-
1633-
/// <summary>Initializes a new instance of the <see cref="SafeCriticalPolicySectionHandle"/> class.</summary>
1634-
private SafeCriticalPolicySectionHandle() : base() { }
1635-
1636-
/// <inheritdoc/>
1637-
protected override bool InternalReleaseHandle() => LeaveCriticalPolicySection(handle);
1638-
}
1622+
[AutoSafeHandle("LeaveCriticalPolicySection(handle)")]
1623+
public partial class SafeCriticalPolicySectionHandle { }
16391624

16401625
private class EnvBlockMarshaler : ICustomMarshaler
16411626
{

PInvoke/UxTheme/UXTHEME.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3745,23 +3745,6 @@ public RECT? ClipRectangle
37453745
}
37463746

37473747
/// <summary>Represents a safe handle for a theme. Use in place of HTHEME.</summary>
3748-
public class SafeHTHEME : SafeHANDLE
3749-
{
3750-
/// <summary>Initializes a new instance of the <see cref="SafeHTHEME"/> class.</summary>
3751-
/// <param name="hTheme">The h theme.</param>
3752-
/// <param name="ownsHandle">if set to <c>true</c> [owns handle].</param>
3753-
public SafeHTHEME(IntPtr hTheme, bool ownsHandle = true) : base(hTheme, ownsHandle) { }
3754-
3755-
private SafeHTHEME() : base()
3756-
{
3757-
}
3758-
3759-
/// <summary>Performs an implicit conversion from <see cref="SafeHTHEME"/> to <see cref="HTHEME"/>.</summary>
3760-
/// <param name="h">The safe handle instance.</param>
3761-
/// <returns>The result of the conversion.</returns>
3762-
public static implicit operator HTHEME(SafeHTHEME h) => h.handle;
3763-
3764-
/// <inheritdoc/>
3765-
protected override bool InternalReleaseHandle() => CloseThemeData(this).Succeeded;
3766-
}
3748+
[AutoSafeHandle("CloseThemeData(this).Succeeded", typeof(HTHEME))]
3749+
public partial class SafeHTHEME { }
37673750
}

PInvoke/UxTheme/UXTHEME_BufferedPaint.cs

Lines changed: 16 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -474,102 +474,6 @@ public BP_ANIMATIONPARAMS(BP_ANIMATIONSTYLE animStyle, int dur = 0)
474474
public static BP_ANIMATIONPARAMS Empty => new() { cbSize = (uint)Marshal.SizeOf(typeof(BP_ANIMATIONPARAMS)) };
475475
}
476476

477-
/// <summary>Provides a handle to an animation buffer.</summary>
478-
[StructLayout(LayoutKind.Sequential)]
479-
public struct HANIMATIONBUFFER : IHandle
480-
{
481-
private IntPtr handle;
482-
483-
/// <summary>Initializes a new instance of the <see cref="HANIMATIONBUFFER"/> struct.</summary>
484-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
485-
public HANIMATIONBUFFER(IntPtr preexistingHandle) => handle = preexistingHandle;
486-
487-
/// <summary>Returns an invalid handle by instantiating a <see cref="HANIMATIONBUFFER"/> object with <see cref="IntPtr.Zero"/>.</summary>
488-
public static HANIMATIONBUFFER NULL => new(IntPtr.Zero);
489-
490-
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
491-
public bool IsNull => handle == IntPtr.Zero;
492-
493-
/// <summary>Performs an explicit conversion from <see cref="HANIMATIONBUFFER"/> to <see cref="IntPtr"/>.</summary>
494-
/// <param name="h">The handle.</param>
495-
/// <returns>The result of the conversion.</returns>
496-
public static explicit operator IntPtr(HANIMATIONBUFFER h) => h.handle;
497-
498-
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HANIMATIONBUFFER"/>.</summary>
499-
/// <param name="h">The pointer to a handle.</param>
500-
/// <returns>The result of the conversion.</returns>
501-
public static implicit operator HANIMATIONBUFFER(IntPtr h) => new(h);
502-
503-
/// <summary>Implements the operator !=.</summary>
504-
/// <param name="h1">The first handle.</param>
505-
/// <param name="h2">The second handle.</param>
506-
/// <returns>The result of the operator.</returns>
507-
public static bool operator !=(HANIMATIONBUFFER h1, HANIMATIONBUFFER h2) => !(h1 == h2);
508-
509-
/// <summary>Implements the operator ==.</summary>
510-
/// <param name="h1">The first handle.</param>
511-
/// <param name="h2">The second handle.</param>
512-
/// <returns>The result of the operator.</returns>
513-
public static bool operator ==(HANIMATIONBUFFER h1, HANIMATIONBUFFER h2) => h1.Equals(h2);
514-
515-
/// <inheritdoc/>
516-
public override bool Equals(object? obj) => obj is HANIMATIONBUFFER h && handle == h.handle;
517-
518-
/// <inheritdoc/>
519-
public override int GetHashCode() => handle.GetHashCode();
520-
521-
/// <inheritdoc/>
522-
public IntPtr DangerousGetHandle() => handle;
523-
}
524-
525-
/// <summary>Provides a handle to a paint buffer.</summary>
526-
[StructLayout(LayoutKind.Sequential)]
527-
public struct HPAINTBUFFER : IHandle
528-
{
529-
private IntPtr handle;
530-
531-
/// <summary>Initializes a new instance of the <see cref="HPAINTBUFFER"/> struct.</summary>
532-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
533-
public HPAINTBUFFER(IntPtr preexistingHandle) => handle = preexistingHandle;
534-
535-
/// <summary>Returns an invalid handle by instantiating a <see cref="HPAINTBUFFER"/> object with <see cref="IntPtr.Zero"/>.</summary>
536-
public static HPAINTBUFFER NULL => new(IntPtr.Zero);
537-
538-
/// <summary>Gets a value indicating whether this instance is a null handle.</summary>
539-
public bool IsNull => handle == IntPtr.Zero;
540-
541-
/// <summary>Performs an explicit conversion from <see cref="HPAINTBUFFER"/> to <see cref="IntPtr"/>.</summary>
542-
/// <param name="h">The handle.</param>
543-
/// <returns>The result of the conversion.</returns>
544-
public static explicit operator IntPtr(HPAINTBUFFER h) => h.handle;
545-
546-
/// <summary>Performs an implicit conversion from <see cref="IntPtr"/> to <see cref="HPAINTBUFFER"/>.</summary>
547-
/// <param name="h">The pointer to a handle.</param>
548-
/// <returns>The result of the conversion.</returns>
549-
public static implicit operator HPAINTBUFFER(IntPtr h) => new(h);
550-
551-
/// <summary>Implements the operator !=.</summary>
552-
/// <param name="h1">The first handle.</param>
553-
/// <param name="h2">The second handle.</param>
554-
/// <returns>The result of the operator.</returns>
555-
public static bool operator !=(HPAINTBUFFER h1, HPAINTBUFFER h2) => !(h1 == h2);
556-
557-
/// <summary>Implements the operator ==.</summary>
558-
/// <param name="h1">The first handle.</param>
559-
/// <param name="h2">The second handle.</param>
560-
/// <returns>The result of the operator.</returns>
561-
public static bool operator ==(HPAINTBUFFER h1, HPAINTBUFFER h2) => h1.Equals(h2);
562-
563-
/// <inheritdoc/>
564-
public override bool Equals(object? obj) => obj is HPAINTBUFFER h && handle == h.handle;
565-
566-
/// <inheritdoc/>
567-
public override int GetHashCode() => handle.GetHashCode();
568-
569-
/// <inheritdoc/>
570-
public IntPtr DangerousGetHandle() => handle;
571-
}
572-
573477
/// <summary>Defines paint operation parameters for <c>BeginBufferedPaint</c>.</summary>
574478
// typedef struct _BP_PAINTPARAMS { DWORD cbSize; DWORD dwFlags; const RECT *prcExclude; const BLENDFUNCTION *pBlendFunction;}
575479
// BP_PAINTPARAMS, *PBP_PAINTPARAMS; https://msdn.microsoft.com/en-us/library/windows/desktop/bb773228(v=vs.85).aspx
@@ -665,52 +569,38 @@ public class BufferedPaintBlock : IDisposable
665569
}
666570

667571
/// <summary>Provides a <see cref="SafeHandle"/> for <see cref="HANIMATIONBUFFER"/> that is disposed using <see cref="EndBufferedAnimation"/>.</summary>
668-
public class SafeHANIMATIONBUFFER : SafeHANDLE
572+
/// <remarks>Initializes a new instance of the <see cref="SafeHANIMATIONBUFFER"/> class and assigns an existing handle.</remarks>
573+
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
574+
/// <param name="updateTargetDC">The value to pass <see cref="EndBufferedAnimation"/> when closing this handle.</param>
575+
/// <param name="ownsHandle">
576+
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
577+
/// </param>
578+
public class SafeHANIMATIONBUFFER(IntPtr preexistingHandle, bool updateTargetDC = true, bool ownsHandle = true) : SafeHANDLE(preexistingHandle, ownsHandle)
669579
{
670-
private readonly bool fUpdateTarget = true;
671-
672-
/// <summary>Initializes a new instance of the <see cref="SafeHANIMATIONBUFFER"/> class and assigns an existing handle.</summary>
673-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
674-
/// <param name="updateTargetDC">The value to pass <see cref="EndBufferedAnimation"/> when closing this handle.</param>
675-
/// <param name="ownsHandle">
676-
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
677-
/// </param>
678-
public SafeHANIMATIONBUFFER(IntPtr preexistingHandle, bool updateTargetDC = true, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) => fUpdateTarget = updateTargetDC;
679-
680-
/// <summary>Initializes a new instance of the <see cref="SafeHANIMATIONBUFFER"/> class.</summary>
681-
private SafeHANIMATIONBUFFER() : base() { }
682-
683580
/// <summary>Performs an implicit conversion from <see cref="SafeHANIMATIONBUFFER"/> to <see cref="HANIMATIONBUFFER"/>.</summary>
684581
/// <param name="h">The safe handle instance.</param>
685582
/// <returns>The result of the conversion.</returns>
686583
public static implicit operator HANIMATIONBUFFER(SafeHANIMATIONBUFFER h) => h.handle;
687584

688585
/// <inheritdoc/>
689-
protected override bool InternalReleaseHandle() => EndBufferedAnimation(this, fUpdateTarget).Succeeded;
586+
protected override bool InternalReleaseHandle() => EndBufferedAnimation(this, updateTargetDC).Succeeded;
690587
}
691588

692589
/// <summary>Provides a <see cref="SafeHandle"/> for <see cref="HPAINTBUFFER"/> that is disposed using <see cref="EndBufferedPaint"/>.</summary>
693-
public class SafeHPAINTBUFFER : SafeHANDLE
590+
/// <remarks>Initializes a new instance of the <see cref="SafeHPAINTBUFFER"/> class and assigns an existing handle.</remarks>
591+
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
592+
/// <param name="updateTargetDC">The value to pass <see cref="EndBufferedPaint"/> when closing this handle.</param>
593+
/// <param name="ownsHandle">
594+
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
595+
/// </param>
596+
public class SafeHPAINTBUFFER(IntPtr preexistingHandle, bool updateTargetDC = true, bool ownsHandle = true) : SafeHANDLE(preexistingHandle, ownsHandle)
694597
{
695-
private readonly bool fUpdateTarget = true;
696-
697-
/// <summary>Initializes a new instance of the <see cref="SafeHPAINTBUFFER"/> class and assigns an existing handle.</summary>
698-
/// <param name="preexistingHandle">An <see cref="IntPtr"/> object that represents the pre-existing handle to use.</param>
699-
/// <param name="updateTargetDC">The value to pass <see cref="EndBufferedPaint"/> when closing this handle.</param>
700-
/// <param name="ownsHandle">
701-
/// <see langword="true"/> to reliably release the handle during the finalization phase; otherwise, <see langword="false"/> (not recommended).
702-
/// </param>
703-
public SafeHPAINTBUFFER(IntPtr preexistingHandle, bool updateTargetDC = true, bool ownsHandle = true) : base(preexistingHandle, ownsHandle) => fUpdateTarget = updateTargetDC;
704-
705-
/// <summary>Initializes a new instance of the <see cref="SafeHPAINTBUFFER"/> class.</summary>
706-
private SafeHPAINTBUFFER() : base() { }
707-
708598
/// <summary>Performs an implicit conversion from <see cref="SafeHPAINTBUFFER"/> to <see cref="HPAINTBUFFER"/>.</summary>
709599
/// <param name="h">The safe handle instance.</param>
710600
/// <returns>The result of the conversion.</returns>
711601
public static implicit operator HPAINTBUFFER(SafeHPAINTBUFFER h) => h.handle;
712602

713603
/// <inheritdoc/>
714-
protected override bool InternalReleaseHandle() => EndBufferedPaint(this, fUpdateTarget).Succeeded;
604+
protected override bool InternalReleaseHandle() => EndBufferedPaint(this, updateTargetDC).Succeeded;
715605
}
716606
}

PInvoke/UxTheme/Vanara.PInvoke.UxTheme.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ BP_ANIMATIONPARAMS BP_PAINTPARAMS DTBGOPTS DTTOPTS HANIMATIONBUFFER HPAINTBUFFER
2020
</PackageReleaseNotes>
2121
<PackageReadmeFile>pkgreadme.md</PackageReadmeFile>
2222
</PropertyGroup>
23+
<ItemGroup>
24+
<AdditionalFiles Include="handles.csv" />
25+
</ItemGroup>
2326
<ItemGroup>
2427
<ProjectReference Include="..\User32\Vanara.PInvoke.User32.csproj" />
2528
</ItemGroup>

PInvoke/UxTheme/handles.csv

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Namespace,ParentClassName,HandleName,InterfaceName,SummaryText,ClassName,BaseClassName,CloseCode,InheritedHandleName
2+
Vanara.PInvoke,UxTheme,HANIMATIONBUFFER,IHandle,Provides a handle to an animation buffer.,,,,
3+
Vanara.PInvoke,UxTheme,HPAINTBUFFER,IHandle,Provides a handle to a paint buffer.,,,,

0 commit comments

Comments
 (0)