簡體   English   中英

出現錯誤 C2139 undefined class is not allowed - 在 MFC 應用程序中使用 xaml 島時

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

我正在嘗試使用 Xaml Islands 將 WinUI 控件嵌入到舊版 C++ MFC 應用程序中。 在 C++ 桌面 (Win32) 應用程序中按照 Host 自定義 WinRT XAML 控件作為指南。 我的 MFC 應用程序一直編譯到我遵循教程的“在桌面項目中托管自定義 WinRT XAML 控件”部分。 當我引用IDesktopWindowXamlSourceNative並編譯我的應用程序時,我收到以下錯誤。

// Line with C2139 error
auto interop = _desktopWindowXamlSource.as<IDesktopWindowXamlSourceNative>();

構建錯誤:

**\Generated Files\winrt\base.h(1981,53):error C2139: IDesktopWindowXamlSourceNative : 一個未定義的 class 不允許作為編譯器內在類型特征__is_base_of的參數

我已經成功完成了教程示例,但是當我將這些步驟應用於我們的舊版 MFC 應用程序時,它沒有編譯。 我不確定可能是什么問題。

當我嘗試在我的項目中的現有 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)".

因此,為了解決這個問題,我在我的項目中創建了新的“MFC 擴展 DLL”。 然后使用以下設置添加對 WinUI MyApp 項目的引用以解決鏈接錯誤

..\bin\Debug\$(AppProjectName)\$(AppProjectName).winmd true

我遇到了同樣的錯誤。 在我的情況下,原因是NTDDI_VERSION宏的值NTDDI_VISTA

我發現的解決方案是創建一個僅包含 WinRT 的 header,並且在此 header 的開頭我這樣做:

#define NTDDI_VERSION NTDDI_WIN10_19H1

並在文件末尾將 NTDDI_VERSION 恢復為初始值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM