I'm trying to find StorageFile's OpenAsync, ReadAsync for C++/WinRT very difficult. ( and tried testing with C # in UWP, it passed no problem. I originally developed with C ++ MFC. )
Windows::Foundation::IAsyncAction MainPage::FilePickerAsync()
{
auto picker = FileOpenPicker();
picker.ViewMode( PickerViewMode::List );
picker.FileTypeFilter().Append( L".cpp" );
StorageFile file = co_await picker.PickSingleFileAsync();
try
{
IRandomAccessStream stream = co_await file.OpenAsync( FileAccessMode::Read );
uint64_t size64 = stream.Size(); // <= Error
uint32_t size32 = static_cast< uint32_t >( size64 );
auto buffer = Buffer( size32 );
co_await stream.ReadAsync( buffer, size32, InputStreamOptions::None ); // <= Error
stream.Close();
}
catch ( const hresult_error &ex )
{
}
}
Visual C++ 2019
Error C3779 'winrt::impl::consume_Windows_Storage_Streams_IRandomAccessStream <<winrt::Windows::Storage::Streams::IRandomAccessStream>>::Size': a function that returns 'auto' cannot be used before it is defined
Error C3779 'winrt::impl::consume_Windows_Storage_Streams_IInputStream<< D >>::ReadAsync': a function that returns 'auto' cannot be used before it is defined