Skip to content

Commit 63bf46b

Browse files
committed
Update packages and add some simple WIC component enumeration
1 parent f236f3a commit 63bf46b

File tree

12 files changed

+134
-11
lines changed

12 files changed

+134
-11
lines changed

src/thirtytwo/Application.cs

+2
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,7 @@ public static string GetUserDefaultLocaleName()
231231
public static Direct2dFactory Direct2dFactory => s_direct2dFactory ??= new();
232232
public static DirectWriteFactory DirectWriteFactory => s_directWriteFactory ??= new();
233233
public static DirectWriteGdiInterop DirectWriteGdiInterop => s_directWriteGdiInterop ??= new();
234+
235+
/// <inheritdoc cref="Windows.Win32.Graphics.Imaging.ImagingFactory"/>
234236
public static ImagingFactory ImagingFactory => s_imagingFactory ??= new();
235237
}

src/thirtytwo/Controls/ActiveXControl.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public ActiveXControl(
4040
_classId = classId;
4141
IUnknown* unknown = ComHelpers.CreateComClass(classId);
4242
_instance = new(unknown, takeOwnership: true);
43-
_instanceAsActiveObject = unknown->QueryAgileInterface<IOleInPlaceActiveObject>();
43+
_instanceAsActiveObject = unknown->TryQueryAgileInterface<IOleInPlaceActiveObject>();
4444

4545
using ComScope<IOleObject> oleObject = ComScope<IOleObject>.QueryFrom(unknown);
4646
if (oleObject.Pointer->GetMiscStatus(DVASPECT.DVASPECT_CONTENT, out OLEMISC status).Succeeded)

src/thirtytwo/NativeMethods.txt

+3
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,8 @@ IsWindowEnabled
248248
IsWindowVisible
249249
IUIAutomationElement
250250
IUnknown
251+
IWICBitmapDecoderInfo
252+
IWICComponentInfo
251253
IWICImagingFactory2
252254
KEY_INFORMATION_CLASS
253255
KEY_NAME_INFORMATION
@@ -386,6 +388,7 @@ UpdateWindow
386388
USER_DEFAULT_SCREEN_DPI
387389
VARIANT_*
388390
VIRTUAL_KEY
391+
WICComponentEnumerateOptions
389392
WIN32_ERROR
390393
WINDOWPOS
391394
WM_*

src/thirtytwo/Win32/Graphics/Imaging/BitmapDecoder.cs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
namespace Windows.Win32.Graphics.Imaging;
55

6+
/// <summary>
7+
/// WIC Bitmap Decoder.
8+
/// </summary>
69
public unsafe class BitmapDecoder : DirectDrawBase<IWICBitmapDecoder>
710
{
811
public BitmapDecoder(IWICBitmapDecoder* pointer) : base(pointer) { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (c) Jeremy W. Kuhne. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Windows.Win32.System.Com;
5+
6+
namespace Windows.Win32.Graphics.Imaging;
7+
8+
public unsafe class ComponentEnumerator : DirectDrawBase<IEnumUnknown>
9+
{
10+
public ComponentEnumerator(IEnumUnknown* pointer) : base(pointer) { }
11+
12+
public ComponentEnumerator(WICComponentType componentType)
13+
: base(CreateComponentEnumerator(Application.ImagingFactory, componentType))
14+
{
15+
}
16+
17+
public static IEnumUnknown* CreateComponentEnumerator(ImagingFactory factory, WICComponentType componentType)
18+
{
19+
IEnumUnknown* enumerator;
20+
factory.Pointer->CreateComponentEnumerator(
21+
(uint)componentType,
22+
(uint)WICComponentEnumerateOptions.WICComponentEnumerateDefault,
23+
&enumerator).ThrowOnFailure();
24+
25+
GC.KeepAlive(factory);
26+
return enumerator;
27+
}
28+
29+
public static implicit operator IEnumUnknown*(ComponentEnumerator d) => d.Pointer;
30+
31+
public bool Next([NotNullWhen(true)] out ComponentInfo? componentInfo)
32+
{
33+
componentInfo = null;
34+
IEnumUnknown* enumerator = this;
35+
if (enumerator is null)
36+
{
37+
return false;
38+
}
39+
40+
uint fetched;
41+
using ComScope<IUnknown> unknown = new(null);
42+
HRESULT result = enumerator->Next(1, unknown, &fetched);
43+
if (result != HRESULT.S_OK || fetched != 1)
44+
{
45+
return false;
46+
}
47+
48+
componentInfo = new(unknown.Pointer->QueryInterface<IWICComponentInfo>());
49+
return true;
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Jeremy W. Kuhne. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Windows.Win32.Graphics.Imaging;
5+
6+
public unsafe class ComponentInfo : DirectDrawBase<IWICComponentInfo>
7+
{
8+
public ComponentInfo(IWICComponentInfo* pointer) : base(pointer) { }
9+
10+
public ComponentInfo(Guid componentClassId)
11+
: base(CreateComponentInfo(Application.ImagingFactory, componentClassId))
12+
{
13+
}
14+
15+
public static IWICComponentInfo* CreateComponentInfo(ImagingFactory factory, Guid componentClassId)
16+
{
17+
IWICComponentInfo* info;
18+
factory.Pointer->CreateComponentInfo(&componentClassId, &info).ThrowOnFailure();
19+
GC.KeepAlive(factory);
20+
return info;
21+
}
22+
23+
public string FriendlyName
24+
{
25+
get
26+
{
27+
uint length;
28+
Pointer->GetFriendlyName(0, null, &length).ThrowOnFailure();
29+
char* name = stackalloc char[(int)length];
30+
Pointer->GetFriendlyName(length, name, &length).ThrowOnFailure();
31+
return new string(name);
32+
}
33+
}
34+
35+
public static implicit operator IWICComponentInfo*(ComponentInfo d) => d.Pointer;
36+
}

src/thirtytwo/Win32/Graphics/Imaging/ImagingFactory.cs

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Windows.Win32.Graphics.Imaging;
88

9+
/// <summary>
10+
/// WIC Imaging Factory.
11+
/// </summary>
912
public unsafe class ImagingFactory : DirectDrawBase<IWICImagingFactory2>
1013
{
1114
public ImagingFactory() : base(Create()) { }

src/thirtytwo/Win32/System/Com/IUnknown.cs

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@ namespace Windows.Win32.System.Com;
99

1010
public unsafe partial struct IUnknown : IVTable<IUnknown, IUnknown.Vtbl>
1111
{
12-
public TInterface* QueryInterface<TInterface>() where TInterface : unmanaged, IComIID
12+
public TInterface* TryQueryInterface<TInterface>() where TInterface : unmanaged, IComIID
1313
{
1414
TInterface* @interface = default;
1515
QueryInterface(IID.Get<TInterface>(), (void**)&@interface);
1616
return @interface;
1717
}
1818

19-
public AgileComPointer<TInterface>? QueryAgileInterface<TInterface>()
19+
public TInterface* QueryInterface<TInterface>() where TInterface : unmanaged, IComIID
20+
{
21+
TInterface* @interface = default;
22+
QueryInterface(IID.Get<TInterface>(), (void**)&@interface).ThrowOnFailure();
23+
return @interface;
24+
}
25+
26+
public AgileComPointer<TInterface>? TryQueryAgileInterface<TInterface>()
2027
where TInterface : unmanaged, IComIID
2128
{
22-
TInterface* @interface = QueryInterface<TInterface>();
29+
TInterface* @interface = TryQueryInterface<TInterface>();
2330
return @interface is null ? null : new(@interface, takeOwnership: true);
2431
}
2532

src/thirtytwo/thirtytwo.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.85-beta">
16+
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106">
1717
<PrivateAssets>all</PrivateAssets>
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
</PackageReference>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) Jeremy W. Kuhne. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
namespace Windows.Win32.Graphics.Imaging;
5+
6+
public class ComponentInfoTests
7+
{
8+
[Fact]
9+
public void EnumerateDecoders()
10+
{
11+
ComponentEnumerator enumerator = new(WICComponentType.WICDecoder);
12+
while (enumerator.Next(out ComponentInfo? info))
13+
{
14+
Assert.NotNull(info);
15+
Assert.NotNull(info.FriendlyName);
16+
}
17+
}
18+
}

src/thirtytwo_tests/Win32/System/Com/StandardDispatchTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void StandardDispatch_ImplDoesNotProvideEx()
3838
&standard).ThrowOnFailure();
3939

4040
// StdDispatch does not provide an implementation of IDispatchEx.
41-
IDispatchEx* dispatchEx = standard->QueryInterface<IDispatchEx>();
41+
IDispatchEx* dispatchEx = standard->TryQueryInterface<IDispatchEx>();
4242
Assert.True(dispatchEx is null);
4343

4444
standard->Release();

src/thirtytwo_tests/thirtytwo_tests.csproj

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="FluentAssertions" Version="6.8.0" />
13-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
14-
<PackageReference Include="xunit" Version="2.4.2" />
15-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
12+
<PackageReference Include="FluentAssertions" Version="6.12.0" />
13+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
14+
<PackageReference Include="xunit" Version="2.9.0" />
15+
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
<PrivateAssets>all</PrivateAssets>
1818
</PackageReference>
19-
<PackageReference Include="coverlet.collector" Version="3.2.0">
19+
<PackageReference Include="coverlet.collector" Version="6.0.2">
2020
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2121
<PrivateAssets>all</PrivateAssets>
2222
</PackageReference>

0 commit comments

Comments
 (0)