Skip to content

Commit 77ae66f

Browse files
authored
Merge pull request #1111 from microsoft/fix275
Offer SafeHandle overloads of methods with HGDIOBJ parameters
2 parents e54bb73 + a71ff04 commit 77ae66f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Microsoft.Windows.CsWin32/MetadataIndex.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ void PopulateNamespace(NamespaceDefinition ns, string? parentNamespace)
175175
}
176176
}
177177
}
178+
else if (this.MetadataName == "Windows.Win32" && typeName == "HGDIOBJ")
179+
{
180+
// This "base type" struct doesn't have an RAIIFree attribute,
181+
// but methods that take an HGDIOBJ parameter are expected to offer SafeHandle friendly overloads.
182+
this.handleTypeReleaseMethod.Add(tdh, "DeleteObject");
183+
}
178184
}
179185
}
180186
}

test/Microsoft.Windows.CsWin32.Tests/HandleTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ public void HandleTypeDefsUseIntPtrAsFieldType(string handleType)
128128
Assert.Equal(nameof(IntPtr), Assert.IsType<IdentifierNameSyntax>(field.Declaration.Type).Identifier.ValueText);
129129
}
130130

131+
[Fact]
132+
public void SafeHandleOverloadsGeneratedFor_HGDIObj()
133+
{
134+
this.GenerateApi("GetObject");
135+
Assert.Contains(
136+
this.FindGeneratedMethod("GetObject"),
137+
method => method!.ParameterList.Parameters[0].Type is IdentifierNameSyntax { Identifier: { ValueText: "SafeHandle" } });
138+
}
139+
131140
[Fact]
132141
public void ReleaseMethodGeneratedWithHandleStruct()
133142
{

0 commit comments

Comments
 (0)