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 ?

3
  • Hi, could you put a short example of code generating the error please ?
    – bendaizer
    Mar 6, 2020 at 9:26
  • The way the class factory is implemented in WinRT is the essential difference with COM. The default one can only locate components listed in the appx manifest, the implementation detail that is missing in your app. How to extend your C++ code with its own factory is the subject of this article. Mar 6, 2020 at 12:39
  • Hey bendaizer The code generating the error is simply the line I try to create the instance of RuntimeComponent1.Class RuntimeComponent1.Class c = new RuntimeComponent1.Class(); And it's basically all I've done here. You can recreate the error by create a WindowsRuntimeComponent project and a .NetFramework project and simply add a reference to the WindowsRuntimeComponent project in the .Net project. run the code that create the instance define in the WindowsRuntimeComponent. Thanks for your patient
    – Xeon-J
    Mar 7, 2020 at 5:35

1 Answer 1

1

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/

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.