0

我已经在 Windows 10.0 Visual Studio 2017(版本 15.2)上安装了我的项目(包括 cpprestsdk)从 VS2013 迁移到 VS2017,并使用 co_await 更改了 .then() 方法。我在网上读过一些东西,但实际上我不能再编译我的解决方案了。无法打开包含文件 pplawait.h 忽略未知选项“/等待”

建议?

4

1 回答 1

1

将协程与 Visual Studio 2017 和一个 MFC 解决方案一起使用,我在其中使用 C++/WinRT 及其async类型函数,我有以下内容。

另请参阅此问题和我的答案,其中包含使用协同程序的几个示例concurrencystd:async以及 C++/WinRT:C++11 线程来更新 MFC 应用程序窗口。需要 SendMessage()、PostMessage() 吗?

首先在解决方案属性中进行设置。

  • 配置属性 -> 常规 -> 平台工具集 Visual Studio 2017 (v141)
  • C/C++ -> 所有选项 -> 附加选项 -> /await
  • C/C++ -> 所有选项 -> C++ 语言标准 ISO C++17 标准 (/stdc++17)

属性设置 - 配置属性

属性设置 - C/C++(编译器设置)

以及我正在使用的实际函数的源代码(C++/WinRT 异步函数co_await):

#include <pplawait.h>

#pragma comment(lib, "windowsapp")
#include "winrt/Windows.Foundation.h"
#include "winrt/Windows.Web.Syndication.h"

// . . .  other code

// sample function using co_await to retrieve an RSS feed which may take
// a while so we want to start it and then continue when the results are
// received. we are using one of the async functions of C++/WinRT to retrieve
// the RSS feed text. We require a pointer to a CMainFrame object which has
// the function we need to output the text lines to a displayed window.
winrt::Windows::Foundation::IAsyncAction myTaskMain(CMainFrame *p)
{
    winrt::Windows::Foundation::Uri uri(L"http://kennykerr.ca/feed");
    winrt::Windows::Web::Syndication::SyndicationClient client;
    winrt::Windows::Web::Syndication::SyndicationFeed feed = co_await client.RetrieveFeedAsync(uri);

    // send the text strings of the RSS feed list to an MFC output window for
    // display to the user.
    for (winrt::Windows::Web::Syndication::SyndicationItem item : feed.Items())
    {
        winrt::hstring title = item.Title().Text();
        p->SendMessageToOutputWnd(WM_APP, COutputWnd::OutputBuild, (LPARAM)title.c_str());  // print a string to an output window in the output pane.
    }
}
于 2018-06-09T20:10:09.713 回答