diff --git a/src/Windows/Avalonia.Win32/SystemDialogImpl.cs b/src/Windows/Avalonia.Win32/SystemDialogImpl.cs index 29844368db..fa53bf57fe 100644 --- a/src/Windows/Avalonia.Win32/SystemDialogImpl.cs +++ b/src/Windows/Avalonia.Win32/SystemDialogImpl.cs @@ -79,7 +79,16 @@ namespace Avalonia.Win32 } } - frm.Show(hWnd); + var showResult = frm.Show(hWnd); + + if ((uint)showResult == (uint)UnmanagedMethods.HRESULT.E_CANCELLED) + { + return result; + } + else if ((uint)showResult != (uint)UnmanagedMethods.HRESULT.S_OK) + { + throw new Win32Exception(showResult); + } if (openDialog?.AllowMultiple == true) { @@ -108,10 +117,6 @@ namespace Avalonia.Win32 } catch (COMException ex) { - if ((uint)ex.HResult == (uint)UnmanagedMethods.HRESULT.E_CANCELLED) - { - return result; - } throw new Win32Exception(ex.HResult); } })!; @@ -151,7 +156,17 @@ namespace Avalonia.Win32 } } - frm.Show(hWnd); + var showResult = frm.Show(hWnd); + + if ((uint)showResult == (uint)UnmanagedMethods.HRESULT.E_CANCELLED) + { + return result; + } + else if ((uint)showResult != (uint)UnmanagedMethods.HRESULT.S_OK) + { + throw new Win32Exception(showResult); + } + if (frm.Result is not null) { result = GetAbsoluteFilePath(frm.Result); @@ -161,10 +176,6 @@ namespace Avalonia.Win32 } catch (COMException ex) { - if ((uint)ex.HResult == (uint)UnmanagedMethods.HRESULT.E_CANCELLED) - { - return result; - } throw new Win32Exception(ex.HResult); } }); diff --git a/src/Windows/Avalonia.Win32/Win32Com/win32.idl b/src/Windows/Avalonia.Win32/Win32Com/win32.idl index 904ac41ff2..54e9aa583f 100644 --- a/src/Windows/Avalonia.Win32/Win32Com/win32.idl +++ b/src/Windows/Avalonia.Win32/Win32Com/win32.idl @@ -112,7 +112,7 @@ interface IShellItemArray : IUnknown interface IModalWindow : IUnknown { [local] - HRESULT Show( + int Show( [in, unique] HWND hwndOwner); }