[英]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.