dllwindows-runtimec++-winrtwinrt-component

How to consume WinRT component inside Win32 dll project?


Using Registration-free WinRT it is possible to load WinRT components inside Win32 application.

What's the process to load WinRT component from inside Win32 dll? I tried the steps mentioned as part of Win32, but winmd files are not generating the corresponding header files.

Main usage scenario is dll can be loaded any application, like electron node addon or c# app etc., Without any changes to application, dll by itself should be able to consume WinRT component!


Solution

  • Following is the solution: Was able to fix this in weird manner i.e. not a standard way to solve this.

    Our use case was to use FFmpegInteropX inside win32 dll, so that we can use ffmpeg as a source reader and use the underlying hardware decode support. Mechanism is discussed detailly in the following link:

    https://github.com/ffmpeginteropx/FFmpegInteropX/discussions/275#discussioncomment-3091100

    Following changes were done to use WinRT component inside a Win32 dll:

    1. Copied the WinRT generated files from the application to Win32 dll project
    2. Before invoking any of the api from the generated runtime class, did LoadLibrary of the specific WinRT component into the dll
    3. Now the make the necessary WinRT component call as it was done in standard win32 application

    All modules were working as expected.

    Above solution was copied from: https://learn.microsoft.com/en-us/answers/questions/924996/how-to-consume-winrt-component-inside-win32-dll-pr.html

    It's not a straight forward solution, also not sure if MS has any plans to add support for WinRT component inside dll project, if such support comes up then this may not be needed.