问题描述
我看到了这个命名空间:
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应用程序时,您将无法再直接访问WindowsRuntime命名空间,例如Windows.System
But when you create a normal .NET console application or WPF application, you can no longer directly reach WindowsRuntime namespaces such as Windows.System
我想知道是否可以通过在上述命名空间中使用interop来调用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运行时互操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!