-
Notifications
You must be signed in to change notification settings - Fork 693
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
FileOpenPicker throw Invalid Window handle exception in Project Reunion 0.5 desktop app #4519
Comments
I had the same issue and this worked for me: #4167 [ComImport, System.Runtime.InteropServices.Guid("3E68D4BD-7135-4D10-8018-9FB6D9F33FA1"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IInitializeWithWindow
{
void Initialize([In] IntPtr hwnd);
}
[DllImport("user32.dll", ExactSpelling = true, CharSet = CharSet.Auto, PreserveSig = true, SetLastError = false)]
public static extern IntPtr GetActiveWindow();
var picker = new FileOpenPicker();
var initializeWithWindowWrapper = picker.As<IInitializeWithWindow>();
initializeWithWindowWrapper.Initialize(GetActiveWindow());
var file = await picker.PickSingleFileAsync(); |
I'm getting a compiler error on this line of code: Interestingly the ContentDialog issue that was mentioned in your issue appears to work now. |
@gcaughey add |
Thanks - that does indeed solve the compiler error. But now I'm getting a new exception on PickSingleFileAsync: Error HRESULT E_FAIL has been returned from a call to a COM component. |
@gcaughey I just tried it out and unfortunately, it doesn't look like the FileTypeFilter gets set automatically either. So, you'll need to add yet another line to your current monstrosity: |
Excellent! This makes a very usable workaround. Thanks! |
Closing as a duplicate of #4167 |
I have a WinUi3 project and this worked for me just now. FYI. Thanks alot to everyone! |
Describe the bug
FileOpenPicker throws Invalid Window handle exception on PickSingleFileAsync()
Steps to reproduce the bug
Steps to reproduce the behavior:
var picker = new FileOpenPicker();
var file = await picker.PickSingleFileAsync();
Expected behavior
picker.PickerSingleFileAsync() should show FileOpenPicker
Screenshots
Version Info
NuGet package version:
WinUI 3 - Project Reunion 0.5 Preview: 0.5.0-prerelease
Windows app type:
This fails running on Win32 but does not fail running in UWP app model.
Additional context
This app runs without error when running under UWP.
The text was updated successfully, but these errors were encountered: