简体   繁体   中英

Getting error C2139 undefined class is not allowed - when using xaml island in MFC app

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

I encountered the same error. In my case the cause was the value of NTDDI_VERSION macro which was NTDDI_VISTA .

Solution I found was to create a header with only WinRT includes and at the start of this header I do:

#define NTDDI_VERSION NTDDI_WIN10_19H1

and at the end of file I restore NTDDI_VERSION to the initial value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM