I have a Win32 programm, where I want to add some winRT calls. Among other things I want to open a file without a GUI interface.
I use the async file open call from the StorageFile class, because the next call needs an IStorageFile interface.
#include <roapi.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Foundation.h>
void openFile()
{
using namespace winrt;
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::Storage;
HRESULT rtn = RoInitialize(RO_INIT_MULTITHREADED);
winrt::hstring path{ L"C:\\Users...\\mytextfile.txt"};
//wait for open the file
auto file = co_await StorageFile::GetFileFromPathAsync(path);
//IStorageFile interface needed
}
int main()
{
openFile();
return 0;
}
At the moment, the compiler complains that the co_await expression requires a suitable "await_ready" function and none was found.
I`m not sure if this is the case due to a missing header include or if "co_await" can not be used within a win32 application.
Edit: My visual studio project setup is: - use c++17, add cppwinrt.exe to my include directories, link against windowsapp.lib and use windows sdk version 10.0.17134.0.