简体   繁体   English

出现错误 C2139 undefined class is not allowed - 在 MFC 应用程序中使用 xaml 岛时

[英]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.我正在尝试使用 Xaml Islands 将 WinUI 控件嵌入到旧版 C++ MFC 应用程序中。 I have followed the Host a custom WinRT XAML control in a C++ desktop (Win32) app as a guide.在 C++ 桌面 (Win32) 应用程序中按照 Host 自定义 WinRT XAML 控件作为指南。 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.我的 MFC 应用程序一直编译到我遵循教程的“在桌面项目中托管自定义 WinRT XAML 控件”部分。 I get the following error when I reference IDesktopWindowXamlSourceNative and compile my application.当我引用IDesktopWindowXamlSourceNative并编译我的应用程序时,我收到以下错误。

// 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 **\Generated Files\winrt\base.h(1981,53):error C2139: IDesktopWindowXamlSourceNative : 一个未定义的 class 不允许作为编译器内在类型特征__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.我已经成功完成了教程示例,但是当我将这些步骤应用于我们的旧版 MFC 应用程序时,它没有编译。 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.当我尝试在我的项目中的现有 MFC DLL 中使用 XAML 控件时,它发生在我身上。

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)". 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.因此,为了解决这个问题,我在我的项目中创建了新的“MFC 扩展 DLL”。 and then added reference to WinUI MyApp Project with below setting to reolve a link error然后使用以下设置添加对 WinUI MyApp 项目的引用以解决链接错误

..\bin\Debug\$(AppProjectName)\$(AppProjectName).winmd true ..\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 .在我的情况下,原因是NTDDI_VERSION宏的值NTDDI_VISTA

Solution I found was to create a header with only WinRT includes and at the start of this header I do:我发现的解决方案是创建一个仅包含 WinRT 的 header,并且在此 header 的开头我这样做:

#define NTDDI_VERSION NTDDI_WIN10_19H1 #define NTDDI_VERSION NTDDI_WIN10_19H1

and at the end of file I restore NTDDI_VERSION to the initial value.并在文件末尾将 NTDDI_VERSION 恢复为初始值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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