I'm trying to embed a WinUI control in a legacy C++ MFC application using Xaml Islands. I have followed the Host a custom WinRT XAML control in a C++ desktop (Win32) app as a guide. My MFC application compiles up to the moment I follow the "Host the custom WinRT XAML control in the desktop project" section of the tutorial. I get the following error when I reference IDesktopWindowXamlSourceNative and compile my application.
// Line with C2139 error
auto interop = _desktopWindowXamlSource.as<IDesktopWindowXamlSourceNative>();
Build Error:
**\Generated Files\winrt\base.h(1981,53):error C2139:
IDesktopWindowXamlSourceNative: an undefined class is not allowed as an argument to compiler intrinsic type trait__is_base_of
I've successfully completed the tutorial example, but when I applied the steps to our legacy MFC application it is not compiling. I'm not sure what could be the problem.
It happened for me when I tried to use XAML control in existing MFC DLL in my project.
And that existing MFC DLL is Extension DLL and it is dependent on bunch of other MFC DLL's and few are just "Regular" dll with no call AfxInitExtensionModule or "new CDynLinkLibrary(dll_name)".
So to resolve the problem I created new "MFC extension DLL" in my project. and then added reference to WinUI MyApp Project with below setting to reolve a link error
..\bin\Debug\$(AppProjectName)\$(AppProjectName).winmd true