如何在 .NET 4.5 中与 Windows 运行时互操作 [英] How to Interop with Windows Runtime in .NET 4.5

查看:23
本文介绍了如何在 .NET 4.5 中与 Windows 运行时互操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了这个命名空间:

I see this namespace:

System.Runtime.InteropServices.WindowsRuntime

提供 .NET 和 WindowsRuntime 之间的互操作.

Which provides interop between .NET and WindowsRuntime.

例如,您可以在创建 Metro 应用程序时调用 WindowsRuntime 中的方法,因为 Metro 使用 WindowsRuntime,例如

For instance, you can invoke a method in WindowsRuntime when you create a Metro application, as Metro uses WindowsRuntime, like

Windows.System.UserProfile.UserInformation

但是当您创建普通的.NET 控制台应用程序或WPF 应用程序时,您将无法再直接访问Windows.System 等WindowsRuntime 命名空间

But when you create a normal .NET console application or WPF application, you can no longer directly reach WindowsRuntime namespaces such as Windows.System

我想知道是否可以通过在上述命名空间中使用互操作来调用 WindowsRuntime 方法.

I wonder if it were possible to invoke WindowsRuntime methods by using interop in the above-mentioned namespace.

非常感谢!

推荐答案

.NET 控制台模式应用程序或 WPF 应用程序不是 Metro 应用程序.它们只能在常规"版本的 Windows 上运行.Windows 8 情况下的传统桌面.因此无法与 WinRT 互操作,它不会在此过程中加载.以 WinRT 为目标需要在启动项目时选择特定的 Metro 项目模板.

A .NET console mode app or a WPF app are not Metro applications. They can only run on the 'regular' version of Windows. The traditional desktop in the case of Windows 8. So can't interop with WinRT, it isn't loaded in the process. Targeting WinRT requires selecting a specific Metro project template when you start your project.

这篇关于如何在 .NET 4.5 中与 Windows 运行时互操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