C++/WinRT 提供了 3 种用于 COM 对象的智能指针 -Microsoft::WRL::ComPtr基于com_ptr、 和 ATL 的智能指针CComPtr。
就我而言,它是一个 COM-lite 对象,这意味着它不是进程内或进程外 COM 对象,它是作为 C++ 对象创建的。
在这种情况下,我应该在 C++/WinRT 组件中使用哪个智能指针?
我正在使用C++/WinRT为 UWP 控件编写 C++ 协程:
winrt::fire_and_forget MyControl::DoSomething()
{
if (/* some condition */)
{
// Why does this work?!
return;
}
co_await winrt::resume_foreground(Dispatcher());
// Do some stuff
co_return;
}
Run Code Online (Sandbox Code Playgroud)
这是为我编译的,但据我所知,C++ 协程不允许简单的return语句。这是编译器中的错误吗?
(有趣的是,我无法将 更改co_return为return;我收到编译器错误。是否只能在or之后返回语句?)co_awaitco_yieldco_return
免责声明:我在微软工作。
我正在尝试编译这个项目:https ://github.com/bucienator/ble-win-cpp
克隆存储库后,我收到错误“wait_for”不是“winrt :: impl”的成员。使用 NuGet,我将 Microsoft.Windows.CppWinRT 包添加到项目中。但之后我对所有库的导入都中断了:
#include <winrt / Windows.Foundation.h>
#include <winrt / Windows.Devices.Bluetooth.h>
#include <winrt / Windows.Devices.Enumeration.h>
#include <winrt / Windows.Devices.Bluetooth.Advertisement.h>
#include <winrt / Windows.Devices.Bluetooth.GenericAttributeProfile.h>
#include <winrt / Windows.Storage.Streams.h>
Run Code Online (Sandbox Code Playgroud)
告诉我如何让 Visual Studio 编译我的项目?