-
Notifications
You must be signed in to change notification settings - Fork 329
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
Error HRESULT E_FAIL has been returned from a call to a COM component when Windows.Storage.Pickers is using. #776
Comments
Hi @LeftTwixWand, thanks for reporting this. This is a dupe of #466, you have to call an public sealed partial class MainWindow : Window
{
...
private async void myButton_Click(object sender, RoutedEventArgs e)
{
var filePicker = new FileOpenPicker();
//Get the Window's HWND
var hwnd = this.As<IWindowNative>().WindowHandle;
//Make folder Picker work in Win32
var initializeWithWindow = filePicker.As<IInitializeWithWindow>();
initializeWithWindow.Initialize(hwnd);
filePicker.FileTypeFilter.Add("*");
var folder = await filePicker.PickSingleFileAsync();
myText.Text = folder != null ? folder.Path : string.Empty;
}
[ComImport]
[Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithWindow
{
void Initialize(IntPtr hwnd);
}
[ComImport]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[Guid("EECDBF0E-BAE9-4CB6-A68E-9598E1CB57BB")]
internal interface IWindowNative
{
IntPtr WindowHandle { get; }
}
...
} In the future, we could do some new feature work to eliminate this requirement and make the APIs work more straightforward (there's a pending ask for new file/folder picker APIs #88). But this pattern is required for a few Windows 10 APIs like secondary tiles. I'd suggest upvoting and commenting on #88 if you're interested in an improved API! Thanks! |
Thank You so much! |
This solution works for me with FileOpenPicker, but does not work with FileSavePicker. I've tested this with Win UI 3 + .NET 5, 6, and 7 + last 10sih versions of WASDK. |
Describe the bug
When I'm trying to use
FileSavePicker
orFileOpenPicker
from the Windows.Storage.Pickers namespace - get this error:Error HRESULT E_FAIL has been returned from a call to a COM component
Steps to reproduce the bug:
Screenshots
Version Info
NuGet package version:
Microsoft.ProjectReunion 0.5.6
The text was updated successfully, but these errors were encountered: