本机 C++ 中的 CreatePushNotificationChannelForApplicationAsync

2024-04-18

我正在尝试在本机 C++ 代码中使用 Windows 推送通知。但我在实施方面遇到了困难。我正在打电话CreatePushNotificationChannelForApplicationAsync但它返回HRESULT_FROM_WIN32(ERROR_NOT_FOUND) : Element not found.

我的操作系统是Win10,使用Visual Studio 2015。

这是我的代码:

#include <wrl.h>
#include <windows.networking.pushnotifications.h>
#include <ppltasks.h>

#pragma comment(lib, "runtimeobject.lib")

using namespace ABI::Windows::Foundation;
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::Networking::PushNotifications;
using namespace concurrency;

int main(char* argv[], int argc)
{
    RoInitializeWrapper init(RO_INIT_MULTITHREADED);
    if ( FAILED(init) )
        return 0;

    ComPtr<IPushNotificationChannelManagerStatics> channelManager;
    HRESULT hr = GetActivationFactory(HStringReference(L"Windows.Networking.PushNotifications.PushNotificationChannelManager").Get(), &channelManager);

    if ( FAILED(hr) )
        return 0;

    IAsyncOperation<PushNotificationChannel*>* asyncOp;
    hr = channelManager->CreatePushNotificationChannelForApplicationAsync(&asyncOp); // return HRESULT_FROM_WIN32(ERROR_NOT_FOUND)

    if ( FAILED(hr) )
        return 0;

    // create task to obtain uri from asyncOp

    return 0;
}

另一方面,在 WinRT 中它非常简单。

namespace WnsPushAPI
{
    public ref class WnsWrapper sealed
    {
    public:

        void ObtainUri()
        {
            IAsyncOperation<PushNotificationChannel^>^ channelOperation = PushNotificationChannelManager::CreatePushNotificationChannelForApplicationAsync();
            auto channelTask = create_task(channelOperation);
            channelTask.then([this](PushNotificationChannel^ channel) {
                // ... Save URI for latter use. channel->Uri->Data()
                channel->PushNotificationReceived += ref new TypedEventHandler<PushNotificationChannel^, PushNotificationReceivedEventArgs^>(this, &WnsWrapper::OnNotify);
            }, task_continuation_context::use_current());
        }

        void OnNotify(PushNotificationChannel^ sender, PushNotificationReceivedEventArgs^ e)
        {
            // do something
        };
    };
}

我还检查了生成的代码/d1ZWtokens编译器开关但我没有发现任何有用的东西。 本机 C++ 的推送通知文档写得很差,我找不到本机 C++ 的示例。


你的代码没问题。问题在于您只能注册来自 Windows 应用商店应用程序的推送通知。您无法通过桌面应用程序执行此操作。该错误源于系统找不到您的 AppX 包标识。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

