Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Quality: Introduced ComPtr for unmanaged COM pointers #16151

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 0 additions & 66 deletions Files.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.App", "src\Files.App\
EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "Files.Package", "src\Files.App (Package)\Files.Package.wapproj", "{8F60FD8E-1921-47D6-97B0-D26D7B3A4999}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.Core.SourceGenerator", "src\Files.Core.SourceGenerator\Files.Core.SourceGenerator.csproj", "{6FA07816-DE0A-4D49-84E8-38E953A33C87}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.App.Server", "src\Files.App.Server\Files.App.Server.csproj", "{1EE996D6-885E-4403-A461-26C7A4E14D26}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Files.App.SaveDialog", "src\Files.App.SaveDialog\Files.App.SaveDialog.vcxproj", "{EBFA367F-CBDB-4CD0-B838-D6B95F61D1F6}"
Expand All @@ -49,8 +47,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.App.UITests", "tests\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Files.App.Controls", "src\Files.App.Controls\Files.App.Controls.csproj", "{83FF8729-CC76-43E2-976F-47F0A187FC7E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Files.App.CsWin32", "src\Files.App.CsWin32\Files.App.CsWin32.csproj", "{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|arm64 = Debug|arm64
Expand Down Expand Up @@ -361,36 +357,6 @@ Global
{8F60FD8E-1921-47D6-97B0-D26D7B3A4999}.Store|x86.ActiveCfg = Store|x86
{8F60FD8E-1921-47D6-97B0-D26D7B3A4999}.Store|x86.Build.0 = Store|x86
{8F60FD8E-1921-47D6-97B0-D26D7B3A4999}.Store|x86.Deploy.0 = Store|x86
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|arm64.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|arm64.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|x64.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|x64.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|x86.ActiveCfg = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Debug|x86.Build.0 = Debug|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|arm64.ActiveCfg = Preview|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|arm64.Build.0 = Preview|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x64.ActiveCfg = Preview|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x64.Build.0 = Preview|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x86.ActiveCfg = Preview|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Preview|x86.Build.0 = Preview|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|arm64.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|arm64.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x64.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x64.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x86.ActiveCfg = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Release|x86.Build.0 = Release|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|arm64.ActiveCfg = Stable|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|arm64.Build.0 = Stable|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x64.ActiveCfg = Stable|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x64.Build.0 = Stable|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x86.ActiveCfg = Stable|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Stable|x86.Build.0 = Stable|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|arm64.ActiveCfg = Store|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|arm64.Build.0 = Store|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x64.ActiveCfg = Store|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x64.Build.0 = Store|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x86.ActiveCfg = Store|Any CPU
{6FA07816-DE0A-4D49-84E8-38E953A33C87}.Store|x86.Build.0 = Store|Any CPU
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|arm64.ActiveCfg = Debug|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|arm64.Build.0 = Debug|arm64
{1EE996D6-885E-4403-A461-26C7A4E14D26}.Debug|arm64.Deploy.0 = Debug|arm64
Expand Down Expand Up @@ -568,36 +534,6 @@ Global
{83FF8729-CC76-43E2-976F-47F0A187FC7E}.Store|arm64.ActiveCfg = Store|arm64
{83FF8729-CC76-43E2-976F-47F0A187FC7E}.Store|x64.ActiveCfg = Store|x64
{83FF8729-CC76-43E2-976F-47F0A187FC7E}.Store|x86.ActiveCfg = Store|x86
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Debug|arm64.ActiveCfg = Debug|arm64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Debug|arm64.Build.0 = Debug|arm64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Debug|x64.ActiveCfg = Debug|x64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Debug|x64.Build.0 = Debug|x64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Debug|x86.ActiveCfg = Debug|x86
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Debug|x86.Build.0 = Debug|x86
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Preview|arm64.ActiveCfg = Preview|arm64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Preview|arm64.Build.0 = Preview|arm64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Preview|x64.ActiveCfg = Preview|x64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Preview|x64.Build.0 = Preview|x64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Preview|x86.ActiveCfg = Preview|x86
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Preview|x86.Build.0 = Preview|x86
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Release|arm64.ActiveCfg = Release|arm64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Release|arm64.Build.0 = Release|arm64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Release|x64.ActiveCfg = Release|x64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Release|x64.Build.0 = Release|x64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Release|x86.ActiveCfg = Release|x86
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Release|x86.Build.0 = Release|x86
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Stable|arm64.ActiveCfg = Stable|arm64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Stable|arm64.Build.0 = Stable|arm64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Stable|x64.ActiveCfg = Stable|x64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Stable|x64.Build.0 = Stable|x64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Stable|x86.ActiveCfg = Stable|x86
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Stable|x86.Build.0 = Stable|x86
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Store|arm64.ActiveCfg = Store|arm64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Store|arm64.Build.0 = Store|arm64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Store|x64.ActiveCfg = Store|x64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Store|x64.Build.0 = Store|x64
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Store|x86.ActiveCfg = Store|x86
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A}.Store|x86.Build.0 = Store|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -614,14 +550,12 @@ Global
{25FD5045-6D4C-4DD0-B3AC-613AB59CBB07} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
{6F431D82-A5FF-4833-B5E4-702E1E523126} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
{8F60FD8E-1921-47D6-97B0-D26D7B3A4999} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
{6FA07816-DE0A-4D49-84E8-38E953A33C87} = {9F36C2AD-005D-4EA5-A1F1-6BC42773FC85}
{1EE996D6-885E-4403-A461-26C7A4E14D26} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
{EBFA367F-CBDB-4CD0-B838-D6B95F61D1F6} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
{7756A1A4-17B5-4E6B-9B12-F19AA868A225} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
{B3FE3F3B-CECC-4918-B72B-5488C3774125} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
{6F5B1C76-6FA1-49C0-9AF5-672BEDF6900B} = {481DE2EA-E6CE-4A9C-A220-3B543B95AAA1}
{83FF8729-CC76-43E2-976F-47F0A187FC7E} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
{4803E2CB-3E27-447D-94FC-45B5F96E4F7A} = {A188C26B-E731-4E0B-9D17-D21CEBD9B43F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0E62043C-A7A1-4982-9EC9-4CDB2939B776}
Expand Down
21 changes: 0 additions & 21 deletions src/Files.App.CsWin32/Files.App.CsWin32.csproj

This file was deleted.

1 change: 0 additions & 1 deletion src/Files.App.Server/Files.App.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Files.App.CsWin32\Files.App.CsWin32.csproj" />
<ProjectReference Include="..\Files.Core.SourceGenerator\Files.Core.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="False" />
<ProjectReference Include="..\Files.Shared\Files.Shared.csproj" />
</ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/Files.App/Files.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Files.App.CsWin32\Files.App.CsWin32.csproj" />
<ProjectReference Include="..\Files.App.BackgroundTasks\Files.App.BackgroundTasks.csproj" />
<ProjectReference Include="..\Files.App.Controls\Files.App.Controls.csproj" />
<ProjectReference Include="..\Files.App.Storage\Files.App.Storage.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWin32" Version="0.3.106" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.Common" Version="4.11.0" PrivateAssets="all" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) 2024 Files Community
// Licensed under the MIT License. See the LICENSE.

using System;
using System.Runtime.CompilerServices;
using Windows.Win32;
using Windows.Win32.System.Com;

namespace Windows.Win32
{
/// <summary>
/// Contains a COM pointer and a set of methods to work with the pointer safely.
/// </summary>
public unsafe struct ComPtr<T> : IDisposable where T : unmanaged
{
private T* _ptr;

public bool IsNull
=> _ptr == default;

public ComPtr(T* ptr)
{
_ptr = ptr;

if (ptr is not null)
((IUnknown*)ptr)->AddRef();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly T* Get()
{
return _ptr;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly T** GetAddressOf()
{
return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Dispose()
{
T* ptr = _ptr;
if (ptr is not null)
{
_ptr = null;
((IUnknown*)ptr)->Release();
}
}
}
}
Loading