0

I'm trying to make a game (Universal DX11 application) and at some point I need access to image library to allow user to select avatar. But for some reason call of PickSingleFileAsync on picker rises an exception.

Windows::Storage::Pickers::FileOpenPicker^ openPicker = ref new Windows::Storage::Pickers::FileOpenPicker();
openPicker->SuggestedStartLocation = Windows::Storage::Pickers::PickerLocationId::PicturesLibrary;
openPicker->ViewMode = Windows::Storage::Pickers::PickerViewMode::Thumbnail; 
// Filter to include a sample subset of file types.
auto filters = openPicker->FileTypeFilter;
filters->Clear();
filters->Append(".png");
openPicker->PickSingleFileAsync();// same exception with create_task(...);

Seems like the sample works only if I put it into UI thread. How can I use picker from my own thread?

UPD: HRESULT:0x80004005

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
AbsZero
  • 65
  • 1
  • 6
  • Can you post the exact `HRESULT` of the exception? And just call this from the GUI thread, shouldn't the dialog open as a response to some user action? If so it seems illogical to call it from a non GUI thread. – Rudolfs Bundulis Jul 21 '15 at 09:37
  • The thing is I'm making crossplatform game, so the only thing I need from Windows Universal App is Swap chain panel (ok, and a file picker). I'm dealing with my own threads (std). Just update the post, by the way. And to be honest I have a little experience with universal apps, that's why I need help. – AbsZero Jul 21 '15 at 14:23
  • Ok, that is simply `E_FAIL`, could be other reasons than non GUI thread, however if on GUI thread it works. There is a way to invoke this through the disptacher, I'll post an example. – Rudolfs Bundulis Jul 21 '15 at 14:41
  • sorry I was a little careless and didn't see that your answer is the thing I was going to tell you to try out. But why do you expect this to even work from a non gui thread? – Rudolfs Bundulis Jul 21 '15 at 14:49
  • As I said, I have very little experience with universal apps. So I used msdn's example to open a picker from my game-updater thread. There is no warnings like 'you should call it from ui thread only, child', so that's why I expected this to work. By the way, thank you for response. – AbsZero Jul 22 '15 at 12:25

1 Answers1

1

Ok, I just decided to call dipatcher's RunAsync to execute this code. But I still have no idea why I cannot open picker inside non-UI thread.

AbsZero
  • 65
  • 1
  • 6