Skip to content
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
17 changes: 13 additions & 4 deletions src/Files.App.CsWin32/Windows.Win32.ComPtr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Runtime.CompilerServices;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.System.Com;

namespace Windows.Win32
Expand Down Expand Up @@ -39,11 +40,19 @@ public ComPtr(T* ptr)
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ComPtr<U> As<U>(Guid riid) where U : unmanaged
public readonly ComPtr<U> As<U>() where U : unmanaged
{
ComPtr<U> pNewPtr = default;
((IUnknown*)_ptr)->QueryInterface(&riid, (void**)pNewPtr.GetAddressOf());
return pNewPtr;
ComPtr<U> ptr = default;
Guid iid = typeof(U).GUID;
((IUnknown*)_ptr)->QueryInterface(&iid, (void**)ptr.GetAddressOf());
return ptr;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly HRESULT CoCreateInstance<U>(CLSCTX dwClsContext = CLSCTX.CLSCTX_LOCAL_SERVER) where U : unmanaged
{
Guid clsid = typeof(U).GUID, iid = typeof(T).GUID;
return PInvoke.CoCreateInstance(&clsid, null, dwClsContext, &iid, (void**)this.GetAddressOf());
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
24 changes: 2 additions & 22 deletions src/Files.App/Services/Windows/WindowsDialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,7 @@
try
{
using ComPtr<IFileOpenDialog> pDialog = default;
var dialogInstanceIid = typeof(FileOpenDialog).GUID;
var dialogIid = typeof(IFileOpenDialog).GUID;

// Get a new instance of the dialog
HRESULT hr = PInvoke.CoCreateInstance(
&dialogInstanceIid,
null,
CLSCTX.CLSCTX_INPROC_SERVER,
&dialogIid,
(void**)pDialog.GetAddressOf())
.ThrowOnFailure();
pDialog.CoCreateInstance<FileOpenDialog>(CLSCTX.CLSCTX_INPROC_SERVER).ThrowOnFailure();

Check failure on line 26 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

The type 'FileOpenDialog' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IFileOpenDialog>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 26 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

The type 'FileOpenDialog' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IFileOpenDialog>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 26 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Release, x64)

The type 'FileOpenDialog' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IFileOpenDialog>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 26 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

The type 'FileOpenDialog' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IFileOpenDialog>.CoCreateInstance<U>(CLSCTX)'

if (filters.Length is not 0 && filters.Length % 2 is 0)
{
Expand All @@ -59,7 +49,7 @@
var shellItemIid = typeof(IShellItem).GUID;
fixed (char* pszDefaultFolderPath = Environment.GetFolderPath(defaultFolder))
{
hr = PInvoke.SHCreateItemFromParsingName(

Check failure on line 52 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

The name 'hr' does not exist in the current context

Check failure on line 52 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

The name 'hr' does not exist in the current context

Check failure on line 52 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Release, x64)

The name 'hr' does not exist in the current context

Check failure on line 52 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

The name 'hr' does not exist in the current context
pszDefaultFolderPath,
null,
&shellItemIid,
Expand Down Expand Up @@ -104,17 +94,7 @@
try
{
using ComPtr<IFileSaveDialog> pDialog = default;
var dialogInstanceIid = typeof(FileSaveDialog).GUID;
var dialogIid = typeof(IFileSaveDialog).GUID;

// Get a new instance of the dialog
HRESULT hr = PInvoke.CoCreateInstance(
&dialogInstanceIid,
null,
CLSCTX.CLSCTX_INPROC_SERVER,
&dialogIid,
(void**)pDialog.GetAddressOf())
.ThrowOnFailure();
pDialog.CoCreateInstance<FileSaveDialog>(CLSCTX.CLSCTX_INPROC_SERVER).ThrowOnFailure();

Check failure on line 97 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

The type 'FileSaveDialog' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IFileSaveDialog>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 97 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

The type 'FileSaveDialog' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IFileSaveDialog>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 97 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Release, x64)

The type 'FileSaveDialog' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IFileSaveDialog>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 97 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

The type 'FileSaveDialog' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IFileSaveDialog>.CoCreateInstance<U>(CLSCTX)'

if (filters.Length is not 0 && filters.Length % 2 is 0)
{
Expand All @@ -140,7 +120,7 @@
var shellItemIid = typeof(IShellItem).GUID;
fixed (char* pszDefaultFolderPath = Environment.GetFolderPath(defaultFolder))
{
hr = PInvoke.SHCreateItemFromParsingName(

Check failure on line 123 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

The name 'hr' does not exist in the current context

Check failure on line 123 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

The name 'hr' does not exist in the current context

Check failure on line 123 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Release, x64)

The name 'hr' does not exist in the current context

Check failure on line 123 in src/Files.App/Services/Windows/WindowsDialogService.cs

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

The name 'hr' does not exist in the current context
pszDefaultFolderPath,
null,
&shellItemIid,
Expand Down
22 changes: 2 additions & 20 deletions src/Files.App/Services/Windows/WindowsWallpaperService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@
public unsafe void SetDesktopWallpaper(string szPath)
{
using ComPtr<IDesktopWallpaper> pDesktopWallpaper = default;
var desktopWallpaperIid = typeof(IDesktopWallpaper).GUID;
var desktopWallpaperInstanceIid = typeof(DesktopWallpaper).GUID;

PInvoke.CoCreateInstance(
&desktopWallpaperInstanceIid,
null,
CLSCTX.CLSCTX_LOCAL_SERVER,
&desktopWallpaperIid,
(void**)pDesktopWallpaper.GetAddressOf())
.ThrowOnFailure();
pDesktopWallpaper.CoCreateInstance<DesktopWallpaper>().ThrowOnFailure();

Check failure on line 21 in src/Files.App/Services/Windows/WindowsWallpaperService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

The type 'DesktopWallpaper' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IDesktopWallpaper>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 21 in src/Files.App/Services/Windows/WindowsWallpaperService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

The type 'DesktopWallpaper' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IDesktopWallpaper>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 21 in src/Files.App/Services/Windows/WindowsWallpaperService.cs

View workflow job for this annotation

GitHub Actions / build (Release, x64)

The type 'DesktopWallpaper' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IDesktopWallpaper>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 21 in src/Files.App/Services/Windows/WindowsWallpaperService.cs

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

The type 'DesktopWallpaper' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IDesktopWallpaper>.CoCreateInstance<U>(CLSCTX)'

pDesktopWallpaper.Get()->GetMonitorDevicePathCount(out var dwMonitorCount);

Expand All @@ -48,16 +39,7 @@
public unsafe void SetDesktopSlideshow(string[] aszPaths)
{
using ComPtr<IDesktopWallpaper> pDesktopWallpaper = default;
var desktopWallpaperIid = typeof(IDesktopWallpaper).GUID;
var desktopWallpaperInstanceIid = typeof(DesktopWallpaper).GUID;

PInvoke.CoCreateInstance(
&desktopWallpaperInstanceIid,
null,
CLSCTX.CLSCTX_LOCAL_SERVER,
&desktopWallpaperIid,
(void**)pDesktopWallpaper.GetAddressOf())
.ThrowOnFailure();
pDesktopWallpaper.CoCreateInstance<DesktopWallpaper>().ThrowOnFailure();

Check failure on line 42 in src/Files.App/Services/Windows/WindowsWallpaperService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, x64)

The type 'DesktopWallpaper' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IDesktopWallpaper>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 42 in src/Files.App/Services/Windows/WindowsWallpaperService.cs

View workflow job for this annotation

GitHub Actions / build (Debug, arm64)

The type 'DesktopWallpaper' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IDesktopWallpaper>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 42 in src/Files.App/Services/Windows/WindowsWallpaperService.cs

View workflow job for this annotation

GitHub Actions / build (Release, x64)

The type 'DesktopWallpaper' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IDesktopWallpaper>.CoCreateInstance<U>(CLSCTX)'

Check failure on line 42 in src/Files.App/Services/Windows/WindowsWallpaperService.cs

View workflow job for this annotation

GitHub Actions / build (Release, arm64)

The type 'DesktopWallpaper' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'U' in the generic type or method 'ComPtr<IDesktopWallpaper>.CoCreateInstance<U>(CLSCTX)'

var dwCount = (uint)aszPaths.Length;

Expand Down
Loading