简体   繁体   English

如何在我的 .Net Framework 项目中添加对 Windows 运行时组件 (C++/WinRT) 的引用

[英]How to add a reference to Windows Runtime Component (C++/WinRT) in my .Net Framework project

I start 2 projects in one solution, one is .Net Framework 4.7.2 and the other one is Windows Runtime Component(C++/WinRT) ,我在一个解决方案中启动了 2 个项目,一个是.Net Framework 4.7.2 ,另一个是Windows Runtime Component(C++/WinRT)

What I want to do is write my DirectX related code in the WindowsRuntimeComponent and expose a certain number of classes to the .NetFramework project.我想要做的是在WindowsRuntimeComponent编写我的 DirectX 相关代码,并向.NetFramework项目公开一定数量的类。

I just add reference to the WindowsRuntimeComponent project in the .Net project, It was a success and .Net seems to understand what is in the C++ project However, when I try to create an instance from WindowsRuntimeComponent ,我只是在 .Net 项目中添加了对WindowsRuntimeComponent项目的引用,这是成功的,.Net 似乎了解 C++ 项目中的内容但是,当我尝试从WindowsRuntimeComponent创建实例时,

it gives me an error saying...它给了我一个错误说......

Class not registered(Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG) error screenshot类未注册(来自 HRESULT 的异常:0x80040154 (REGDB_E_CLASSNOTREG)错误截图

Im new to COM and basically all I know about COM is form enter link description here So how I suppose to do ?我是 COM 新手,基本上我所知道的关于 COM 的所有信息都是在此处输入链接描述的形式 那么我想怎么做?

To instantiate a class via WinRT (the class you made in C++/CX), you need to declare it in your manifest or otherwise Windows will not know which .dll file to look in (and that will result in REGDB_E_CLASSNOTREG HRESULT/ClassNotRegistered exception).要通过 WinRT(您在 C++/CX 中创建的类)实例化一个类,您需要在清单中声明它,否则 Windows 将不知道要查找哪个 .dll 文件(这将导致 REGDB_E_CLASSNOTREG HRESULT/ClassNotRegistered 异常) .

Up until recently, this was only available to UWP applications and they had to declare these dependencies in their AppXManifest.xml file.直到最近,这仅适用于 UWP 应用程序,他们必须在 AppXManifest.xml 文件中声明这些依赖项。 However, recent Windows versions support declaring these dependencies in Win32 manifest.但是,最近的 Windows 版本支持在 Win32 清单中声明这些依赖项。 This is how you do it:这是你如何做到的:

<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
    <assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
    <file name="RuntimeComponent1.dll">
        <activatableClass name="RuntimeComponent1.Class" threadingModel="both" xmlns="urn:schemas-microsoft-com:winrt.v1" />
    </file>
</assembly>

You can read more about it here:你可以在这里读更多关于它的内容:

https://blogs.windows.com/windowsdeveloper/2019/04/30/enhancing-non-packaged-desktop-apps-using-windows-runtime-components/ https://blogs.windows.com/windowsdeveloper/2019/04/30/enhancing-non-packaged-desktop-apps-using-windows-runtime-components/

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

相关问题 将Windows运行时组件的引用添加到现有项目 - Add reference of a Windows Runtime Component to an existing project 从Windows应用商店应用项目引用C ++ WinRT组件 - Referencing C++ WinRT component from a Windows Store app project 无法添加对WinRT C ++ DLL项目的引用 - Could not add reference to WinRT C++ DLL project 如何释放在运行时组件中创建的 c++ WinRT 类的内存 - How to free memory of c++ WinRT classes created in the runtime component Windows Metro C ++ C#-如何添加WinRT Portable Project的命名空间? - Windows Metro C++ C# - How to add namespace of WinRT Portable Project? 如何在Visual Studio 2005的C#.NET中的项目中添加对COM组件的引用? - How to add reference to a COM component in my project in C#.NET in Visual Studio 2005? 无法在Visual Studio中向Windows Phone项目添加Visual C ++运行时包引用 - Cannot add Visual C++ Runtime Package reference to Windows Phone project in Visual Studio C#如何将我的dll添加到.Net Framework组件列表 - C# How to add my dll to .Net Framework Component List 如何将C ++ / CX内置的Windows运行时组件安装到C#项目中? - How do you install a Windows Runtime Component built in C++/CX into a C# project? 如何从 c++/cx uwp 项目调用 windows 运行时组件? - How to call windows runtime component from c++/cx uwp project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM