美文网首页
从C++/CX移植到C++/WinRT

从C++/CX移植到C++/WinRT

作者: 叶迎宪 | 来源:发表于2023-07-21 17:54 被阅读0次
一、WinRT中使用 winrt::init_apartment() 完成windows运行时的初始化,功效等同于调用RoInitialize加上COM初始化
二、头文件,C++/CX中的头文件前面加上winrt/

例如 C++/CX中

#include <Windows.Foundation.h>
#include <Windows.Devices.Bluetooth.h>
#include <Windows.Devices.Bluetooth.Advertisement.h>

变成

#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Devices.Bluetooth.h>
#include <winrt/Windows.Devices.Bluetooth.Advertisement.h>
三、命名空间,C++/CX中的命名空间前面加上winrt.

例如
using namespace Windows;
using namespace Windows::Devices;
using namespace Windows::Devices::Bluetooth;
改为
using namespace winrt::Windows;
using namespace winrt::Windows::Devices;
using namespace winrt::Windows::Devices::Bluetooth;

四、对象引用。

C++/CX中一般使用 ^指针来保存对象,一般使用 ref new 来生成对象。而C++/WinRT中使用对象名字的结构体来保存,而且对象直接使用构造函数构造,不需要new
例如

Bluetooth::Advertisement::BluetoothLEAdvertisementWatcher^ scanner_ = 
  ref new Bluetooth::Advertisement::BluetoothLEAdvertisementWatcher();

改为

Bluetooth::Advertisement::BluetoothLEAdvertisementWatcher scanner_ = 
  Bluetooth::Advertisement::BluetoothLEAdvertisementWatcher();
五、访问对象的Property。

从->访问,改为.访问。从直接访问property,变成函数指针,如果传参就是设置值,如果不传参就是获取值。

    auto id = record->XboxUserId;
    auto state = record->UserState;
    record->UserState = newValue;

改为

    auto id = record.XboxUserId();
    auto state = record.UserState();
    record.UserState(newValue);

参考
https://learn.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/move-to-winrt-from-cx

相关文章

  • 迅为i.MX6ULL教程更新至2060+页_完善教程到全面讲解_

    手把手教学,从Windows到Linux再到QT操作系统,从C++到QT系统移植,面向热点紧抓痛点。 独创框架学习...

  • C++语言学习目录

    第一章 预备知识1.1 C++简介1.2 C++简史1.3 可移植性和标准

  • 5. C++与STL入门

    从C到C++ C++模板C++版的“a+b程序”#includeint main() { i...

  • python知识点总结

    简介特点可移植性:可以移植到许多平台可扩展行:可以使用C/C++完成部分程序可嵌入:可以将Python嵌入到C/C...

  • C++复习

    C++谭版期末复习 前言 好好复习,简单看看语法 从C到C++ C++的输入输出 cin cout cerr cl...

  • effective C++ 笔记

    第一章 从 C 到 C++ 条款1 C++是语言联邦这条意思是C++支持面向过程、面向对象、泛型编程、函数编程、元...

  • c++预备知识——可移植性及程序创建技巧

    c++预备知识――可移植性及程序创建技巧 什么是自顶向下,什么是自下向上?结合百度与我的理解:自底向上是从具体到抽...

  • C++,从入门到放弃?

    大家都看过这样的一句话,“C++,从入门到放弃。”,相信想学习C++的人对这句话也深有同感,C++真的那么难学吗?...

  • C++学习笔记 day 1

    C++学习笔记 day 1 教学课程链接:bilibili 黑马程序员:C++从0到1入门编程[https://w...

  • 安卓NDK开发学习笔记

    一、NDK基础概念 1.NDK概念 2.使用场景 代码保护 调用第三方c/c++开源库 c++ 便于移植。用c/c...

网友评论

      本文标题:从C++/CX移植到C++/WinRT

      本文链接:https://www.haomeiwen.com/subject/dnptpdtx.html