From 74f7ad41db0015f3b63a7dec4e4f8838b8637da1 Mon Sep 17 00:00:00 2001 From: Jeremy Kuhne Date: Wed, 7 Feb 2024 16:32:55 -0800 Subject: [PATCH] Refactor DirectDraw classes DirectDraw's objects can be accessed from any thread. Change ComScope.Value to .Pointer --- .editorconfig | 3 + src/thirtytwo/Application.cs | 2 + .../ActiveXControl.ConnectionPoint.cs | 4 +- src/thirtytwo/Controls/ActiveXControl.Site.cs | 4 +- src/thirtytwo/Controls/ActiveXControl.cs | 12 +-- src/thirtytwo/Dialogs/FileDialog.cs | 30 +++---- src/thirtytwo/Dialogs/FileOpenDialog.cs | 8 +- src/thirtytwo/Support/Error.cs | 4 +- src/thirtytwo/Win32/ComHelpers.cs | 10 +-- .../Win32/Graphics/Direct2D/Brush.cs | 10 +-- .../Graphics/Direct2D/Direct2dFactory.cs | 37 ++++----- .../Graphics/Direct2D/HwndRenderTarget.cs | 9 +-- .../Win32/Graphics/Direct2D/RenderTarget.cs | 10 +-- .../Win32/Graphics/Direct2D/Resource.cs | 24 +----- .../Graphics/Direct2D/SolidColorBrush.cs | 10 +-- .../Win32/Graphics/DirectDrawBase.cs | 28 +++++++ .../DirectWrite/DirectWriteFactory.cs | 30 ++----- .../DirectWrite/DirectWriteGdiInterop.cs | 26 +++++++ .../Win32/Graphics/DirectWrite/TextFormat.cs | 26 +------ .../Win32/Graphics/DirectWrite/TextLayout.cs | 37 ++------- .../Win32/Graphics/DirectWrite/Typography.cs | 25 +----- .../Win32/System/Com/AgileComPointer.cs | 6 ++ .../Win32/System/Com/ComPropertyDescriptor.cs | 4 +- src/thirtytwo/Win32/System/Com/ComScope{T}.cs | 6 +- .../Win32/System/Com/ComTypeDescriptor.cs | 24 +++--- .../Win32/System/Com/DispatchExAdapter.cs | 14 ++-- .../Win32/System/Com/ComTests.cs | 4 +- .../Com/ComponentCategoriesManagerTests.cs | 8 +- .../Win32/System/Com/IReflectTests.cs | 78 +++++++++---------- .../Com/ReflectPropertiesDispatchTests.cs | 20 ++--- .../Win32/System/Com/StandardDispatchTests.cs | 20 ++--- .../Win32/System/Com/VariantTests.cs | 2 +- .../Win32/System/Ole/LoadRegTypeLibTests.cs | 2 +- .../UI/Accessibility/AccessibleBaseTests.cs | 2 +- .../CreateStdAccessibleObjectTests.cs | 20 ++--- .../CreateStdAccessibleProxyTests.cs | 10 +-- .../UiaProviderForNonClientTests.cs | 2 +- 37 files changed, 255 insertions(+), 316 deletions(-) create mode 100644 src/thirtytwo/Win32/Graphics/DirectDrawBase.cs create mode 100644 src/thirtytwo/Win32/Graphics/DirectWrite/DirectWriteGdiInterop.cs diff --git a/.editorconfig b/.editorconfig index 6b1912f..2b7e98d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -405,6 +405,9 @@ dotnet_diagnostic.SYSLIB1096.severity = none # SA1117: Parameters should be on same line or separate lines dotnet_diagnostic.SA1117.severity = silent +# SA1627: Documentation text should not be empty +dotnet_diagnostic.SA1627.severity = silent + [*.{cs,vb}] dotnet_style_coalesce_expression = true:suggestion dotnet_style_null_propagation = true:silent diff --git a/src/thirtytwo/Application.cs b/src/thirtytwo/Application.cs index e18c500..6a12a18 100644 --- a/src/thirtytwo/Application.cs +++ b/src/thirtytwo/Application.cs @@ -14,6 +14,7 @@ public static unsafe class Application private static ActivationContext? s_visualStylesContext; private static Direct2dFactory? s_direct2dFactory; private static DirectWriteFactory? s_directWriteFactory; + private static DirectWriteGdiInterop? s_directWriteGdiInterop; internal static ActivationScope ThemingScope => new(GetStylesContext()); @@ -211,4 +212,5 @@ public static void EnumerateThreadWindows( public static Direct2dFactory Direct2dFactory => s_direct2dFactory ??= new(); public static DirectWriteFactory DirectWriteFactory => s_directWriteFactory ??= new(); + public static DirectWriteGdiInterop DirectWriteGdiInterop => s_directWriteGdiInterop ??= new(); } \ No newline at end of file diff --git a/src/thirtytwo/Controls/ActiveXControl.ConnectionPoint.cs b/src/thirtytwo/Controls/ActiveXControl.ConnectionPoint.cs index 1f78de0..4247851 100644 --- a/src/thirtytwo/Controls/ActiveXControl.ConnectionPoint.cs +++ b/src/thirtytwo/Controls/ActiveXControl.ConnectionPoint.cs @@ -21,7 +21,7 @@ public ConnectionPoint(AgileComPointer control, IManagedWrapper sink) } IConnectionPoint* connectionPoint; - if (container.Value->FindConnectionPoint(IID.Get(), &connectionPoint).Failed) + if (container.Pointer->FindConnectionPoint(IID.Get(), &connectionPoint).Failed) { return; } @@ -60,7 +60,7 @@ protected override void Dispose(bool disposing) using var connectionPoint = TryGetInterface(out HRESULT hr); if (hr.Succeeded) { - hr = connectionPoint.Value->Unadvise(_cookie); + hr = connectionPoint.Pointer->Unadvise(_cookie); } } diff --git a/src/thirtytwo/Controls/ActiveXControl.Site.cs b/src/thirtytwo/Controls/ActiveXControl.Site.cs index 38e9d09..a37a3d4 100644 --- a/src/thirtytwo/Controls/ActiveXControl.Site.cs +++ b/src/thirtytwo/Controls/ActiveXControl.Site.cs @@ -189,7 +189,7 @@ HRESULT IOleInPlaceSite.Interface.OnInPlaceDeactivate() HRESULT IOleInPlaceSite.Interface.DeactivateAndUndo() { using var inPlace = _control._instance.GetInterface(); - return inPlace.Value->UIDeactivate(); + return inPlace.Pointer->UIDeactivate(); } HRESULT IOleInPlaceSite.Interface.OnPosRectChange(RECT* lprcPosRect) @@ -201,7 +201,7 @@ HRESULT IOleInPlaceSite.Interface.OnPosRectChange(RECT* lprcPosRect) using var inPlace = _control._instance.GetInterface(); RECT clipRect = new(int.MinValue, int.MinValue, int.MaxValue, int.MaxValue); - HRESULT hr = inPlace.Value->SetObjectRects(lprcPosRect, &clipRect); + HRESULT hr = inPlace.Pointer->SetObjectRects(lprcPosRect, &clipRect); return HRESULT.S_OK; } diff --git a/src/thirtytwo/Controls/ActiveXControl.cs b/src/thirtytwo/Controls/ActiveXControl.cs index b211efc..08e3fb0 100644 --- a/src/thirtytwo/Controls/ActiveXControl.cs +++ b/src/thirtytwo/Controls/ActiveXControl.cs @@ -43,7 +43,7 @@ public ActiveXControl( _instanceAsActiveObject = unknown->QueryAgileInterface(); using ComScope oleObject = ComScope.QueryFrom(unknown); - if (oleObject.Value->GetMiscStatus(DVASPECT.DVASPECT_CONTENT, out OLEMISC status).Succeeded) + if (oleObject.Pointer->GetMiscStatus(DVASPECT.DVASPECT_CONTENT, out OLEMISC status).Succeeded) { _status = status; } @@ -53,7 +53,7 @@ public ActiveXControl( _site = new Site(this); IOleClientSite* site = ComHelpers.GetComPointer(_site); - HRESULT hr = oleObject.Value->SetClientSite(site); + HRESULT hr = oleObject.Pointer->SetClientSite(site); _typeDescriptor = new ComTypeDescriptor(_instance); } @@ -70,7 +70,7 @@ protected internal override bool PreProcessMessage(ref MSG message) using var scope = activeObject.GetInterface(); fixed (MSG* msg = &message) { - if (scope.Value->TranslateAccelerator(msg) == HRESULT.S_OK) + if (scope.Pointer->TranslateAccelerator(msg) == HRESULT.S_OK) { return true; } @@ -94,7 +94,7 @@ private void DoVerb(OLEIVERB verb, Rectangle bounds) RECT rect = bounds; IOleClientSite* clientSite = ComHelpers.GetComPointer(_site); - HRESULT hr = oleObject.Value->DoVerb( + HRESULT hr = oleObject.Pointer->DoVerb( iVerb: (int)verb, lpmsg: (MSG*)null, pActiveSite: clientSite, @@ -147,7 +147,7 @@ void PositionChanged() { // Not specifically called out in the SetExtent docs, but OLE defaults are HIMETRic Size size = PixelToHiMetric(this.GetClientRectangle().Size); - oleObject.Value->SetExtent(DVASPECT.DVASPECT_CONTENT, (SIZE*)&size); + oleObject.Pointer->SetExtent(DVASPECT.DVASPECT_CONTENT, (SIZE*)&size); } } @@ -157,7 +157,7 @@ void PositionChanged() if (hr.Succeeded) { RECT rect = boundsInParent; - inPlaceObject.Value->SetObjectRects(&rect, &rect); + inPlaceObject.Pointer->SetObjectRects(&rect, &rect); } } diff --git a/src/thirtytwo/Dialogs/FileDialog.cs b/src/thirtytwo/Dialogs/FileDialog.cs index 2ab59a4..e89937d 100644 --- a/src/thirtytwo/Dialogs/FileDialog.cs +++ b/src/thirtytwo/Dialogs/FileDialog.cs @@ -37,7 +37,7 @@ public HWND Handle if (_hwnd.IsNull) { using var scope = Interface.GetInterface(); - scope.Value->GetWindow(out _hwnd); + scope.Pointer->GetWindow(out _hwnd); } return _hwnd; @@ -52,7 +52,7 @@ public bool ShowDialog() { using var modalScope = Application.EnterThreadModalScope(); using var fileDialog = Interface.GetInterface(); - HRESULT result = fileDialog.Value->Show(Owner?.Handle ?? default); + HRESULT result = fileDialog.Pointer->Show(Owner?.Handle ?? default); return result.Succeeded || (result == WIN32_ERROR.ERROR_CANCELLED.ToHRESULT() ? false : throw result); } @@ -61,13 +61,13 @@ public Options DialogOptions get { using ComScope dialog = Interface.GetInterface(); - dialog.Value->GetOptions(out var options); + dialog.Pointer->GetOptions(out var options); return (Options)options; } set { using ComScope dialog = Interface.GetInterface(); - dialog.Value->SetOptions((FILEOPENDIALOGOPTIONS)value); + dialog.Pointer->SetOptions((FILEOPENDIALOGOPTIONS)value); } } @@ -79,7 +79,7 @@ public string FileName get { using ComScope dialog = Interface.GetInterface(); - dialog.Value->GetFileName(out PWSTR pszName); + dialog.Pointer->GetFileName(out PWSTR pszName); string result = new(pszName); Interop.CoTaskMemFree(pszName); return result; @@ -87,7 +87,7 @@ public string FileName set { using ComScope dialog = Interface.GetInterface(); - dialog.Value->SetFileName(value); + dialog.Pointer->SetFileName(value); } } @@ -99,7 +99,7 @@ public string FileNameLabel set { using ComScope dialog = Interface.GetInterface(); - dialog.Value->SetFileNameLabel(value); + dialog.Pointer->SetFileNameLabel(value); } } @@ -111,7 +111,7 @@ public string OkButtonLabel set { using ComScope dialog = Interface.GetInterface(); - dialog.Value->SetOkButtonLabel(value); + dialog.Pointer->SetOkButtonLabel(value); } } @@ -121,7 +121,7 @@ public string DefaultFolder { using ComScope dialog = Interface.GetInterface(); using ComScope item = Interop.SHCreateShellItem(value); - dialog.Value->SetDefaultFolder(item); + dialog.Pointer->SetDefaultFolder(item); } } @@ -131,7 +131,7 @@ public string InitialFolder { using ComScope dialog = Interface.GetInterface(); using ComScope item = Interop.SHCreateShellItem(value); - dialog.Value->SetFolder(item); + dialog.Pointer->SetFolder(item); } } @@ -141,8 +141,8 @@ public string? CurrentSelection { using ComScope dialog = Interface.GetInterface(); using ComScope item = new(null); - HRESULT result = dialog.Value->GetCurrentSelection(item); - return result.Failed ? null : item.Value->GetFullPath(); + HRESULT result = dialog.Pointer->GetCurrentSelection(item); + return result.Failed ? null : item.Pointer->GetFullPath(); } } @@ -155,7 +155,7 @@ public Guid ClientGuid set { using ComScope dialog = Interface.GetInterface(); - dialog.Value->SetClientGuid(value); + dialog.Pointer->SetClientGuid(value); } } @@ -165,13 +165,13 @@ public Guid ClientGuid public void ClearClientData() { using ComScope dialog = Interface.GetInterface(); - dialog.Value->ClearClientData(); + dialog.Pointer->ClearClientData(); } public void Close() { using ComScope dialog = Interface.GetInterface(); - dialog.Value->Close(WIN32_ERROR.ERROR_CANCELLED.ToHRESULT()); + dialog.Pointer->Close(WIN32_ERROR.ERROR_CANCELLED.ToHRESULT()); } protected override void Dispose(bool disposing) diff --git a/src/thirtytwo/Dialogs/FileOpenDialog.cs b/src/thirtytwo/Dialogs/FileOpenDialog.cs index 8e45590..430b7f0 100644 --- a/src/thirtytwo/Dialogs/FileOpenDialog.cs +++ b/src/thirtytwo/Dialogs/FileOpenDialog.cs @@ -31,14 +31,14 @@ public IReadOnlyList GetResults() { using ComScope items = new(null); using ComScope dialog = Interface.GetInterface(); - dialog.Value->GetResults(items).ThrowOnFailure(); - items.Value->GetCount(out uint count).ThrowOnFailure(); + dialog.Pointer->GetResults(items).ThrowOnFailure(); + items.Pointer->GetCount(out uint count).ThrowOnFailure(); string[] paths = new string[(int)count]; for (int i = 0; i < count; i++) { using ComScope item = new(null); - items.Value->GetItemAt(0, item).ThrowOnFailure(); - paths[i] = item.Value->GetFullPath(); + items.Pointer->GetItemAt(0, item).ThrowOnFailure(); + paths[i] = item.Pointer->GetFullPath(); } return paths; diff --git a/src/thirtytwo/Support/Error.cs b/src/thirtytwo/Support/Error.cs index 8f750cf..f538b5f 100644 --- a/src/thirtytwo/Support/Error.cs +++ b/src/thirtytwo/Support/Error.cs @@ -206,8 +206,8 @@ public static string FormatMessage( HRESULT hr = (HRESULT)messageId; if (hr.Failed && hr.Facility == FACILITY_CODE.FACILITY_URT) { - // .NET HRESULT, extract the message - string? dotNetMessage = Marshal.GetExceptionForHR((int)hr)?.Message; + // .NET HRESULT, extract the message (pass -1 to ignore whatever random IErrorInfo is on the thread) + string? dotNetMessage = Marshal.GetExceptionForHR((int)hr, -1)?.Message; if (dotNetMessage is not null) { return dotNetMessage; diff --git a/src/thirtytwo/Win32/ComHelpers.cs b/src/thirtytwo/Win32/ComHelpers.cs index f55305f..1a73964 100644 --- a/src/thirtytwo/Win32/ComHelpers.cs +++ b/src/thirtytwo/Win32/ComHelpers.cs @@ -157,17 +157,17 @@ internal static HRESULT UnwrapAndInvoke(TThis* @this, FuncGetLicInfo(&info); + factory.Pointer->GetLicInfo(&info); if (info.fRuntimeKeyAvail) { using BSTR key = default; - factory.Value->RequestLicKey(0, &key); - factory.Value->CreateInstanceLic(null, IID.GetRef(), key, out void* unknown); + factory.Pointer->RequestLicKey(0, &key); + factory.Pointer->CreateInstanceLic(null, IID.GetRef(), key, out void* unknown); return (IUnknown*)unknown; } else { - factory.Value->CreateInstance(null, IID.GetRef(), out void* unknown); + factory.Pointer->CreateInstance(null, IID.GetRef(), out void* unknown); return (IUnknown*)unknown; } } @@ -203,7 +203,7 @@ public static ComScope GetRegisteredTypeInfo( hr.ThrowOnFailure(); ComScope typeInfo = new(null); - typelib.Value->GetTypeInfoOfGuid(interfaceId, typeInfo).ThrowOnFailure(); + typelib.Pointer->GetTypeInfoOfGuid(interfaceId, typeInfo).ThrowOnFailure(); return typeInfo; } } \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/Brush.cs b/src/thirtytwo/Win32/Graphics/Direct2D/Brush.cs index 38368e6..9cda982 100644 --- a/src/thirtytwo/Win32/Graphics/Direct2D/Brush.cs +++ b/src/thirtytwo/Win32/Graphics/Direct2D/Brush.cs @@ -7,13 +7,11 @@ namespace Windows.Win32.Graphics.Direct2D; public unsafe class Brush : Resource, IPointer { - public unsafe new ID2D1Brush* Pointer { get; private set; } + public unsafe new ID2D1Brush* Pointer => (ID2D1Brush*)base.Pointer; - public Brush(ID2D1Brush* brush) : base((ID2D1Resource*)brush) => Pointer = brush; - - protected override void Dispose(bool disposing) + public Brush(ID2D1Brush* brush) : base((ID2D1Resource*)brush) { - Pointer = null; - base.Dispose(disposing); } + + public static implicit operator ID2D1Brush*(Brush brush) => brush.Pointer; } \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/Direct2dFactory.cs b/src/thirtytwo/Win32/Graphics/Direct2D/Direct2dFactory.cs index a8aebcd..0ab11b6 100644 --- a/src/thirtytwo/Win32/Graphics/Direct2D/Direct2dFactory.cs +++ b/src/thirtytwo/Win32/Graphics/Direct2D/Direct2dFactory.cs @@ -1,20 +1,23 @@ // Copyright (c) Jeremy W. Kuhne. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Windows.Support; -using Windows.Win32.System.Com; - namespace Windows.Win32.Graphics.Direct2D; -public unsafe class Direct2dFactory : DisposableBase.Finalizable, IPointer +/// +/// wrapper. +/// +/// +/// +public unsafe class Direct2dFactory : DirectDrawBase { - private readonly AgileComPointer _factory; - - public unsafe ID2D1Factory* Pointer { get; private set; } - public Direct2dFactory( - D2D1_FACTORY_TYPE factoryType = D2D1_FACTORY_TYPE.D2D1_FACTORY_TYPE_SINGLE_THREADED, + D2D1_FACTORY_TYPE factoryType = D2D1_FACTORY_TYPE.D2D1_FACTORY_TYPE_MULTI_THREADED, D2D1_DEBUG_LEVEL factoryOptions = D2D1_DEBUG_LEVEL.D2D1_DEBUG_LEVEL_NONE) + : base(Create(factoryType, factoryOptions)) + { + } + + private static ID2D1Factory* Create(D2D1_FACTORY_TYPE factoryType, D2D1_DEBUG_LEVEL factoryOptions) { ID2D1Factory* factory; Interop.D2D1CreateFactory( @@ -23,20 +26,6 @@ public Direct2dFactory( (D2D1_FACTORY_OPTIONS*)&factoryOptions, (void**)&factory).ThrowOnFailure(); - Pointer = factory; - - // Ensure that this can be disposed on the finalizer thread by giving the "last" ref count - // to an agile pointer. - _factory = new AgileComPointer(factory, takeOwnership: true); - } - - protected override void Dispose(bool disposing) - { - Pointer = null; - - if (disposing) - { - _factory.Dispose(); - } + return factory; } } \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/HwndRenderTarget.cs b/src/thirtytwo/Win32/Graphics/Direct2D/HwndRenderTarget.cs index 33aec23..2d1b56f 100644 --- a/src/thirtytwo/Win32/Graphics/Direct2D/HwndRenderTarget.cs +++ b/src/thirtytwo/Win32/Graphics/Direct2D/HwndRenderTarget.cs @@ -9,12 +9,11 @@ namespace Windows.Win32.Graphics.Direct2D; public unsafe class HwndRenderTarget : RenderTarget, IPointer { - public new ID2D1HwndRenderTarget* Pointer { get; private set; } + public new ID2D1HwndRenderTarget* Pointer => (ID2D1HwndRenderTarget*)base.Pointer; public HwndRenderTarget(ID2D1HwndRenderTarget* renderTarget) : base((ID2D1RenderTarget*)renderTarget) { - Pointer = renderTarget; } public static HwndRenderTarget CreateForWindow( @@ -54,9 +53,5 @@ public static HwndRenderTarget CreateForWindow( return new HwndRenderTarget(renderTarget); } - protected override void Dispose(bool disposing) - { - Pointer = null; - base.Dispose(disposing); - } + public static implicit operator ID2D1HwndRenderTarget*(HwndRenderTarget target) => target.Pointer; } \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/RenderTarget.cs b/src/thirtytwo/Win32/Graphics/Direct2D/RenderTarget.cs index 5cd8d4d..e23c15f 100644 --- a/src/thirtytwo/Win32/Graphics/Direct2D/RenderTarget.cs +++ b/src/thirtytwo/Win32/Graphics/Direct2D/RenderTarget.cs @@ -7,13 +7,11 @@ namespace Windows.Win32.Graphics.Direct2D; public unsafe class RenderTarget : Resource, IPointer { - public unsafe new ID2D1RenderTarget* Pointer { get; private set; } + public unsafe new ID2D1RenderTarget* Pointer => (ID2D1RenderTarget*)base.Pointer; - public RenderTarget(ID2D1RenderTarget* renderTarget) : base((ID2D1Resource*)renderTarget) => Pointer = renderTarget; - - protected override void Dispose(bool disposing) + public RenderTarget(ID2D1RenderTarget* renderTarget) : base((ID2D1Resource*)renderTarget) { - Pointer = null; - base.Dispose(disposing); } + + public static implicit operator ID2D1RenderTarget*(RenderTarget renderTarget) => renderTarget.Pointer; } \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/Resource.cs b/src/thirtytwo/Win32/Graphics/Direct2D/Resource.cs index 669fc3f..e27a405 100644 --- a/src/thirtytwo/Win32/Graphics/Direct2D/Resource.cs +++ b/src/thirtytwo/Win32/Graphics/Direct2D/Resource.cs @@ -2,32 +2,12 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using Windows.Support; -using Windows.Win32.System.Com; namespace Windows.Win32.Graphics.Direct2D; -public unsafe class Resource : DisposableBase.Finalizable, IPointer +public unsafe class Resource : DirectDrawBase, IPointer { - private readonly AgileComPointer _resource; - - public unsafe ID2D1Resource* Pointer { get; private set; } - - public Resource(ID2D1Resource* resource) + public Resource(ID2D1Resource* resource) : base(resource) { - Pointer = resource; - - // Ensure that this can be disposed on the finalizer thread by giving the "last" ref count - // to an agile pointer. - _resource = new AgileComPointer(resource, takeOwnership: true); - } - - protected override void Dispose(bool disposing) - { - Pointer = null; - - if (disposing) - { - _resource.Dispose(); - } } } \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/Direct2D/SolidColorBrush.cs b/src/thirtytwo/Win32/Graphics/Direct2D/SolidColorBrush.cs index 1d097f1..9e7e8d3 100644 --- a/src/thirtytwo/Win32/Graphics/Direct2D/SolidColorBrush.cs +++ b/src/thirtytwo/Win32/Graphics/Direct2D/SolidColorBrush.cs @@ -7,13 +7,11 @@ namespace Windows.Win32.Graphics.Direct2D; public unsafe class SolidColorBrush : Brush, IPointer { - public unsafe new ID2D1SolidColorBrush* Pointer { get; private set; } + public unsafe new ID2D1SolidColorBrush* Pointer => (ID2D1SolidColorBrush*)base.Pointer; - public SolidColorBrush(ID2D1SolidColorBrush* brush) : base((ID2D1Brush*)brush) => Pointer = brush; - - protected override void Dispose(bool disposing) + public SolidColorBrush(ID2D1SolidColorBrush* brush) : base((ID2D1Brush*)brush) { - Pointer = null; - base.Dispose(disposing); } + + public static implicit operator ID2D1SolidColorBrush*(SolidColorBrush brush) => brush.Pointer; } \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/DirectDrawBase.cs b/src/thirtytwo/Win32/Graphics/DirectDrawBase.cs new file mode 100644 index 0000000..a43922d --- /dev/null +++ b/src/thirtytwo/Win32/Graphics/DirectDrawBase.cs @@ -0,0 +1,28 @@ +// Copyright (c) Jeremy W. Kuhne. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using Windows.Support; +using Windows.Win32.System.Com; + +namespace Windows.Win32.Graphics; + +public unsafe abstract class DirectDrawBase : DisposableBase.Finalizable, IPointer where T : unmanaged +{ + private nint _pointer; + + public T* Pointer => (T*)_pointer; + + public DirectDrawBase(T* pointer) => _pointer = (nint)pointer; + + public static implicit operator T*(DirectDrawBase d) => d.Pointer; + + protected override void Dispose(bool disposing) + { + // DirectDraw objects can be accessed from any thread. + nint current = Interlocked.Exchange(ref _pointer, 0); + if (current != 0) + { + ((IUnknown*)current)->Release(); + } + } +} \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/DirectWrite/DirectWriteFactory.cs b/src/thirtytwo/Win32/Graphics/DirectWrite/DirectWriteFactory.cs index 3c6323a..eed5cf6 100644 --- a/src/thirtytwo/Win32/Graphics/DirectWrite/DirectWriteFactory.cs +++ b/src/thirtytwo/Win32/Graphics/DirectWrite/DirectWriteFactory.cs @@ -1,18 +1,16 @@ // Copyright (c) Jeremy W. Kuhne. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Windows.Support; -using Windows.Win32.System.Com; - namespace Windows.Win32.Graphics.DirectWrite; -public unsafe class DirectWriteFactory : DisposableBase.Finalizable, IPointer +public unsafe class DirectWriteFactory : DirectDrawBase { - private readonly AgileComPointer _factory; - - public unsafe IDWriteFactory* Pointer { get; private set; } - public DirectWriteFactory(DWRITE_FACTORY_TYPE factoryType = DWRITE_FACTORY_TYPE.DWRITE_FACTORY_TYPE_SHARED) + : base(Create(factoryType)) + { + } + + private static IDWriteFactory* Create(DWRITE_FACTORY_TYPE factoryType) { IDWriteFactory* factory; Interop.DWriteCreateFactory( @@ -20,20 +18,6 @@ public DirectWriteFactory(DWRITE_FACTORY_TYPE factoryType = DWRITE_FACTORY_TYPE. IID.Get(), (void**)&factory).ThrowOnFailure(); - Pointer = factory; - - // Ensure that this can be disposed on the finalizer thread by giving the "last" ref count - // to an agile pointer. - _factory = new AgileComPointer(factory, takeOwnership: true); - } - - protected override void Dispose(bool disposing) - { - Pointer = null; - - if (disposing) - { - _factory.Dispose(); - } + return factory; } } \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/DirectWrite/DirectWriteGdiInterop.cs b/src/thirtytwo/Win32/Graphics/DirectWrite/DirectWriteGdiInterop.cs new file mode 100644 index 0000000..acf356a --- /dev/null +++ b/src/thirtytwo/Win32/Graphics/DirectWrite/DirectWriteGdiInterop.cs @@ -0,0 +1,26 @@ +// Copyright (c) Jeremy W. Kuhne. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Windows.Win32.Graphics.DirectWrite; + +/// +/// https://learn.microsoft.com/windows/win32/directwrite/appendix--win32-migration +/// https://learn.microsoft.com/windows/win32/directwrite/interoperating-with-gdi +/// +public unsafe class DirectWriteGdiInterop : DirectDrawBase +{ + public DirectWriteGdiInterop() : this(Create()) + { + } + + public DirectWriteGdiInterop(IDWriteGdiInterop* gdiInterop) : base(gdiInterop) + { + } + + private static IDWriteGdiInterop* Create() + { + IDWriteGdiInterop* format; + Application.DirectWriteFactory.Pointer->GetGdiInterop(&format).ThrowOnFailure(); + return format; + } +} \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/DirectWrite/TextFormat.cs b/src/thirtytwo/Win32/Graphics/DirectWrite/TextFormat.cs index f5d77ed..a5f69db 100644 --- a/src/thirtytwo/Win32/Graphics/DirectWrite/TextFormat.cs +++ b/src/thirtytwo/Win32/Graphics/DirectWrite/TextFormat.cs @@ -1,24 +1,12 @@ // Copyright (c) Jeremy W. Kuhne. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using Windows.Support; -using Windows.Win32.System.Com; - namespace Windows.Win32.Graphics.DirectWrite; -public unsafe class TextFormat : DisposableBase.Finalizable, IPointer +public unsafe class TextFormat : DirectDrawBase { - private readonly AgileComPointer _format; - - public unsafe IDWriteTextFormat* Pointer { get; private set; } - - public TextFormat(IDWriteTextFormat* format) + public TextFormat(IDWriteTextFormat* format) : base(format) { - Pointer = format; - - // Ensure that this can be disposed on the finalizer thread by giving the "last" ref count - // to an agile pointer. - _format = new AgileComPointer(format, takeOwnership: true); } public TextFormat( @@ -86,14 +74,4 @@ public ParagraphAlignment ParagraphAlignment GC.KeepAlive(this); } } - - protected override void Dispose(bool disposing) - { - Pointer = null; - - if (disposing) - { - _format.Dispose(); - } - } } \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/DirectWrite/TextLayout.cs b/src/thirtytwo/Win32/Graphics/DirectWrite/TextLayout.cs index 2a38821..00404f1 100644 --- a/src/thirtytwo/Win32/Graphics/DirectWrite/TextLayout.cs +++ b/src/thirtytwo/Win32/Graphics/DirectWrite/TextLayout.cs @@ -3,37 +3,22 @@ using System.Drawing; using Windows.Support; -using Windows.Win32.System.Com; namespace Windows.Win32.Graphics.DirectWrite; -public unsafe class TextLayout : DisposableBase.Finalizable, IPointer +public unsafe class TextLayout : DirectDrawBase { - private readonly AgileComPointer _layout; - - public unsafe IDWriteTextLayout* Pointer { get; private set; } - - public TextLayout(IDWriteTextLayout* layout) + public TextLayout(IDWriteTextLayout* layout) : base(layout) { - Pointer = layout; - - // Ensure that this can be disposed on the finalizer thread by giving the "last" ref count - // to an agile pointer. - _layout = new AgileComPointer(layout, takeOwnership: true); } - public TextLayout( - string text, - TextFormat format, - SizeF maxSize) : this(Create(text, format, maxSize.Width, maxSize.Height)) + public TextLayout(string text, TextFormat format, SizeF maxSize) + : this(Create(text, format, maxSize.Width, maxSize.Height)) { } - public TextLayout( - string text, - TextFormat format, - float maxWidth, - float maxHeight) : this(Create(text, format, maxWidth, maxHeight)) + public TextLayout(string text, TextFormat format, float maxWidth, float maxHeight) + : this(Create(text, format, maxWidth, maxHeight)) { } @@ -143,14 +128,4 @@ public void SetFontWeight(FontWeight fontWeight, TextRange textRange) Pointer->SetFontWeight((DWRITE_FONT_WEIGHT)fontWeight, textRange); GC.KeepAlive(this); } - - protected override void Dispose(bool disposing) - { - Pointer = null; - - if (disposing) - { - _layout.Dispose(); - } - } } \ No newline at end of file diff --git a/src/thirtytwo/Win32/Graphics/DirectWrite/Typography.cs b/src/thirtytwo/Win32/Graphics/DirectWrite/Typography.cs index 7d16526..bcde939 100644 --- a/src/thirtytwo/Win32/Graphics/DirectWrite/Typography.cs +++ b/src/thirtytwo/Win32/Graphics/DirectWrite/Typography.cs @@ -2,24 +2,13 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Runtime.CompilerServices; -using Windows.Support; -using Windows.Win32.System.Com; namespace Windows.Win32.Graphics.DirectWrite; -public unsafe class Typography : DisposableBase.Finalizable, IPointer +public unsafe class Typography : DirectDrawBase { - private readonly AgileComPointer _typography; - - public unsafe IDWriteTypography* Pointer { get; private set; } - - public Typography(IDWriteTypography* typography) + public Typography(IDWriteTypography* typography) : base(typography) { - Pointer = typography; - - // Ensure that this can be disposed on the finalizer thread by giving the "last" ref count - // to an agile pointer. - _typography = new AgileComPointer(typography, takeOwnership: true); } public Typography() : this(Create()) @@ -60,14 +49,4 @@ public uint FontFeatureCount return result; } } - - protected override void Dispose(bool disposing) - { - Pointer = null; - - if (disposing) - { - _typography.Dispose(); - } - } } \ No newline at end of file diff --git a/src/thirtytwo/Win32/System/Com/AgileComPointer.cs b/src/thirtytwo/Win32/System/Com/AgileComPointer.cs index 59eed1f..42920e5 100644 --- a/src/thirtytwo/Win32/System/Com/AgileComPointer.cs +++ b/src/thirtytwo/Win32/System/Com/AgileComPointer.cs @@ -32,6 +32,12 @@ public AgileComPointer(TInterface* @interface, bool takeOwnership) } } + /// + /// Gets the default interface. + /// + /// + /// + /// public ComScope GetInterface() { var scope = GlobalInterfaceTable.GetInterface(_cookie, out HRESULT hr); diff --git a/src/thirtytwo/Win32/System/Com/ComPropertyDescriptor.cs b/src/thirtytwo/Win32/System/Com/ComPropertyDescriptor.cs index b9c8d64..c4252f4 100644 --- a/src/thirtytwo/Win32/System/Com/ComPropertyDescriptor.cs +++ b/src/thirtytwo/Win32/System/Com/ComPropertyDescriptor.cs @@ -67,7 +67,7 @@ public override void ResetValue(object component) { } return null; } - using VARIANT value = dispatch.Value->GetPropertyValue(_dispatchId); + using VARIANT value = dispatch.Pointer->GetPropertyValue(_dispatchId); if (value.IsEmpty) { return null; @@ -127,6 +127,6 @@ public override void SetValue(object? component, object? value) variant.data.boolVal = (bool)value! ? VARIANT_BOOL.VARIANT_TRUE : VARIANT_BOOL.VARIANT_FALSE; } - dispatch.Value->SetPropertyValue(_dispatchId, variant).ThrowOnFailure(); + dispatch.Pointer->SetPropertyValue(_dispatchId, variant).ThrowOnFailure(); } } \ No newline at end of file diff --git a/src/thirtytwo/Win32/System/Com/ComScope{T}.cs b/src/thirtytwo/Win32/System/Com/ComScope{T}.cs index 0d74cfa..2b8b6ab 100644 --- a/src/thirtytwo/Win32/System/Com/ComScope{T}.cs +++ b/src/thirtytwo/Win32/System/Com/ComScope{T}.cs @@ -37,7 +37,7 @@ namespace Windows.Win32.System.Com; { // Keeping internal as nint allows us to use Unsafe methods to get significantly better generated code. private readonly nint _value; - public T* Value => (T*)_value; + public T* Pointer => (T*)_value; public ComScope(T* value) => _value = (nint)value; @@ -60,7 +60,7 @@ namespace Windows.Win32.System.Com; public ComScope QueryInterface() where TInterface : unmanaged, IComIID { ComScope scope = new(null); - ((IUnknown*)Value)->QueryInterface(IID.Get(), scope).ThrowOnFailure(); + ((IUnknown*)Pointer)->QueryInterface(IID.Get(), scope).ThrowOnFailure(); return scope; } @@ -70,7 +70,7 @@ public ComScope TryQueryInterface() where TInterface : u public ComScope TryQueryInterface(out HRESULT result) where TInterface : unmanaged, IComIID { ComScope scope = new(null); - result = ((IUnknown*)Value)->QueryInterface(IID.Get(), scope); + result = ((IUnknown*)Pointer)->QueryInterface(IID.Get(), scope); return scope; } diff --git a/src/thirtytwo/Win32/System/Com/ComTypeDescriptor.cs b/src/thirtytwo/Win32/System/Com/ComTypeDescriptor.cs index 13ed891..1c10997 100644 --- a/src/thirtytwo/Win32/System/Com/ComTypeDescriptor.cs +++ b/src/thirtytwo/Win32/System/Com/ComTypeDescriptor.cs @@ -37,7 +37,7 @@ public ComTypeDescriptor(IComPointer comObject) } using BSTR name = default; - HRESULT hr = typeInfo.Value->GetDocumentation( + HRESULT hr = typeInfo.Pointer->GetDocumentation( Interop.MEMBERID_NIL, &name, null, @@ -57,7 +57,7 @@ public ComTypeDescriptor(IComPointer comObject) return string.Empty; } - using (VARIANT value = dispatch.Value->GetPropertyValue("__id")) + using (VARIANT value = dispatch.Pointer->GetPropertyValue("__id")) { if (value.vt == VARENUM.VT_BSTR) { @@ -65,7 +65,7 @@ public ComTypeDescriptor(IComPointer comObject) } } - using (VARIANT value = dispatch.Value->GetPropertyValue(Interop.DISPID_Name)) + using (VARIANT value = dispatch.Pointer->GetPropertyValue(Interop.DISPID_Name)) { if (value.vt == VARENUM.VT_BSTR) { @@ -73,7 +73,7 @@ public ComTypeDescriptor(IComPointer comObject) } } - using (VARIANT value = dispatch.Value->GetPropertyValue("Name")) + using (VARIANT value = dispatch.Pointer->GetPropertyValue("Name")) { if (value.vt == VARENUM.VT_BSTR) { @@ -113,7 +113,7 @@ private void InitializeEventDescriptors() using ComScope typeLib = new(null); uint typeIndex; - HRESULT hr = typeInfo.Value->GetContainingTypeLib(typeLib, &typeIndex); + HRESULT hr = typeInfo.Pointer->GetContainingTypeLib(typeLib, &typeIndex); if (hr.Failed) { return; @@ -126,7 +126,7 @@ private void InitializeEventDescriptors() } using ComScope enumerator = new(null); - container.Value->EnumConnectionPoints(enumerator); + container.Pointer->EnumConnectionPoints(enumerator); if (hr.Failed) { return; @@ -134,7 +134,7 @@ private void InitializeEventDescriptors() uint count; IConnectionPoint* connectionPoint = null; - while (enumerator.Value->Next(1u, &connectionPoint, &count).Succeeded && count == 1) + while (enumerator.Pointer->Next(1u, &connectionPoint, &count).Succeeded && count == 1) { using ComScope scope = new(connectionPoint); Guid connectionId; @@ -145,13 +145,13 @@ private void InitializeEventDescriptors() } using ComScope eventTypeInfo = new(null); - hr = typeLib.Value->GetTypeInfoOfGuid(connectionId, eventTypeInfo); + hr = typeLib.Pointer->GetTypeInfoOfGuid(connectionId, eventTypeInfo); if (hr.Failed) { continue; } - using var typeAttr = eventTypeInfo.Value->GetTypeAttr(out hr); + using var typeAttr = eventTypeInfo.Pointer->GetTypeAttr(out hr); if (hr.Failed || typeAttr.Value->typekind != TYPEKIND.TKIND_DISPATCH || ((TYPEFLAGS)typeAttr.Value->wTypeFlags).HasFlag(TYPEFLAGS.TYPEFLAG_FDUAL)) @@ -161,7 +161,7 @@ private void InitializeEventDescriptors() } using BSTR name = default; - hr = typeInfo.Value->GetDocumentation(Interop.MEMBERID_NIL, &name, null, null, null); + hr = typeInfo.Pointer->GetDocumentation(Interop.MEMBERID_NIL, &name, null, null, null); if (hr.Failed) { continue; @@ -239,7 +239,7 @@ ComScope FromIDispatch() } ComScope typeInfo = new(null); - hr = dispatch.Value->GetTypeInfo(0, Interop.GetThreadLocale(), typeInfo); + hr = dispatch.Pointer->GetTypeInfo(0, Interop.GetThreadLocale(), typeInfo); return typeInfo; } @@ -252,7 +252,7 @@ ComScope FromIProvideClassInfo() } ComScope typeInfo = new(null); - hr = classInfo.Value->GetClassInfo(typeInfo); + hr = classInfo.Pointer->GetClassInfo(typeInfo); return typeInfo; } } diff --git a/src/thirtytwo/Win32/System/Com/DispatchExAdapter.cs b/src/thirtytwo/Win32/System/Com/DispatchExAdapter.cs index bbb97b0..309120c 100644 --- a/src/thirtytwo/Win32/System/Com/DispatchExAdapter.cs +++ b/src/thirtytwo/Win32/System/Com/DispatchExAdapter.cs @@ -75,7 +75,7 @@ public virtual HRESULT GetMemberProperties(int id, uint grfdexFetch, FDEX_PROP_F return hr; } - hr = typeInfo.Value->GetTypeAttr(out TYPEATTR* typeAttr); + hr = typeInfo.Pointer->GetTypeAttr(out TYPEATTR* typeAttr); if (hr.Failed) { return hr; @@ -93,7 +93,7 @@ public virtual HRESULT GetMemberProperties(int id, uint grfdexFetch, FDEX_PROP_F FUNCDESC* funcdesc; for (uint i = 0; result == HRESULT.DISP_E_UNKNOWNNAME && i < functionCount; i++) { - hr = typeInfo.Value->GetFuncDesc(i, &funcdesc); + hr = typeInfo.Pointer->GetFuncDesc(i, &funcdesc); if (hr.Failed) { return hr; @@ -106,7 +106,7 @@ public virtual HRESULT GetMemberProperties(int id, uint grfdexFetch, FDEX_PROP_F result = HRESULT.S_OK; } - typeInfo.Value->ReleaseFuncDesc(funcdesc); + typeInfo.Pointer->ReleaseFuncDesc(funcdesc); } return result; @@ -126,7 +126,7 @@ public virtual HRESULT GetMemberName(int id, BSTR* pbstrName) return hr; } - hr = typeInfo.Value->GetNames(id, pbstrName, 1, out uint count); + hr = typeInfo.Pointer->GetNames(id, pbstrName, 1, out uint count); return hr; } @@ -152,7 +152,7 @@ public virtual HRESULT GetNextDispID(uint grfdex, int id, int* pid) return hr; } - hr = typeInfo.Value->GetTypeAttr(out TYPEATTR* typeAttr); + hr = typeInfo.Pointer->GetTypeAttr(out TYPEATTR* typeAttr); if (hr.Failed) { return hr; @@ -170,7 +170,7 @@ public virtual HRESULT GetNextDispID(uint grfdex, int id, int* pid) FUNCDESC* funcdesc; for (uint i = 0; i < functionCount; i++) { - hr = typeInfo.Value->GetFuncDesc(i, &funcdesc); + hr = typeInfo.Pointer->GetFuncDesc(i, &funcdesc); if (hr.Failed) { return hr; @@ -178,7 +178,7 @@ public virtual HRESULT GetNextDispID(uint grfdex, int id, int* pid) int currentId = funcdesc->memid; - typeInfo.Value->ReleaseFuncDesc(funcdesc); + typeInfo.Pointer->ReleaseFuncDesc(funcdesc); if (next) { diff --git a/src/thirtytwo_tests/Win32/System/Com/ComTests.cs b/src/thirtytwo_tests/Win32/System/Com/ComTests.cs index 9abe306..b2ff04a 100644 --- a/src/thirtytwo_tests/Win32/System/Com/ComTests.cs +++ b/src/thirtytwo_tests/Win32/System/Com/ComTests.cs @@ -15,7 +15,7 @@ public void Com_GetComPointer_SameUnknownInstance() using ComScope unknown1 = events.GetComCallableWrapper(); using ComScope unknown2 = events.GetComCallableWrapper(); - Assert.True(unknown1.Value == unknown2.Value); + Assert.True(unknown1.Pointer == unknown2.Pointer); } [Fact] @@ -25,6 +25,6 @@ public void Com_GetComPointer_SameInterfaceInstance() using ComScope iEvents1 = events.GetComCallableWrapper(); using ComScope iEvents2 = events.GetComCallableWrapper(); - Assert.True(iEvents1.Value == iEvents2.Value); + Assert.True(iEvents1.Pointer == iEvents2.Pointer); } } diff --git a/src/thirtytwo_tests/Win32/System/Com/ComponentCategoriesManagerTests.cs b/src/thirtytwo_tests/Win32/System/Com/ComponentCategoriesManagerTests.cs index 8af288b..ece1991 100644 --- a/src/thirtytwo_tests/Win32/System/Com/ComponentCategoriesManagerTests.cs +++ b/src/thirtytwo_tests/Win32/System/Com/ComponentCategoriesManagerTests.cs @@ -14,12 +14,12 @@ public void EnumerateCategories() using var categoriesInfo = unknown.TryGetInterface(out HRESULT hr); using ComScope enumCategories = new(null); - hr = categoriesInfo.Value->EnumCategories(Interop.GetUserDefaultLCID(), enumCategories); + hr = categoriesInfo.Pointer->EnumCategories(Interop.GetUserDefaultLCID(), enumCategories); Dictionary categories = []; CATEGORYINFO categoryInfo = default; uint fetched = 0; - while (enumCategories.Value->Next(1, &categoryInfo, &fetched).Succeeded && fetched == 1) + while (enumCategories.Pointer->Next(1, &categoryInfo, &fetched).Succeeded && fetched == 1) { categories.Add(categoryInfo.catid, categoryInfo.szDescription.ToString()); } @@ -35,13 +35,13 @@ public void EnumerateActiveXClasses() using ComScope enumGuids = new(null); Guid control = CATID.Control; - hr = categoriesInfo.Value->EnumClassesOfCategories(1, &control, 0, null, enumGuids); + hr = categoriesInfo.Pointer->EnumClassesOfCategories(1, &control, 0, null, enumGuids); hr.Succeeded.Should().BeTrue(); List classGuids = []; Guid guid = default; uint fetched = 0; - while (enumGuids.Value->Next(1, &guid, &fetched).Succeeded && fetched == 1) + while (enumGuids.Pointer->Next(1, &guid, &fetched).Succeeded && fetched == 1) { classGuids.Add(guid); } diff --git a/src/thirtytwo_tests/Win32/System/Com/IReflectTests.cs b/src/thirtytwo_tests/Win32/System/Com/IReflectTests.cs index ea02a4f..25afe3b 100644 --- a/src/thirtytwo_tests/Win32/System/Com/IReflectTests.cs +++ b/src/thirtytwo_tests/Win32/System/Com/IReflectTests.cs @@ -50,7 +50,7 @@ public void SimpleClass_Public_DispatchBehavior() using ComScope dispatch = new((IDispatch*)InteropMarshal.GetIDispatchForObject(publicSimple)); using ComScope typeInfo = new(null); - HRESULT hr = dispatch.Value->GetTypeInfo(0, Interop.GetThreadLocale(), typeInfo); + HRESULT hr = dispatch.Pointer->GetTypeInfo(0, Interop.GetThreadLocale(), typeInfo); hr.Should().Be(HRESULT.TLBX_E_LIBNOTREGISTERED); } @@ -139,7 +139,7 @@ public void IReflect_IConnectionPointContainer_NoAttribute() hr = container->EnumConnectionPoints(enumPoints); hr.Should().Be(HRESULT.S_OK); IConnectionPoint* connection; - while (enumPoints.Value->Next(1, &connection, out uint fetched) == HRESULT.S_OK) + while (enumPoints.Pointer->Next(1, &connection, out uint fetched) == HRESULT.S_OK) { connection->Release(); Assert.Fail("Shouldn't get any connection points."); @@ -167,7 +167,7 @@ public void IReflect_IConnectionPointContainer_Attributed() { container->EnumConnectionPoints(enumPoints).Succeeded.Should().BeTrue(); IConnectionPoint* connection; - while (enumPoints.Value->Next(1, &connection, out uint fetched) == HRESULT.S_OK) + while (enumPoints.Pointer->Next(1, &connection, out uint fetched) == HRESULT.S_OK) { connection->GetConnectionInterface(out Guid riid).Succeeded.Should().BeTrue(); IConnectionPoint* foundConnection; @@ -224,7 +224,7 @@ public void IReflect_IClassInfo() // The Assembly needs to have a registered TypeLib to get anything. ITypeInfo* typeInfo; - hr = provideClassInfo.Value->GetClassInfo(&typeInfo); + hr = provideClassInfo.Pointer->GetClassInfo(&typeInfo); hr.Should().Be(HRESULT.TLBX_E_LIBNOTREGISTERED); } @@ -263,21 +263,21 @@ public void IReflect_InvokeMember() using ComScope dispatchEx = dispatch.TryQueryInterface(out HRESULT hr); using ComScope typeInfo = new(null); - hr = dispatchEx.Value->GetTypeInfo(0, Interop.GetThreadLocale(), typeInfo); + hr = dispatchEx.Pointer->GetTypeInfo(0, Interop.GetThreadLocale(), typeInfo); hr.Succeeded.Should().Be(true); using BSTR findName = new("Foo"); - hr = dispatchEx.Value->GetDispID(findName, default, out int pid); + hr = dispatchEx.Pointer->GetDispID(findName, default, out int pid); TYPEATTR* attr; - hr = typeInfo.Value->GetTypeAttr(&attr); + hr = typeInfo.Pointer->GetTypeAttr(&attr); hr.Succeeded.Should().Be(true); TYPEATTR attrCopy = *attr; - typeInfo.Value->ReleaseTypeAttr(attr); + typeInfo.Pointer->ReleaseTypeAttr(attr); VARIANT result; DISPPARAMS dispparams = default; - hr = dispatchEx.Value->Invoke( + hr = dispatchEx.Pointer->Invoke( 1776, IID.Empty(), 0, @@ -287,7 +287,7 @@ public void IReflect_InvokeMember() null, null); - hr = dispatchEx.Value->InvokeEx( + hr = dispatchEx.Pointer->InvokeEx( 1776, 0, (ushort)DISPATCH_FLAGS.DISPATCH_PROPERTYGET, @@ -307,12 +307,12 @@ public void IReflect_Enumerate_ReflectSelf() // When Invoking via enumerated ids "ToString" is passed to IReflect.InvokeMember (as opposed to "[DISPID=]"). - var dispatchIds = dispatchEx.Value->GetAllDispatchIds(); + var dispatchIds = dispatchEx.Pointer->GetAllDispatchIds(); dispatchIds.Keys.Should().BeEquivalentTo("GetType", "ToString", "Equals", "GetHashCode"); using VARIANT result = default; DISPPARAMS dispparams = default; - HRESULT hr = dispatchEx.Value->InvokeEx( + HRESULT hr = dispatchEx.Pointer->InvokeEx( dispatchIds["ToString"], 0, (ushort)DISPATCH_FLAGS.DISPATCH_METHOD, @@ -329,7 +329,7 @@ public void IReflect_Enumerate_ReflectSelf() result.Dispose(); // Invoke works as well. - hr = dispatchEx.Value->Invoke( + hr = dispatchEx.Pointer->Invoke( dispatchIds["ToString"], IID.Empty(), 0, @@ -349,7 +349,7 @@ public void IReflect_Enumerate_ReflectSelf() // Try again with QI'ed IDispatch using ComScope dispatch = unknown.QueryInterface(); - hr = dispatch.Value->Invoke( + hr = dispatch.Pointer->Invoke( dispatchIds["ToString"], IID.Empty(), 0, @@ -366,13 +366,13 @@ public void IReflect_Enumerate_ReflectSelf() // Can we get any more info off of IDispatch? Everything but GetDocumentation takes an index, not an id. using ComScope typeInfo = new(null); - dispatchEx.Value->GetTypeInfo(0, 0, typeInfo); + dispatchEx.Pointer->GetTypeInfo(0, 0, typeInfo); using BSTR name = default; using BSTR doc = default; using BSTR helpFile = default; uint helpContext; - hr = typeInfo.Value->GetDocumentation(dispatchIds["ToString"], &name, &doc, &helpContext, &helpFile); + hr = typeInfo.Pointer->GetDocumentation(dispatchIds["ToString"], &name, &doc, &helpContext, &helpFile); hr.Should().Be(HRESULT.TYPE_E_ELEMENTNOTFOUND); } @@ -396,9 +396,9 @@ public void IReflect_ObjectBehavior(object? obj, VARENUM expected) using ComScope unknown = new((IUnknown*)InteropMarshal.GetIUnknownForObject(reflect)); using ComScope dispatch = unknown.QueryInterface(); - var dispatchIds = dispatch.Value->GetAllDispatchIds(); + var dispatchIds = dispatch.Pointer->GetAllDispatchIds(); - dispatch.Value->GetMemberProperties(dispatchIds["Object"], uint.MaxValue, out var flags); + dispatch.Pointer->GetMemberProperties(dispatchIds["Object"], uint.MaxValue, out var flags); flags.Should().Be(fdexPropCanGet | fdexPropCanPut | fdexPropCannotPutRef | fdexPropCannotCall | fdexPropCannotConstruct | fdexPropCannotSourceEvents); @@ -408,7 +408,7 @@ public void IReflect_ObjectBehavior(object? obj, VARENUM expected) reflect.Object = obj; reflect.ObjectAsInterface = obj; - using VARIANT result = dispatch.Value->TryGetPropertyValue(dispatchIds["Object"], out HRESULT hr); + using VARIANT result = dispatch.Pointer->TryGetPropertyValue(dispatchIds["Object"], out HRESULT hr); if (expected == VARENUM.VT_ILLEGAL) { hr.Succeeded.Should().BeFalse(); @@ -419,7 +419,7 @@ public void IReflect_ObjectBehavior(object? obj, VARENUM expected) result.vt.Should().Be(expected); } - using VARIANT result2 = dispatch.Value->TryGetPropertyValue(dispatchIds["ObjectAsInterface"], out hr); + using VARIANT result2 = dispatch.Pointer->TryGetPropertyValue(dispatchIds["ObjectAsInterface"], out hr); if (expected == VARENUM.VT_ILLEGAL) { hr.Succeeded.Should().BeFalse(); @@ -442,36 +442,36 @@ public void IReflect_NonObjectBehavior() using ComScope unknown = new((IUnknown*)InteropMarshal.GetIUnknownForObject(reflect)); using ComScope dispatch = unknown.QueryInterface(); - var dispatchIds = dispatch.Value->GetAllDispatchIds(); + var dispatchIds = dispatch.Pointer->GetAllDispatchIds(); dispatchIds.Keys.Should().Contain("Location", "get_Location", "Color", "get_Color", "set_Color"); - VARIANT result = dispatch.Value->TryGetPropertyValue(dispatchIds["Location"], out HRESULT hr); + VARIANT result = dispatch.Pointer->TryGetPropertyValue(dispatchIds["Location"], out HRESULT hr); hr.Should().Be(HRESULT.COR_E_NOTSUPPORTED); VARIANT value = (VARIANT)42; - hr = dispatch.Value->TrySetPropertyValue(dispatchIds["Count"], value); + hr = dispatch.Pointer->TrySetPropertyValue(dispatchIds["Count"], value); hr.Succeeded.Should().BeTrue(); reflect.Count.Should().Be(42); - result = dispatch.Value->TryGetPropertyValue(dispatchIds["Color"], out hr); + result = dispatch.Pointer->TryGetPropertyValue(dispatchIds["Color"], out hr); result.vt.Should().Be(VARENUM.VT_UI4); ((uint)result).Should().Be(0x00FF0000); // AABBGGRR OLECOLOR // While we can *get* the color, we can't set it as there is no way (afaik) to match the passed in uint parameter. value = (VARIANT)(uint)0x000000FF; - hr = dispatch.Value->TrySetPropertyValue(dispatchIds["Color"], value); + hr = dispatch.Pointer->TrySetPropertyValue(dispatchIds["Color"], value); hr.Should().Be(HRESULT.DISP_E_MEMBERNOTFOUND); - dispatch.Value->GetMemberProperties(dispatchIds["Color"], uint.MaxValue, out var flags); + dispatch.Pointer->GetMemberProperties(dispatchIds["Color"], uint.MaxValue, out var flags); flags.Should().Be(fdexPropCanGet | fdexPropCanPut | fdexPropCannotPutRef | fdexPropCannotCall | fdexPropCannotConstruct | fdexPropCannotSourceEvents); - dispatch.Value->GetMemberProperties(dispatchIds["get_Color"], uint.MaxValue, out flags); + dispatch.Pointer->GetMemberProperties(dispatchIds["get_Color"], uint.MaxValue, out flags); flags.Should().Be(fdexPropCannotGet | fdexPropCannotPut | fdexPropCannotPutRef | fdexPropCanCall | fdexPropCannotConstruct | fdexPropCannotSourceEvents); - dispatch.Value->GetMemberProperties(dispatchIds["set_Color"], uint.MaxValue, out flags); + dispatch.Pointer->GetMemberProperties(dispatchIds["set_Color"], uint.MaxValue, out flags); flags.Should().Be(fdexPropCannotGet | fdexPropCannotPut | fdexPropCannotPutRef | fdexPropCanCall | fdexPropCannotConstruct | fdexPropCannotSourceEvents); } @@ -493,7 +493,7 @@ public void IReflect_IDispatchEx_Enumerate(object reflect, IEnumerable n // Only explicitly provided member info in IReflect is exposed. - var dispatchIds = dispatch.Value->GetAllDispatchIds(); + var dispatchIds = dispatch.Pointer->GetAllDispatchIds(); dispatchIds.Keys.Should().BeEquivalentTo(names); } @@ -513,19 +513,19 @@ public void IReflect_IDispatchDefaultBehavior(object reflect) // Getting IDispatch calls IReflect.GetProperties, IReflect.GetFields, then IReflect.GetMethods using ComScope dispatch = new((IDispatch*)InteropMarshal.GetIDispatchForObject(reflect)); - HRESULT hr = dispatch.Value->GetTypeInfoCount(out uint count); + HRESULT hr = dispatch.Pointer->GetTypeInfoCount(out uint count); hr.Should().Be(HRESULT.S_OK); count.Should().Be(1); using ComScope typeInfo = new(null); - hr = dispatch.Value->GetTypeInfo(0, Interop.GetThreadLocale(), typeInfo); + hr = dispatch.Pointer->GetTypeInfo(0, Interop.GetThreadLocale(), typeInfo); hr.Should().Be(HRESULT.S_OK); TYPEATTR* attr; - hr = typeInfo.Value->GetTypeAttr(&attr); + hr = typeInfo.Pointer->GetTypeAttr(&attr); hr.Succeeded.Should().Be(true); TYPEATTR attrCopy = *attr; - typeInfo.Value->ReleaseTypeAttr(attr); + typeInfo.Pointer->ReleaseTypeAttr(attr); attrCopy.cFuncs.Should().Be(3); attrCopy.cImplTypes.Should().Be(0); @@ -542,15 +542,15 @@ public void IReflect_IDispatchDefaultBehavior(object reflect) attrCopy.wTypeFlags.Should().Be((ushort)TYPEFLAGS.TYPEFLAG_FHIDDEN); using ComScope typeComp = new(null); - hr = typeInfo.Value->GetTypeComp(typeComp); + hr = typeInfo.Pointer->GetTypeComp(typeComp); hr.Succeeded.Should().BeTrue(); VARDESC* vardesc; - hr = typeInfo.Value->GetVarDesc(1, &vardesc); + hr = typeInfo.Pointer->GetVarDesc(1, &vardesc); hr.Should().Be(HRESULT.TYPE_E_ELEMENTNOTFOUND); FUNCDESC* funcdesc; - hr = typeInfo.Value->GetFuncDesc(0, &funcdesc); + hr = typeInfo.Pointer->GetFuncDesc(0, &funcdesc); hr.Succeeded.Should().BeTrue(); funcdesc->cParams.Should().Be(2); funcdesc->memid.Should().Be(0x60000000); @@ -571,20 +571,20 @@ public void IReflect_IDispatchDefaultBehavior(object reflect) funcdesc->lprgelemdescParam[1].tdesc.Anonymous.lptdesc->vt.Should().Be(VARENUM.VT_PTR); funcdesc->lprgelemdescParam[1].tdesc.Anonymous.lptdesc->Anonymous.lptdesc->vt.Should().Be(VARENUM.VT_VOID); - typeInfo.Value->ReleaseFuncDesc(funcdesc); + typeInfo.Pointer->ReleaseFuncDesc(funcdesc); using BSTR name = default; using BSTR doc = default; using BSTR helpFile = default; uint helpContext; - hr = typeInfo.Value->GetDocumentation(0x60000000, &name, &doc, &helpContext, &helpFile); + hr = typeInfo.Pointer->GetDocumentation(0x60000000, &name, &doc, &helpContext, &helpFile); name.ToStringAndFree().Should().Be("QueryInterface"); // This will call IReflect.InvokeMember with a name of "[DISPID=0]" (the member dispid) VARIANT result; DISPPARAMS dispparams = default; - hr = dispatch.Value->Invoke(0, IID.Empty(), 0, DISPATCH_FLAGS.DISPATCH_METHOD, &dispparams, &result, null, null); + hr = dispatch.Pointer->Invoke(0, IID.Empty(), 0, DISPATCH_FLAGS.DISPATCH_METHOD, &dispparams, &result, null, null); } public class PublicSimpleClass diff --git a/src/thirtytwo_tests/Win32/System/Com/ReflectPropertiesDispatchTests.cs b/src/thirtytwo_tests/Win32/System/Com/ReflectPropertiesDispatchTests.cs index 7575d51..8168162 100644 --- a/src/thirtytwo_tests/Win32/System/Com/ReflectPropertiesDispatchTests.cs +++ b/src/thirtytwo_tests/Win32/System/Com/ReflectPropertiesDispatchTests.cs @@ -34,11 +34,11 @@ public void ReflectPropertiesDispatch_ObjectBehavior(object? obj, VARENUM expect using ComScope dispatch = new(ComHelpers.GetComPointer(reflect)); - var dispatchIds = dispatch.Value->GetAllDispatchIds(); + var dispatchIds = dispatch.Pointer->GetAllDispatchIds(); dispatchIds.Keys.Should().Contain("ObjectAsInterface", "Object"); - dispatch.Value->GetMemberProperties(dispatchIds["Object"], uint.MaxValue, out var flags); + dispatch.Pointer->GetMemberProperties(dispatchIds["Object"], uint.MaxValue, out var flags); flags.Should().Be(fdexPropCanGet | fdexPropCanPut | fdexPropCannotPutRef | fdexPropCannotCall | fdexPropCannotConstruct | fdexPropCannotSourceEvents); @@ -48,7 +48,7 @@ public void ReflectPropertiesDispatch_ObjectBehavior(object? obj, VARENUM expect reflect.Object = obj; reflect.ObjectAsInterface = obj; - using VARIANT result = dispatch.Value->TryGetPropertyValue(dispatchIds["Object"], out HRESULT hr); + using VARIANT result = dispatch.Pointer->TryGetPropertyValue(dispatchIds["Object"], out HRESULT hr); if (expected == VARENUM.VT_ILLEGAL) { hr.Succeeded.Should().BeFalse(); @@ -59,7 +59,7 @@ public void ReflectPropertiesDispatch_ObjectBehavior(object? obj, VARENUM expect result.vt.Should().Be(expected); } - using VARIANT result2 = dispatch.Value->TryGetPropertyValue(dispatchIds["ObjectAsInterface"], out hr); + using VARIANT result2 = dispatch.Pointer->TryGetPropertyValue(dispatchIds["ObjectAsInterface"], out hr); if (expected == VARENUM.VT_ILLEGAL) { hr.Succeeded.Should().BeFalse(); @@ -84,27 +84,27 @@ public void ReflectPropertiesDispatch_NonObjectBehavior() using ComScope dispatch = new(ComHelpers.GetComPointer(reflect)); - var dispatchIds = dispatch.Value->GetAllDispatchIds(); + var dispatchIds = dispatch.Pointer->GetAllDispatchIds(); dispatchIds.Keys.Should().Contain("Location", "Color", "Count"); - VARIANT result = dispatch.Value->TryGetPropertyValue(dispatchIds["Location"], out HRESULT hr); + VARIANT result = dispatch.Pointer->TryGetPropertyValue(dispatchIds["Location"], out HRESULT hr); hr.Should().Be(HRESULT.COR_E_NOTSUPPORTED); VARIANT value = (VARIANT)42; - hr = dispatch.Value->TrySetPropertyValue(dispatchIds["Count"], value); + hr = dispatch.Pointer->TrySetPropertyValue(dispatchIds["Count"], value); hr.Succeeded.Should().BeTrue(); reflect.Count.Should().Be(42); - result = dispatch.Value->TryGetPropertyValue(dispatchIds["Color"], out hr); + result = dispatch.Pointer->TryGetPropertyValue(dispatchIds["Color"], out hr); result.vt.Should().Be(VARENUM.VT_UI4); ((uint)result).Should().Be(0x00FF0000); // AABBGGRR OLECOLOR value = (VARIANT)(uint)0x000000FF; - hr = dispatch.Value->TrySetPropertyValue(dispatchIds["Color"], value); + hr = dispatch.Pointer->TrySetPropertyValue(dispatchIds["Color"], value); hr.Should().Be(HRESULT.DISP_E_MEMBERNOTFOUND); - dispatch.Value->GetMemberProperties(dispatchIds["Color"], uint.MaxValue, out var flags); + dispatch.Pointer->GetMemberProperties(dispatchIds["Color"], uint.MaxValue, out var flags); flags.Should().Be(fdexPropCanGet | fdexPropCanPut | fdexPropCannotPutRef | fdexPropCannotCall | fdexPropCannotConstruct | fdexPropCannotSourceEvents); } diff --git a/src/thirtytwo_tests/Win32/System/Com/StandardDispatchTests.cs b/src/thirtytwo_tests/Win32/System/Com/StandardDispatchTests.cs index 33699df..de15f4f 100644 --- a/src/thirtytwo_tests/Win32/System/Com/StandardDispatchTests.cs +++ b/src/thirtytwo_tests/Win32/System/Com/StandardDispatchTests.cs @@ -24,7 +24,7 @@ public void StandardDispatch_ImplDoesNotProvideEx() hr.ThrowOnFailure(); using ComScope typeinfo = new(null); - typelib.Value->GetTypeInfoOfGuid(IUnknown.IID_Guid, typeinfo); + typelib.Pointer->GetTypeInfoOfGuid(IUnknown.IID_Guid, typeinfo); IUnknown* unknown = ComHelpers.GetComPointer(new OleWindow()); @@ -34,7 +34,7 @@ public void StandardDispatch_ImplDoesNotProvideEx() Interop.CreateStdDispatch( unknown, instance, - typeinfo.Value, + typeinfo.Pointer, &standard).ThrowOnFailure(); // StdDispatch does not provide an implementation of IDispatchEx. @@ -59,16 +59,16 @@ public void StandardDispatch_IUnknown() using ComScope dispatchEx = dispatch.TryQueryInterface(out HRESULT hr); using ComScope typeInfo = new(null); - hr = dispatch.Value->GetTypeInfo(0, Interop.GetThreadLocale(), typeInfo); + hr = dispatch.Pointer->GetTypeInfo(0, Interop.GetThreadLocale(), typeInfo); hr.Should().Be(HRESULT.S_OK); // This all matches what we get off of an IReflect dispatch through COM interop TYPEATTR* attr; - hr = typeInfo.Value->GetTypeAttr(&attr); + hr = typeInfo.Pointer->GetTypeAttr(&attr); hr.Succeeded.Should().Be(true); TYPEATTR attrCopy = *attr; - typeInfo.Value->ReleaseTypeAttr(attr); + typeInfo.Pointer->ReleaseTypeAttr(attr); attrCopy.cFuncs.Should().Be(3); attrCopy.cImplTypes.Should().Be(0); @@ -85,15 +85,15 @@ public void StandardDispatch_IUnknown() attrCopy.wTypeFlags.Should().Be((ushort)TYPEFLAGS.TYPEFLAG_FHIDDEN); using ComScope typeComp = new(null); - hr = typeInfo.Value->GetTypeComp(typeComp); + hr = typeInfo.Pointer->GetTypeComp(typeComp); hr.Succeeded.Should().BeTrue(); VARDESC* vardesc; - hr = typeInfo.Value->GetVarDesc(1, &vardesc); + hr = typeInfo.Pointer->GetVarDesc(1, &vardesc); hr.Should().Be(HRESULT.TYPE_E_ELEMENTNOTFOUND); FUNCDESC* funcdesc; - hr = typeInfo.Value->GetFuncDesc(0, &funcdesc); + hr = typeInfo.Pointer->GetFuncDesc(0, &funcdesc); hr.Succeeded.Should().BeTrue(); funcdesc->cParams.Should().Be(2); funcdesc->memid.Should().Be(0x60000000); @@ -114,14 +114,14 @@ public void StandardDispatch_IUnknown() funcdesc->lprgelemdescParam[1].tdesc.Anonymous.lptdesc->vt.Should().Be(VARENUM.VT_PTR); funcdesc->lprgelemdescParam[1].tdesc.Anonymous.lptdesc->Anonymous.lptdesc->vt.Should().Be(VARENUM.VT_VOID); - typeInfo.Value->ReleaseFuncDesc(funcdesc); + typeInfo.Pointer->ReleaseFuncDesc(funcdesc); using BSTR name = default; using BSTR doc = default; using BSTR helpFile = default; uint helpContext; - hr = typeInfo.Value->GetDocumentation(0x60000000, &name, &doc, &helpContext, &helpFile); + hr = typeInfo.Pointer->GetDocumentation(0x60000000, &name, &doc, &helpContext, &helpFile); name.ToStringAndFree().Should().Be("QueryInterface"); } diff --git a/src/thirtytwo_tests/Win32/System/Com/VariantTests.cs b/src/thirtytwo_tests/Win32/System/Com/VariantTests.cs index 92a174a..c225c81 100644 --- a/src/thirtytwo_tests/Win32/System/Com/VariantTests.cs +++ b/src/thirtytwo_tests/Win32/System/Com/VariantTests.cs @@ -39,7 +39,7 @@ public void MarshalRectangleToVariant_ThroughLegacyCCW() // Getting the variant from the native pointer gives the NotSupported HRESULT VARIANT variant = default; - testVariant.Value->GetVariant(&variant).Should().Be(HRESULT.COR_E_NOTSUPPORTED); + testVariant.Pointer->GetVariant(&variant).Should().Be(HRESULT.COR_E_NOTSUPPORTED); variant.IsEmpty.Should().BeTrue(); } diff --git a/src/thirtytwo_tests/Win32/System/Ole/LoadRegTypeLibTests.cs b/src/thirtytwo_tests/Win32/System/Ole/LoadRegTypeLibTests.cs index 06da218..b9264fc 100644 --- a/src/thirtytwo_tests/Win32/System/Ole/LoadRegTypeLibTests.cs +++ b/src/thirtytwo_tests/Win32/System/Ole/LoadRegTypeLibTests.cs @@ -19,7 +19,7 @@ public void LoadRegTypeLib_Accessibility() typelib.IsNull.Should().BeFalse(); using ComScope typeinfo = new(null); - typelib.Value->GetTypeInfoOfGuid(IID.Get(), typeinfo); + typelib.Pointer->GetTypeInfoOfGuid(IID.Get(), typeinfo); typeinfo.IsNull.Should().BeFalse(); } } diff --git a/src/thirtytwo_tests/Win32/UI/Accessibility/AccessibleBaseTests.cs b/src/thirtytwo_tests/Win32/UI/Accessibility/AccessibleBaseTests.cs index 178e4c7..6f7b6b6 100644 --- a/src/thirtytwo_tests/Win32/UI/Accessibility/AccessibleBaseTests.cs +++ b/src/thirtytwo_tests/Win32/UI/Accessibility/AccessibleBaseTests.cs @@ -15,7 +15,7 @@ public void AccessibleBase_Dispatch() { AccessibleCallback callback = new(); using ComScope accessible = callback.GetComCallableWrapper(); - IDispatch* dispatch = (IDispatch*)accessible.Value; + IDispatch* dispatch = (IDispatch*)accessible.Pointer; int[] result = dispatch->GetIdsOfNames("accHitTest", "xLeft", "yTop", "pvarChild"); result.Should().HaveCount(4); result[0].Should().Be(Interop.DISPID_ACC_HITTEST); diff --git a/src/thirtytwo_tests/Win32/UI/Accessibility/CreateStdAccessibleObjectTests.cs b/src/thirtytwo_tests/Win32/UI/Accessibility/CreateStdAccessibleObjectTests.cs index 4de8d7d..faa8163 100644 --- a/src/thirtytwo_tests/Win32/UI/Accessibility/CreateStdAccessibleObjectTests.cs +++ b/src/thirtytwo_tests/Win32/UI/Accessibility/CreateStdAccessibleObjectTests.cs @@ -47,22 +47,22 @@ public void CreateStdAccessibleObject_Window() hr.Succeeded.Should().BeFalse(); // For OBJID_WINDOW the child count is always 7 (OBJID_SYSMENU through OBJID_SIZEGRIP) - accessible.Value->get_accChildCount(out int childCount).Succeeded.Should().BeTrue(); + accessible.Pointer->get_accChildCount(out int childCount).Succeeded.Should().BeTrue(); childCount.Should().Be(7); using BSTR description = default; - accessible.Value->get_accDescription((VARIANT)(int)Interop.CHILDID_SELF, &description).Should().Be(HRESULT.S_FALSE); - accessible.Value->get_accDescription((VARIANT)(int)OBJECT_IDENTIFIER.OBJID_SYSMENU, &description).Succeeded.Should().BeTrue(); + accessible.Pointer->get_accDescription((VARIANT)(int)Interop.CHILDID_SELF, &description).Should().Be(HRESULT.S_FALSE); + accessible.Pointer->get_accDescription((VARIANT)(int)OBJECT_IDENTIFIER.OBJID_SYSMENU, &description).Succeeded.Should().BeTrue(); description.ToStringAndFree().Should().Be("Contains commands to manipulate the window"); // Navigating left from the system menu goes nowhere. using VARIANT result = default; - hr = accessible.Value->accNavigate((int)Interop.NAVDIR_LEFT, (VARIANT)(int)OBJECT_IDENTIFIER.OBJID_SYSMENU, &result); + hr = accessible.Pointer->accNavigate((int)Interop.NAVDIR_LEFT, (VARIANT)(int)OBJECT_IDENTIFIER.OBJID_SYSMENU, &result); result.vt.Should().Be(VARENUM.VT_EMPTY); result.Dispose(); // We get IDispatch for the title bar going right from the system menu - hr = accessible.Value->accNavigate((int)Interop.NAVDIR_RIGHT, (VARIANT)(int)OBJECT_IDENTIFIER.OBJID_SYSMENU, &result); + hr = accessible.Pointer->accNavigate((int)Interop.NAVDIR_RIGHT, (VARIANT)(int)OBJECT_IDENTIFIER.OBJID_SYSMENU, &result); using ComScope right = new((IDispatch*)result); // Can't directly get IAccessibleEx / IRawElementProviderSimple @@ -73,11 +73,11 @@ public void CreateStdAccessibleObject_Window() { rightService.IsNull.Should().BeFalse(); using ComScope provider = new(null); - rightService.Value->QueryService(IID.Get(), IID.Get(), provider); + rightService.Pointer->QueryService(IID.Get(), IID.Get(), provider); provider.IsNull.Should().BeFalse(); - provider.Value->GetPropertyValue(UIA_PROPERTY_ID.UIA_IsContentElementPropertyId, out VARIANT property).Succeeded.Should().BeTrue(); + provider.Pointer->GetPropertyValue(UIA_PROPERTY_ID.UIA_IsContentElementPropertyId, out VARIANT property).Succeeded.Should().BeTrue(); ((bool)property).Should().BeFalse(); - provider.Value->GetPropertyValue(UIA_PROPERTY_ID.UIA_AutomationIdPropertyId, out property).Succeeded.Should().BeTrue(); + provider.Pointer->GetPropertyValue(UIA_PROPERTY_ID.UIA_AutomationIdPropertyId, out property).Succeeded.Should().BeTrue(); property.IsEmpty.Should().BeTrue(); } @@ -86,7 +86,7 @@ public void CreateStdAccessibleObject_Window() using ComScope oleWindow = accessible.TryQueryInterface(out hr); hr.Succeeded.Should().BeTrue(); - oleWindow.Value->GetWindow(out HWND hwnd); + oleWindow.Pointer->GetWindow(out HWND hwnd); hwnd.Should().Be(window.Handle); @@ -98,7 +98,7 @@ public void CreateStdAccessibleObject_Window() byte* id = default; uint length; - identity.Value->GetIdentityString(Interop.CHILDID_SELF, &id, &length); + identity.Pointer->GetIdentityString(Interop.CHILDID_SELF, &id, &length); Span idSpan = new(id, (int)length); idSpan.IsEmpty.Should().BeFalse(); Interop.CoTaskMemFree(id); diff --git a/src/thirtytwo_tests/Win32/UI/Accessibility/CreateStdAccessibleProxyTests.cs b/src/thirtytwo_tests/Win32/UI/Accessibility/CreateStdAccessibleProxyTests.cs index 5331496..df0d50b 100644 --- a/src/thirtytwo_tests/Win32/UI/Accessibility/CreateStdAccessibleProxyTests.cs +++ b/src/thirtytwo_tests/Win32/UI/Accessibility/CreateStdAccessibleProxyTests.cs @@ -100,7 +100,7 @@ public void CreateStdAccessibleProxy_GetTypeInfo() dispatch->GetTypeInfo(0, 0, typeInfo); typeInfo.IsNull.Should().BeFalse(); - typeInfo.Value->GetTypeAttr(out TYPEATTR* pTypeAttr); + typeInfo.Pointer->GetTypeAttr(out TYPEATTR* pTypeAttr); try { pTypeAttr->cFuncs.Should().Be(28); @@ -112,12 +112,12 @@ public void CreateStdAccessibleProxy_GetTypeInfo() } finally { - typeInfo.Value->ReleaseTypeAttr(pTypeAttr); + typeInfo.Pointer->ReleaseTypeAttr(pTypeAttr); } using ComScope typelib = new(null); - typeInfo.Value->GetContainingTypeLib(typelib, out uint index); - typelib.Value->GetLibAttr(out TLIBATTR* pLibAttr); + typeInfo.Pointer->GetContainingTypeLib(typelib, out uint index); + typelib.Pointer->GetLibAttr(out TLIBATTR* pLibAttr); try { // This is the Accessibility type library @@ -129,7 +129,7 @@ public void CreateStdAccessibleProxy_GetTypeInfo() } finally { - typelib.Value->ReleaseTLibAttr(pLibAttr); + typelib.Pointer->ReleaseTLibAttr(pLibAttr); } } } \ No newline at end of file diff --git a/src/thirtytwo_tests/Win32/UI/Accessibility/UiaProviderForNonClientTests.cs b/src/thirtytwo_tests/Win32/UI/Accessibility/UiaProviderForNonClientTests.cs index 1c4561e..f21d872 100644 --- a/src/thirtytwo_tests/Win32/UI/Accessibility/UiaProviderForNonClientTests.cs +++ b/src/thirtytwo_tests/Win32/UI/Accessibility/UiaProviderForNonClientTests.cs @@ -25,7 +25,7 @@ public void UiaProviderForNonClient_Window() hr.Succeeded.Should().BeTrue(); VARIANT variant = default; - hr = provider.Value->GetPropertyValue(UIA_PROPERTY_ID.UIA_BoundingRectanglePropertyId, &variant); + hr = provider.Pointer->GetPropertyValue(UIA_PROPERTY_ID.UIA_BoundingRectanglePropertyId, &variant); hr.Succeeded.Should().BeTrue(); // Not sure why we get no bounding rect.