本机 C++ 中的 CreatePushNotificationChannelForApplicationAsync 的相关文章

  • C 中的隐秘结构定义

    我遇到了以下情况迷宫定义 https github com gduarte lkb blob master code stack maze h code typedef struct mazeNode int hasCheese int t
  • 以编程方式获取命名管道的系统名称

    我正在使用 WCF NetNamedPipeBinding 编写进程间通信 我的目标是让服务在 net pipe localhost service 上运行 所以我运行最简单的主机 host new ServiceHost contract
  • Java 相当于 C# 的 async/await?

    我是一名普通的 C 开发人员 但偶尔也会使用 Java 开发应用程序 我想知道 Java 中是否有相当于 C async await 的东西 简单来说 java 相当于 async Task
  • 如果将其名称作为参数传递,如何在方法中打开表单

    我正在尝试创建一个标准方法来根据传递给它的参数打开表单 基本上 要完成此任务 using Quotes newQte new Quotes newQte ShowDialog 通过替换 Quotes with a passed parame
  • 表达式:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 错误

    此错误发生在运行时 我不确定是什么原因导致的 代码对我来说看起来是正确的 include
  • 清理 STL 指针列表/向量

    您可以想出的最短的 C 块是多少来安全地清理std vector or std list指针 假设您必须对指针调用删除 list
  • esp8266互联网交换机问题

    我正在尝试制作一个门继电器开关系统 我可以通过端口转发从任何地方进行操作 我找到了一个非常有用的指南和代码 我的程序基于 https openhomeautomation net control a lamp remotely using
  • 三元运算的结果(类型)是什么?

    三元运算是否返回副本或引用 我检查了以下代码 vector
  • 如何使用 Unity 动态注册通用类?

    我有一个包含很多类 300 和 BaseClass 的程序集 我想用接口注册一个泛型类 统一后 您必须在 Name如果你想解析接口的对象数组 我想要一个对象数组主视图模型自动地 有没有办法通过反射来自动执行此操作 有什么建议么 示例 伪 p
  • 如何在提升日期时间中忽略周末和节假日?

    第一个问题 我有一个提升日期对象 如下所示 boost gregorian date 今天 2012 02 13 我从今天减去日期部分 如下所示 今天 月 240 或今天 天 X 等 我想在进行上述减法时是否有办法排除周末和特殊假期 我的意
  • 如何防止打印屏幕

    我有一个要求 我正在开发的应用程序阻止用户轻松捕获屏幕内容 我已经表示 没有可行的方法可以完全防止这种情况发生 但我正在寻找方法来为这一过程引入一些障碍 我正在使用 C NET 2 0 和 WinForms 你不能 您能做的最好的事情就是在
  • try-catch 块是否会降低性能[重复]

    这个问题在这里已经有答案了 This link http www cplusplus com doc tutorial exceptions states 为了捕获异常 我们必须将一部分代码放在异常下 检查 这是通过将这部分代码包含在 tr
  • 如何将日期格式从 DD/MM/YYYY 或 MM/DD/YYYY 更改为 YYYY-MM-DD?

    我需要使用 C 更改日期字符串的格式 来自 06 16 2010 或 16 06 2010 至 2010 06 16 你能帮我实现这个目标吗 thanks 如果您已经将其作为DateTime use string x dt ToString
  • 无法在 Visual Studio Code 的 C# 输出上键入任何内容

    所以我试图在 vscode 上运行一个非常基本的 C 程序 代码如下 using System namespace HelloWorld class Program static void Main string args string N
  • 如何检查 iOS 分发配置文件是否启用了推送通知?

    我有一个应用程序应该启用推送通知 但由于某种原因没有启用它们 我见过其他人下载并安装了该应用程序 但它甚至没有提示他们授予发送推送通知的权限 正如预期的那样 此应用程序不会出现在其 设置 gt 通知 中 但是 在我的 iPad 上 我能够从
  • 如何收集和存储tellp()、tellg()返回类型?

    我正在编写一个在文件中维护 linked list 的程序 因此 我通过使用tellp tellg 遍历文件并将其添加到特定的长整数 可以视为偏移量 以到达新位置 一个简单的例子是 long next offset sizeof long
  • 如何将 .ashx 处理程序与 asp:Image 对象一起使用?

    我有一个 ashx 处理程序 using System using System Web public class Thumbnail IHttpHandler public void ProcessRequest HttpContext
  • 为什么删除void*是UB而不是编译错误?

    为什么要通过删除对象void 是未定义的行为 而不是编译错误 void foo void p delete p 这段代码编译并生成代码 尽管有关于 gcc 和 clang 的警告 令人惊讶的是 ICC 没有给出警告 2 5 warning
  • printf 右对齐括号内的数字

    我正在编写一个程序 显示数组中的所有信息 它必须以括号中的数组索引开头 例如 2 并且它们必须彼此正确对齐 如果只是数字 我知道你可以这样做 printf 10d index 但是用括号括起来会得到以下输出 1 2 10 11 当我真正希望
  • C++ 中带逗号的表达式的执行顺序 [重复]

    这个问题在这里已经有答案了 我的理解是这个词j i将在之前执行 i在声明中 j i i C 标准是否保证j i将在之前执行 i在循环 for auto i std next begin j begin i end j i i 逗号运算符引入

随机推荐