简体   繁体   English

如何在 C++/WinRT 控制台应用程序中包含系统

[英]How to include System in C++/WinRT console application

Using Visual Studio 2019 16.10.2 how do you include .NET components in a C++ / WinRT Console programme?使用 Visual Studio 2019 16.10.2 如何在 C++/WinRT 控制台程序中包含 .NET 组件?

The indexOf method of IVector requires a UInt32 struct from System . IVector indexOf方法需要来自System UInt32结构

How is the System utilised in this context?在这种情况下如何使用System Trying to use the namespace results in a尝试使用命名空间会导致

"System' : a namespace with this name does not exist"

This has been covered already on SO , but only for a C++/CLI application and not in the context of a C++/WinRT console app. 这已经在 SO 上进行了介绍,但仅适用于 C++/CLI 应用程序,而不是 C++/WinRT 控制台应用程序的上下文。 The solutions provided in that post also do not work.该帖子中提供的解决方案也不起作用。

#include "pch.h"

#include <Windows.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>

using winrt::Windows::Foundation::Collections::IVector;
using namespace System;

int main()
{
    IVector<int> foo;
    foo.Append(1);
    UInt32 bar;
    foo.indexOf(1, bar);

    return EXIT_SUCCESS;
}

In this case pch.h is empty.在这种情况下pch.h是空的。

When you select the appropriate language from the documentation 's language dropdown list in the top right corner (C++/WinRT) you'll see the C++/WinRT-specific signature:当您从右上角 (C++/WinRT) 文档的语言下拉列表中选择适当的语言时,您将看到 C++/WinRT 特定的签名:

bool IndexOf(T const& value, uint32_t & index);

You'll need to replace你需要更换

UInt32 bar;

with

uint32_t bar{};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM