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

1

I start 2 projects in one solution, one is .Net Framework 4.7.2 and the other one is 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.

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,

it gives me an error saying...

Class not registered(Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG) error screenshot

Im new to COM and basically all I know about COM is form enter link description here So how I suppose to do ?

c#
c++
.net
com
windows-runtime
asked on Stack Overflow Mar 6, 2020 by Xeon-J • edited Mar 6, 2020 by Osaf

1 Answer

0

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).

Up until recently, this was only available to UWP applications and they had to declare these dependencies in their AppXManifest.xml file. However, recent Windows versions support declaring these dependencies in Win32 manifest. 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/

answered on Stack Overflow Mar 10, 2020 by Sunius

User contributions licensed under CC BY-SA 3.0