项目需要用到UWP的api,windows下c++使用windows runtime api 是微软的一
个愿景,做了许多工作,包括c++/CX等,最近又发布了c++/winrt,winrt问题目前
还是比较多。
winrt编程很简单只需要引入(VC_IncludePath);$(WindowsSDK_IncludePath);
下的winrt头文件,里面提供了uwp的api到c++桌面程序的映射。一般这个include
路径是不用改变的,如果第一次include winrt 头文件提示can not open source file
"winrt",需要手动设置一下include路径。这时候需要找到电脑上winrt这个文件
夹,winrt有多个,每个windows sdk文件夹下都有。就拿我用的10.0.19041.0来举
例,我的winrt文件夹在C:\Program Files (x86)\Windows
Kits\10\Include\10.0.19041.0\winrt。
把winrt文件引入进来后,编译器会报错there are too many errors for the
intellisense engine to function properly。这是因为winrt是用c++17编写的,这些
错误实际上都是文件里面的语法错误。解决方法是设置项目的
Configuration Properties/C/C++/Languge->C++ Languge Standard 为ISO C++17 Standard (/std:c++17)
至此可以在c++ console程序使用UWP的api
引入winrt头文件时提示there are too many errors for the intellisense engine to function properly
最新推荐文章于 2024-05-20 23:52:50 发布