Registration-Free WinRT component for DLL

487 views Asked by At

I am trying to use Registration-free WinRT by adding an application manifest following https://blogs.windows.com/windowsdeveloper/2019/04/30/enhancing-non-packaged-desktop-apps-using-windows-runtime-components/ to my DLL which is used as a in-proc COM server.

However, I get REGDB_E_CLASSNOTREG when the runtime class is instantiated. I used mt.exe to make sure the manifest is embedded. I am on Win-10 2004. Is this supposed to be working for win32 in-proc DLL servers? Is there an API call to register the component manually?

2

There are 2 answers

0
Venkatesan Thiyagarajan On

Make sure all dependencies related to WinRT component are present. Dependencies can be other required DLLs or VS runtime DLLs etc.

One problem I faced was: VCRUNTIME140_APP.dll not found, so I copied VC runtime libraries from the following location:

C:\program files (x86)\msbuild\15.0.net.netnative\15.0.24211\x64\ilc\lib\MSCRT

to the output folder, post this FFmpegInteropX component got loaded into application (I think this can be solved by installing Microsoft.VCRTForwarders.140 nuget, but haven't tried it yet)

0
wUsrr On

It appears that the Dll activation context is not used as active activation context by the loader as found in https://stackoverflow.com/a/48308884 .

Instead we have to save the context and activate it before instantiating our runtime class as shown below:

In DllMain:

if (dwReason == DLL_PROCESS_ATTACH)
{
    GetCurrentActCtx(&hActCtx);
}

And before instantiating the Runtime class:

ActivateActCtx(hActCtx, &cookie);
Class1 c;
DeactivateActCtx(0, cookie);
auto x = c.MyProperty();

By manually using the activation context API along with the embedded manifest in DLL, i can use winrt components without registration.