Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any chance to get a tutorial how to apply it to MFC app ? #7786

Closed
tomaszkot opened this issue Oct 5, 2022 · 34 comments
Closed

Any chance to get a tutorial how to apply it to MFC app ? #7786

tomaszkot opened this issue Oct 5, 2022 · 34 comments
Labels
area-Islands Xaml Islands feature documentation An issue with existing documentation or a request for documenation of a new topic needs-triage Issue needs to be triaged by the area owners no-issue-activity question

Comments

@tomaszkot
Copy link

How apply it to MFC app ?

There is a similar tutorial at:
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/host-custom-control-with-xaml-islands-cpp

But that was UWP so some details are not applicable here.

@tomaszkot tomaszkot added the feature proposal New feature proposal label Oct 5, 2022
@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Oct 5, 2022
@DarranRowe
Copy link

Truthfully, it isn't that different to doing this with UWP Xaml with WinUI 2.
The issue is that DesktopWindowXamlSource and WindowsXamlManager are experimental features that are only available in the experimental versions of WinUI 3.
As an example, if you run winmdidl on the 1.2 experimental 2 version of Microsoft.UI.Xaml.winmd, you can get:

[composable(Microsoft.UI.Xaml.Hosting.IDesktopWindowXamlSourceFactory, public, Microsoft.UI.Xaml.Hosting.HostingContract, 1.0)]
[contract(Microsoft.UI.Xaml.Hosting.HostingContract, 1.0)]
[experimental]
[marshaling_behavior(agile)]
[threading(both)]
runtimeclass DesktopWindowXamlSource
{
    [default] [experimental] interface Microsoft.UI.Xaml.Hosting.IDesktopWindowXamlSource;
    [contract(Microsoft.UI.Xaml.Hosting.HostingContract, 1.0)] [experimental] interface Windows.Foundation.IClosable;
}

and

[contract(Microsoft.UI.Xaml.Hosting.HostingContract, 1.0)]
[experimental]
[marshaling_behavior(agile)]
[static(Microsoft.UI.Xaml.Hosting.IWindowsXamlManagerStatics, Microsoft.UI.Xaml.Hosting.HostingContract, 1.0)]
[threading(both)]
runtimeclass WindowsXamlManager
{
    [default] [experimental] interface Microsoft.UI.Xaml.Hosting.IWindowsXamlManager;
    [contract(Microsoft.UI.Xaml.Hosting.HostingContract, 1.0)] [experimental] interface Windows.Foundation.IClosable;
}

These are the interfaces needed to host Xaml content in MFC, but notice how they have the experimental attribute? The WinUI 3 Xaml islands are not classed as ready for general usage right now.

If you have no issues with experimenting with experimental features, it takes a little more work, but it is still easy to get it to work. The biggest thing you need in addition is a class that derives from Microsoft.UI.Xaml.Application and implements IMetadataProvider. Although the metadata provider can be much simpler than a full Xaml application. It only needs to provide metadata for existing components, meaning you can just pass the metadata provider through.

If you want an example, I have no issues providing a fairly minimal Windows API example. It is easy enough to adapt that when you have all of the pieces.

@tomaszkot
Copy link
Author

tomaszkot commented Oct 6, 2022

Hello,

Thank you for hints.
Unfortunately with my current knowledge I'm not able to make it work.

I wanted to start with a simple setup. I followed that tutorial, trying to rework it with WinUI.
https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/host-custom-control-with-xaml-islands-cpp

I forked repo to:
https://github.com/tomaszkot/WindowsAppSDK-Samples
New sln is: Samples\CustomControlsMFC\WinUIComponentCsToMFC.sln

  • created project MyUWPApp - Experimental Win3UI (c++)
  • created project MFCApplication1

Note: Currently app must be switched to x86 before compilation.

Currently there are such issues:

  1. MFCApplication1 give compilation error :

cppwinrt : error Type 'Microsoft.UI.Xaml.Markup.IXamlMetadataProvider' could not be found
1>D:\Repos\WindowsAppSDK-Samples\Samples\CustomControlsMFC\packages\Microsoft.Windows.CppWinRT.2.0.220929.3\build\native\Microsoft.Windows.CppWinRT.targets(741,9): error MSB3073: The command ""D:\Repos\WindowsAppSDK-Samples\Samples\CustomControlsMFC\packages\Microsoft.Windows.CppWinRT.2.0.220929.3\build\native....\bin"cppwinrt @"D:\Repos\WindowsAppSDK-Samples\Samples\CustomControlsMFC\obj\x64\Debug\MFCApplication1\MFCApplication1.vcxproj.cppwinrt_ref.rsp"" exited with code 1.

  1. If I temporarily remove MyUWPApp from a dependency list of MFCApplication1, previous one is gone, but I get other one :
    Severity Code Description Project File Line Suppression State
    Error C2039 'DesktopWindowXamlSource': is not a member of 'winrt::Windows::UI::Xaml::Hosting' MFCApplication1 D:\Repos\WindowsAppSDK-Samples\Samples\CustomControlsMFC\MFCApplication1\MFCApplication1View.cpp 28

Summing up, hard way to start without a decent tutorial.

@DarranRowe
Copy link

Okay. This sample uses a Windows API window.
It creates a window and loads a Xaml control from an embedded resource.

XamlIslandTest3.zip

It should be fairly easy to transfer the required parts into an MFC application. The important parts are the IslandApplication component and some method for getting the DesktopWindowXamlSource to filter any messages.

@tomaszkot
Copy link
Author

Thank you for this one.

When I try to build it I get:
Severity Code Description Project File Line Suppression State
Error MIDL2072 [msg]inapplicable attribute [context]: Windows.Foundation.Metadata.ExperimentalAttribute [ RuntimeClass 'Microsoft.UI.Xaml.Application' ( RuntimeClass 'XamlIslandTest3.IslandApplication' ) ] XamlIslandTest3 D:\tmp\XamlIslandTest3\XamlIslandTest3\XamlIslandTest3\IslandApplication.idl 9

I installed the stuff from beneath link and have experimental projects available when trying to add a new Project, but obviously I miss something.
https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/experimental-channel#version-12-experimental-120-experimental2

@DarranRowe
Copy link

That is interesting.
Nothing referenced in that file should have the experimental attribute set.

The only thing I can think of is that there is something with the version of MIDL you are using. What version of the Windows SDK is being used? It was building, and succeeding, with the Windows 11 22H2 (10.0.22621.0) version of the SDK. IIRC, the project was set to use the latest version 10 SDK installed on the system.

@tomaszkot
Copy link
Author

Thank you for further help.

I've machine with win10, was wondering it I can install SDK 10.0.22621.0 on it, tried and installation was fine,.

Then it compiled.

At the startup I got:
'This application requires the Windows App Runtime
Version 1.2-experimental2
(MSIX package version >= 0.0.0.0)

Do you want to install a compatible Windows App Runtime now?'

So I installed it.

Now it's crashing at startup:

D:\a_work\1\s\dev\DynamicDependency\API\WinRTInprocModule.h(55)\Microsoft.WindowsAppRuntime.dll!7950A005: (caller: 79509AEE) Exception(1) tid(1eb8) 80004002 No such interface supported
Msg:[Error 0x80004002 in ifactory->QueryInterface(Microsoft.UI.Xaml.Media.AcrylicBrush)]
Exception thrown at 0x7555CC12 in XamlIslandTest3.exe: Microsoft C++ exception: wil::ResultException at memory location 0x009DC050.
Exception thrown at 0x7555CC12 in XamlIslandTest3.exe: Microsoft C++ exception: [rethrow] at memory location 0x00000000.
D:\a_work\1\s\dev\DynamicDependency\API\MddWinRT.cpp(54)\Microsoft.WindowsAppRuntime.dll!79504C50: (caller: 7950BBD9) ReturnHr(2) tid(1eb8) 80004002 No such interface supported
Msg:[D:\a_work\1\s\dev\DynamicDependency\API\WinRTInprocModule.h(55)\Microsoft.WindowsAppRuntime.dll!7950A005: (caller: 79509AEE) Exception(1) tid(1eb8) 80004002 No such interface supported
Msg:[Error 0x80004002 in ifactory->QueryInterface(Microsoft.UI.Xaml.Media.AcrylicBrush)]

So I suppose maybe win10 is not capable of running it.

@DarranRowe
Copy link

DarranRowe commented Oct 11, 2022

The output for these projects is problematic since the Windows App SDK doesn't hesitate to use exceptions internally.
On a Windows 11 system, I get.

'XamlIslandTest3.exe' (Win32): Loaded 'C:\Users\Darran\source\repos\XamlIslandTest3\ARM64\Debug\XamlIslandTest3.exe'. Symbols loaded.
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\win32u.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\gdi32full.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\msvcp_win.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbase.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\combase.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\dwmapi.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140d.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. 
'XamlIslandTest3.exe' (Win32): Unloaded 'C:\Windows\System32\ucrtbased.dll'
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. 
'XamlIslandTest3.exe' (Win32): Unloaded 'C:\Windows\System32\ucrtbased.dll'
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Users\Darran\source\repos\XamlIslandTest3\ARM64\Debug\Microsoft.WindowsAppRuntime.Bootstrap.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\bcryptprimitives.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\uxtheme.dll'. 
D:\a\_work\1\s\BuildOutput\Release\ARM64\WindowsAppRuntime_DLL\WindowsAppRuntimeInsights.h(53)\Microsoft.WindowsAppRuntime.Bootstrap.dll!00007FFFA5791CEC: (caller: 00007FFFA57919D0) LogHr(1) tid(9b8) 8007007E The specified module could not be found.
    Msg:[Unable to load resource dll. Microsoft.WindowsAppRuntime.Insights.Resource.dll] 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\clbcatq.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\AppXDeploymentClient.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\Windows.ApplicationModel.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\WinTypes.dll'. 
D:\a\_work\1\s\dev\WindowsAppRuntime_BootstrapDLL\MddBootstrap.cpp(814)\Microsoft.WindowsAppRuntime.Bootstrap.dll!00007FFFA578A9BC: (caller: 00007FFFA5789404) LogHr(2) tid(9b8) 80040010 Object is not in any of the inplace active states
    Msg:[Bootstrap.Intitialize: Scanning packages for Major.Minor=1.2, Tag=experimental2, MinVersion=0.0.0.0] CallContext:[\Initialize] 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\Windows.StateRepositoryCore.dll'. 
D:\a\_work\1\s\dev\WindowsAppRuntime_BootstrapDLL\MddBootstrap.cpp(923)\Microsoft.WindowsAppRuntime.Bootstrap.dll!00007FFFA578B188: (caller: 00007FFFA5789404) LogHr(3) tid(9b8) 80040012 Not able to perform the operation because object is not given storage yet
    Msg:[Bootstrap.Intitialize: Microsoft.WinAppRuntime.DDLM.2000.616.1852.0-a6-e2_2000.616.1852.0_arm64__8wekyb3d8bbwe is applicable (Major.Minor=1.2, Tag=experimental2, MinVersion=0.0.0.0)] CallContext:[\Initialize] 
D:\a\_work\1\s\dev\WindowsAppRuntime_BootstrapDLL\MddBootstrap.cpp(914)\Microsoft.WindowsAppRuntime.Bootstrap.dll!00007FFFA578B104: (caller: 00007FFFA5789404) LogHr(4) tid(9b8) 80040011 Not able to convert object
    Msg:[Bootstrap.Intitialize: Microsoft.WinAppRuntime.DDLM.2000.616.1852.0-x6-e2_2000.616.1852.0_x64__8wekyb3d8bbwe not applicable. Architecture doesn't match current architecture arm64 (Major.Minor=1.2, Tag=experimental2, MinVersion=0.0.0.0)] CallContext:[\Initialize] 
D:\a\_work\1\s\dev\WindowsAppRuntime_BootstrapDLL\MddBootstrap.cpp(914)\Microsoft.WindowsAppRuntime.Bootstrap.dll!00007FFFA578B104: (caller: 00007FFFA5789404) LogHr(5) tid(9b8) 80040011 Not able to convert object
    Msg:[Bootstrap.Intitialize: Microsoft.WinAppRuntime.DDLM.2000.616.1852.0-x8-e2_2000.616.1852.0_x86__8wekyb3d8bbwe not applicable. Architecture doesn't match current architecture arm64 (Major.Minor=1.2, Tag=experimental2, MinVersion=0.0.0.0)] CallContext:[\Initialize] 
D:\a\_work\1\s\dev\WindowsAppRuntime_BootstrapDLL\MddBootstrap.cpp(946)\Microsoft.WindowsAppRuntime.Bootstrap.dll!00007FFFA578B560: (caller: 00007FFFA5789404) LogHr(6) tid(9b8) 80040013     Msg:[Bootstrap.Intitialize: Microsoft.WinAppRuntime.DDLM.2000.616.1852.0-a6-e2_2000.616.1852.0_arm64__8wekyb3d8bbwe best matches the criteria (Major.Minor=1.2, Tag=experimental2, MinVersion=0.0.0.0) of 95 packages scanned] CallContext:[\Initialize] 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\twinui.appcore.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\windows.storage.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\OneCoreUAPCommonProxyStub.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\SHCore.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\daxexec.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\userenv.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\container.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\usermgrcli.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\Windows.StateRepositoryClient.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\Windows.StateRepositoryPS.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\LicenseManagerApi.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\capauthz.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\ntmarta.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\shlwapi.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\propsys.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\Windows.FileExplorer.Common.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\windowsudk.shellcommon.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\xmllite.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\OneCoreCommonProxyStub.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\vaultcli.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\profapi.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\cfgmgr32.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\edputil.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\urlmon.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\iertutil.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\netutils.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\srvcli.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\cldapi.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\sspicli.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\AppResolver.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\BCP47Langs.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\mpr.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\execmodelproxy.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.WindowsAppRuntime.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\rometadata.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\powrprof.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\powrprof.dll'. 
'XamlIslandTest3.exe' (Win32): Unloaded 'C:\Windows\System32\powrprof.dll'
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\romd_arm64.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\umpdc.dll'. 
onecore\base\appmodel\runtime\src\lookup.cpp(218)\kernelbase.dll!00007FF837385DE0: (caller: 00007FF8373E2A10) ReturnHr(1) tid(9b8) 8007007A The data area passed to a system call is too small.
onecore\base\appmodel\runtime\src\lookup.cpp(218)\kernelbase.dll!00007FF837385DE0: (caller: 00007FF8373E2A10) ReturnHr(2) tid(9b8) 8007007A The data area passed to a system call is too small.
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.UI.Xaml.Controls.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\d2d1.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.ui.xaml.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\DWrite.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\d3d11.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\dxgi.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.Internal.FrameworkUdk.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\CoreMessaging.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\dcomp.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\Microsoft.Internal.FrameworkUdk.System.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\twinapi.appcore.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\CoreMessagingXP.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\Windows.UI.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\DXCore.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\ResourcePolicyClient.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\Windows.UI.Immersive.dll'. 
'XamlIslandTest3.exe' (Win32): Unloaded 'C:\Windows\System32\ResourcePolicyClient.dll'
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\directxdatabasehelper.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.Windows.ApplicationModel.Resources.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\MRM.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\qcdx8180.inf_arm64_df5df23ee5cd0b80\qcdx11arm64xum8180.dll'. 
onecoreuap\windows\frameworkudk\mrtcore.cpp(388)\Microsoft.Internal.FrameworkUdk.System.dll!00007FFFDA46E80C: (caller: 00007FFF977A64F0) ReturnHr(1) tid(9b8) 80073D54 The process has no package identity.
D:\a\_work\1\s\dev\DynamicDependency\API\PackageGraphManager.cpp(219)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA58E8: (caller: 00007FFF98D9BDD4) ReturnHr(1) tid(9b8) 8007007A The data area passed to a system call is too small.
D:\a\_work\1\s\dev\DynamicDependency\API\WinRTInprocModule.h(55)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA6ED8: (caller: 00007FFF98DA6A54) Exception(1) tid(9b8) 80004002 No such interface supported
    Msg:[Error 0x80004002 in ifactory->QueryInterface(Microsoft.UI.Xaml.Media.AcrylicBrush)] 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.WindowsAppRuntime.Insights.Resource.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\DriverStore\FileRepository\qcdx8180.inf_arm64_df5df23ee5cd0b80\qcdxarm64xcompiler8180.DLL'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\cryptbase.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\D3DSCache.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\TextShaping.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\BCP47mrm.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\Windows.Globalization.dll'. 
The thread 0x2754 has exited with code 0 (0x0).
Exception thrown at 0x00007FF8373C8D44 in XamlIslandTest3.exe: Microsoft C++ exception: wil::ResultException at memory location 0x00000099190F9790.
Exception thrown at 0x00007FF8373C8D44 in XamlIslandTest3.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
D:\a\_work\1\s\dev\DynamicDependency\API\MddWinRT.cpp(54)\Microsoft.WindowsAppRuntime.dll!00007FFF98DDF558: (caller: 00007FFF98DA9960) ReturnHr(2) tid(9b8) 80004002 No such interface supported
    Msg:[D:\a\_work\1\s\dev\DynamicDependency\API\WinRTInprocModule.h(55)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA6ED8: (caller: 00007FFF98DA6A54) Exception(1) tid(9b8) 80004002 No such interface supported
    Msg:[Error 0x80004002 in ifactory->QueryInterface(Microsoft.UI.Xaml.Media.AcrylicBrush)] 
] 
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\catalog.cpp(348)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA9984: (caller: 00007FFF98DACF08) ReturnHr(3) tid(9b8) 80004002 No such interface supported
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\catalog.cpp(334)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA999C: (caller: 00007FFF98DACF08) ReturnHr(4) tid(9b8) 80004002 No such interface supported
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\urfw.cpp(244)\Microsoft.WindowsAppRuntime.dll!00007FFF98DACEE8: (caller: 00007FFF97E3A39C) ReturnHr(5) tid(9b8) 80004002 No such interface supported
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.UI.Windowing.Core.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\msctf.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\dcompi.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\marshal.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.UI.Composition.OSSupport.dll'. 
'XamlIslandTest3.exe' (Win32): Unloaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.UI.Composition.OSSupport.dll'
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.UI.Composition.OSSupport.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\dwmcorei.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.InputStateManager.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\D3DCompiler_47.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\cryptsp.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.UI.Input.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\DataExchange.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\TextInputFramework.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\oleacc.dll'. 
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_arm64__8wekyb3d8bbwe\Microsoft.DirectManipulation.dll'. 
onecoreuap\windows\frameworkudk\dxprivatescommon.cpp(53)\Microsoft.Internal.FrameworkUdk.System.dll!00007FFFDA4623CC: (caller: 00007FFF977A6590) ReturnHr(2) tid(9b8) 80004002 No such interface supported
onecoreuap\windows\frameworkudk\dxprivatescommon.cpp(53)\Microsoft.Internal.FrameworkUdk.System.dll!00007FFFDA4623CC: (caller: 00007FFF977A6590) ReturnHr(3) tid(9b8) 80004002 No such interface supported
D:\a\_work\1\s\dev\DynamicDependency\API\WinRTInprocModule.h(55)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA6ED8: (caller: 00007FFF98DA6A54) Exception(2) tid(9b8) 80004002 No such interface supported
    Msg:[Error 0x80004002 in ifactory->QueryInterface(Microsoft.UI.Xaml.Controls.AnimatedIcon)] 
Exception thrown at 0x00007FF8373C8D44 in XamlIslandTest3.exe: Microsoft C++ exception: wil::ResultException at memory location 0x00000099190F7AD0.
Exception thrown at 0x00007FF8373C8D44 in XamlIslandTest3.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
D:\a\_work\1\s\dev\DynamicDependency\API\MddWinRT.cpp(54)\Microsoft.WindowsAppRuntime.dll!00007FFF98DDF558: (caller: 00007FFF98DA9960) ReturnHr(6) tid(9b8) 80004002 No such interface supported
    Msg:[D:\a\_work\1\s\dev\DynamicDependency\API\WinRTInprocModule.h(55)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA6ED8: (caller: 00007FFF98DA6A54) Exception(2) tid(9b8) 80004002 No such interface supported
    Msg:[Error 0x80004002 in ifactory->QueryInterface(Microsoft.UI.Xaml.Controls.AnimatedIcon)] 
] 
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\catalog.cpp(348)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA9984: (caller: 00007FFF98DACF08) ReturnHr(7) tid(9b8) 80004002 No such interface supported
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\catalog.cpp(334)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA999C: (caller: 00007FFF98DACF08) ReturnHr(8) tid(9b8) 80004002 No such interface supported
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\urfw.cpp(244)\Microsoft.WindowsAppRuntime.dll!00007FFF98DACEE8: (caller: 00007FFF97E3A39C) ReturnHr(9) tid(9b8) 80004002 No such interface supported
D:\a\_work\1\s\dev\DynamicDependency\API\WinRTInprocModule.h(55)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA6ED8: (caller: 00007FFF98DA6A54) Exception(3) tid(9b8) 80004002 No such interface supported
    Msg:[Error 0x80004002 in ifactory->QueryInterface(Microsoft.UI.Xaml.Controls.CommandBarFlyout)] 
Exception thrown at 0x00007FF8373C8D44 in XamlIslandTest3.exe: Microsoft C++ exception: wil::ResultException at memory location 0x00000099190F6C50.
Exception thrown at 0x00007FF8373C8D44 in XamlIslandTest3.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
D:\a\_work\1\s\dev\DynamicDependency\API\MddWinRT.cpp(54)\Microsoft.WindowsAppRuntime.dll!00007FFF98DDF558: (caller: 00007FFF98DA9960) ReturnHr(10) tid(9b8) 80004002 No such interface supported
    Msg:[D:\a\_work\1\s\dev\DynamicDependency\API\WinRTInprocModule.h(55)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA6ED8: (caller: 00007FFF98DA6A54) Exception(3) tid(9b8) 80004002 No such interface supported
    Msg:[Error 0x80004002 in ifactory->QueryInterface(Microsoft.UI.Xaml.Controls.CommandBarFlyout)] 
] 
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\catalog.cpp(348)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA9984: (caller: 00007FFF98DACF08) ReturnHr(11) tid(9b8) 80004002 No such interface supported
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\catalog.cpp(334)\Microsoft.WindowsAppRuntime.dll!00007FFF98DA999C: (caller: 00007FFF98DACF08) ReturnHr(12) tid(9b8) 80004002 No such interface supported
D:\a\_work\1\s\dev\UndockedRegFreeWinRT\urfw.cpp(244)\Microsoft.WindowsAppRuntime.dll!00007FFF98DACEE8: (caller: 00007FFF97E3A39C) ReturnHr(13) tid(9b8) 80004002 No such interface supported
onecoreuap\windows\frameworkudk\dxprivatescommon.cpp(53)\Microsoft.Internal.FrameworkUdk.System.dll!00007FFFDA4623CC: (caller: 00007FFF977A6590) ReturnHr(4) tid(1294) 80004002 No such interface supported
'XamlIslandTest3.exe' (Win32): Loaded 'C:\Windows\System32\cabinet.dll'. 
The thread 0x3798 has exited with code 0 (0x0).
The thread 0xc3c has exited with code 0 (0x0).
The thread 0x22d4 has exited with code 0 (0x0).
The thread 0x3720 has exited with code 0 (0x0).
The thread 0x250 has exited with code 0 (0x0).
The thread 0xee4 has exited with code 0 (0x0).
The thread 0x1474 has exited with code 0 (0x0).
The thread 0x1b04 has exited with code 0 (0x0).
The thread 0x1f98 has exited with code 0 (0x0).
The thread 0x387c has exited with code 0 (0x0).
The thread 0xf30 has exited with code 0 (0x0).
The thread 0x1a00 has exited with code 0 (0x0).
The thread 0x2c4c has exited with code 0 (0x0).
The thread 0x1ab8 has exited with code 0 (0x0).
The thread 0x1294 has exited with code 0 (0x0).
The thread 0x1778 has exited with code 0 (0x0).
The program '[13088] XamlIslandTest3.exe' has exited with code 0 (0x0).

For a successful run. I have the AcrylicBrush exception as well as two others (AnimatedIcon and CommandBarFlyout). So that isn't the issue. But after looking through the code again, I did find the issue. I did originally use it to test a couple of extra things, but I stripped them out. I missed one.

If you open mainwindow.cpp and check lines 87 and 88, you should find:

BOOL host_backdrop = TRUE;
THROW_IF_FAILED(DwmSetWindowAttribute(get_handle(), DWMWA_USE_HOSTBACKDROPBRUSH, &host_backdrop, sizeof(BOOL)));

This attribute is only available on Windows 11 21H2 and newer. For Windows 10, it would fail. It doesn't do anything for the application. My apologies about this.

Edit...
Looking at it, I was actually quite sloppy stripping unneeded things out.

XamlIslandTest3.zip

I have removed everything else that I could see that was unneeded for the demonstration of the Xaml Island. My apologies for this. This project was originally testing a few other things. Mica and Desktop Acrylic being one of them as well as figuring out a bug where the Xaml loader wouldn't recognise a property of the Acrylic brush.

@tomaszkot
Copy link
Author

Thank you, now it compiles and runs.

Now I grabbed the idl code you provided above for DesktopWindowXamlSource put it into idl file in the project.
When trying to compile, lots of errors occured.

Added a reference to the C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.22621.0\Windows.winmd

Now it compiles for a while and gives:
...
1>Processing WinMD c:\program files (x86)\windows kits\10\references\10.0.22621.0\windows.web.http.diagnostics.httpdiagnosticscontract\2.0.0.0\windows.web.http.diagnostics.httpdiagnosticscontract.winmd
1>
1>midl : error MIDL9008: internal compiler problem - See documentation for suggestions on how to find a workaround.
1>midl: Assertion failed: node == nullptr, file com\rpc\midl\midlrt\metaread\metadataparser.cxx, line 216
1>Done building project "XamlIslandTest3.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

@DarranRowe
Copy link

That is why, if you check the sample project that I gave, there is no extra reference to the Windows metadata.
I would have to double check, but I think it is C++/WinRT adding the metadata reference automatically. This means that there ends up being multiply defined symbols, and midlrt just gets really crashy in these cases.

@tomaszkot
Copy link
Author

Without adding that reference when trying to compile idl files I get:

Severity Code Description Project File Line Suppression State
Error MIDL2025 [msg]syntax error [context]: expecting . near "(" XamlIslandTest3 D:\tmp\XamlIslandTest3\XamlIslandTest3\XamlIslandTest3\DesktopWindowXamlSource.idl 1
Error MIDL2009 [msg]undefined symbol [context]: composable.Microsoft.UI.Xaml.Hosting.IDesktopWindowXamlSourceFactory XamlIslandTest3 D:\tmp\XamlIslandTest3\XamlIslandTest3\XamlIslandTest3\DesktopWindowXamlSource.idl 1
Error MIDL2009 [msg]undefined symbol [context]: Microsoft.UI.Xaml.Hosting.HostingContract XamlIslandTest3 D:\tmp\XamlIslandTest3\XamlIslandTest3\XamlIslandTest3\DesktopWindowXamlSource.idl 1
Error MIDL2025 [msg]syntax error [context]: expecting ] or , near "1.0" XamlIslandTest3 D:\tmp\XamlIslandTest3\XamlIslandTest3\XamlIslandTest3\DesktopWindowXamlSource.idl 1
Error MIDL2025 [msg]syntax error [context]: expecting . near "]" XamlIslandTest3 D:\tmp\XamlIslandTest3\XamlIslandTest3\XamlIslandTest3\DesktopWindowXamlSource.idl 3
Error MIDL2026 [msg]cannot recover from earlier syntax errors; aborting compilation XamlIslandTest3 D:\tmp\XamlIslandTest3\XamlIslandTest3\XamlIslandTest3\DesktopWindowXamlSource.idl 4

@pratikone pratikone added documentation An issue with existing documentation or a request for documenation of a new topic question area-Islands Xaml Islands feature and removed feature proposal New feature proposal needs-triage Issue needs to be triaged by the area owners labels Oct 11, 2022
@DarranRowe
Copy link

Ok, in wanting to solve the midl error, I didn't read your post fully.
You don't have to use the IDL for DesktopWindowXamlSource or WindowsXamlManager. Just by referencing the Windows App SDK Nuget package, Visual Studio will reference all of the .winmd files in the Windows App SDK. The hosting classes, which DesktopWindowXamlSource and WindowsXamlManager are part of, are in Microsoft.UI.Xaml.winmd.

This is verifiable. If you set the Visual Studio build log to diagnostic, you can find the midl command line.

Screenshot 2022-10-11 233036

The command line contains the name of the response (.rsp) file.

Screenshot 2022-10-11 233109

This is the path on my system. It is relative to where the file is stored. This response file contains all of the references that midl uses. For my system, this file starts off as:

/reference "C:\Users\Darran\source\repos\XamlIslandTest3\packages\Microsoft.WindowsAppSDK.1.2.220909.2-experimental2\lib\uap10.0.18362\Microsoft.Foundation.winmd"
/reference "C:\Users\Darran\source\repos\XamlIslandTest3\packages\Microsoft.WindowsAppSDK.1.2.220909.2-experimental2\lib\uap10.0.18362\Microsoft.Graphics.winmd"
/reference "C:\Users\Darran\source\repos\XamlIslandTest3\packages\Microsoft.WindowsAppSDK.1.2.220909.2-experimental2\lib\uap10.0\Microsoft.UI.Text.winmd"
/reference "C:\Users\Darran\source\repos\XamlIslandTest3\packages\Microsoft.WindowsAppSDK.1.2.220909.2-experimental2\lib\uap10.0.18362\Microsoft.UI.winmd"
/reference "C:\Users\Darran\source\repos\XamlIslandTest3\packages\Microsoft.WindowsAppSDK.1.2.220909.2-experimental2\lib\uap10.0\Microsoft.UI.Xaml.winmd"

Where Microsoft.UI.Xaml.winmd is quite high up. The response file is used because of the Windows command line limit, so it is better to use a response file to pass in lots of command line options if the executable looks out for it. But it is equivalent to passing all of these options on the command line. I showed the runtime class definitions above to illustrate their presence, but it would be rare to want to use the in idl form. The idl definitions were extracted from the generated files, so they were incomplete.

C++/WinRT is the expected way to use WinRT these days, and midl references the metadata directly, so you don't need to have separate idl files to use the Xaml Island classes and interfaces in your own components. As an example, if the IslandApplication runtime class is modified as follows:

[default_interface]
runtimeclass IslandApplication : Microsoft.UI.Xaml.Application, IXamlMetadataContainer, Windows.Foundation.IClosable
{
	IslandApplication(Windows.Foundation.Collections.IVector<Microsoft.UI.Xaml.Markup.IXamlMetadataProvider> providers);
	protected IslandApplication();
	protected void Initialize();

	//note, this is now WindowsXamlManager
	Microsoft.UI.Xaml.Hosting.WindowsXamlManager WindowsXamlManager{ get; };
	Boolean IsDisposed{ get; };
};

then this idl file will compile with a warning. The warning is that since you are using an experimental type in a runtime class, the runtime class itself must be marked as experimental.

//add the experimental attribute to the runtime class
[experimental]
[default_interface]
runtimeclass IslandApplication : Microsoft.UI.Xaml.Application, IXamlMetadataContainer, Windows.Foundation.IClosable
{
	IslandApplication(Windows.Foundation.Collections.IVector<Microsoft.UI.Xaml.Markup.IXamlMetadataProvider> providers);
	protected IslandApplication();
	protected void Initialize();

	//note, this is now WindowsXamlManager
	Microsoft.UI.Xaml.Hosting.WindowsXamlManager WindowsXamlManager{ get; };
	Boolean IsDisposed{ get; };
};

That was actually the reason why I used IClosable there. The only useful operation on WindowsXamlManager is Close, InitializeForCurrentThread is a static and is used to create the instance. This means that the runtime class can reference IClosable and not require the experimental attribute. Obviously, doing this will require modifications to the IslandApplication.h and IslandApplication.cpp files.

C++/WinRT picks these classes up too. If you look at the Microsoft.UI.Xaml.Hosting.h file that C++/WinRT generates (it is under (project root)(platform)(configuration)\Generated Files, where project root is the directory where the .vcxproj is, you will find that C++/WinRT has generated wrappers for the runtime classes and interfaces there. The sample uses these particular classes directly. IslandApplication.h has a variable named m_xamlmanager of type winrt::Microsoft::UI::Xaml::Hosting::WindowsXamlManager. Using these types with C++/WinRT and the Windows App SDK packages doesn't require much else.

If you were trying to use the idl definitions because it wasn't clear that you didn't need to use them, then you don't need to use them. As mentioned, Visual Studio will reference the correct .winmd file automatically meaning midl and C++/WinRT will just automatically use them.
If you were trying to use the definitions because you cannot use C++/WinRT in your application, then that will require a completely different tutorial on how to generate the ABI headers for the Windows App SDK.

@tomaszkot
Copy link
Author

tomaszkot commented Oct 12, 2022

Thank you.
I then included the IslandApplication.idl file to my MFC project.
I made sure Windows SDK is 1.2.220930.4-preview2 tried to compile and got:

image

Then I reviewed properties of MFC project against XamlIslandTest3, did a few changes, but the error still remains.
I updated repo with my recent changes, the project file is also attached here:
MFCApplication1.vcxproj.txt

I also compared "Generated Files" folders and they differ a bit - but why - I do not know.

@DarranRowe
Copy link

As I said previously, Xaml Islands are currently an experimental feature. This means that they are only in experimental versions of the Windows App SDK. For 1.2, this means 1.2.220727.1-experimental1 and 1.2.220909.2-experimental2 only.
Also, are those just intellisense errors? Does the compile itself fail? The Visual C++ intellisense can be slow to pick up generated code.

If it is just intellisense errors, then just force Visual Studio to rescan the solution.

Screenshot 2022-10-12 100804

Selecting Rescan Solution will cause Visual Studio to dump all intellisense information and then rebuild it from the solution.

@tomaszkot
Copy link
Author

tomaszkot commented Oct 12, 2022

As I said previously, Xaml Islands are currently an experimental feature. This means that they are only in experimental versions of the Windows App SDK. For 1.2, this means 1.2.220727.1-experimental1 and 1.2.220909.2-experimental2 only.

Yes, I noticed that but did not update the post. I changed it to be 1.2.220909.2-experimental2, but still not helped.
image

Also, are those just intellisense errors? Does the compile itself fail? The Visual C++ intellisense can be slow to pick up generated code. If it is just intellisense errors, then just force Visual Studio to rescan the solution.

Sorry I did not provided exact error, no it's not intellisense , it's a compiler error:
image

Here is the solution you provided with that MFC project added:
XamlIslandTest3WithMFC.zip

Selecting Rescan Solution will cause Visual Studio to dump all intellisense information and then rebuild it from the solution.

Thank you, I did not know the trick, might be handy.

@tomaszkot
Copy link
Author

tomaszkot commented Oct 12, 2022

Putting aside MFC example I tried to host User Control in this XamlIslandTest3 project.

So I did (added parts bolded):

`winrt::Microsoft::UI::Xaml::Hosting::DesktopWindowXamlSource _desktopWindowXamlSource{ nullptr };
bool main_window::create_window(int cmdshow)
{
register_window_class();
...
ShowWindow(window_handle, cmdshow);
UpdateWindow(window_handle);

_desktopWindowXamlSource = winrt::Microsoft::UI::Xaml::Hosting::DesktopWindowXamlSource();
auto interop = _desktopWindowXamlSource.as();
interop->AttachToWindow(window_handle);
`

At this point app started.

Then I added to the solution a project WinUIComponentCs created as described at:
https://learn.microsoft.com/en-us/windows/apps/develop/platform/csharp-winrt/create-winrt-component-winui-cswinrt

and tried this:
_desktopWindowXamlSource = winrt::Microsoft::UI::Xaml::Hosting::DesktopWindowXamlSource();
auto interop = _desktopWindowXamlSource.as();
interop->AttachToWindow(window_handle);
winrt::WinUIComponentCs::NameReporter reporter;
_desktopWindowXamlSource.Content(reporter);

App is crashing with:
'XamlIslandTest3.exe' (Win32): Loaded 'E:\Projects\OT\Bruker_src\OpusTouch\dev\Sources\WinUI\WinUIComponentCsVS2022\Debug\WinUIComponentCs.dll'.
D:\a_work\1\s\dev\UndockedRegFreeWinRT\catalog.cpp(65)\Microsoft.WindowsAppRuntime.dll!7B44B10D: (caller: 7B44BCF5) ReturnHr(6) tid(5e04) 8007007F The specified procedure could not be found.
D:\a_work\1\s\dev\UndockedRegFreeWinRT\catalog.cpp(337)\Microsoft.WindowsAppRuntime.dll!7B44BC36: (caller: 7B44DFE7) ReturnHr(7) tid(5e04) 8007007F The specified procedure could not be found.
D:\a_work\1\s\dev\UndockedRegFreeWinRT\urfw.cpp(244)\Microsoft.WindowsAppRuntime.dll!7B44DFCD: (caller: 00B24DE9) ReturnHr(8) tid(5e04) 8007007F The specified procedure could not be found.
E:\Projects\OT\Bruker_src\OpusTouch\dev\Sources\WinUI\WinUIComponentCsVS2022\XamlIslandTest3\Debug\Generated Files\winrt\base.h(6126)\XamlIslandTest3.exe!00B16CBA: LogHr(1) tid(5e04) 8007007F The specified procedure could not be found.
[get_activation_factory]
E:\Projects\OT\Bruker_src\OpusTouch\dev\Sources\WinUI\WinUIComponentCsVS2022\XamlIslandTest3\Debug\Generated Files\winrt\base.h(6126)\XamlIslandTest3.exe!00AFAAE9: LogHr(2) tid(5e04) 8007007F The specified procedure could not be found.
[get_activation_factory]
Exception thrown at 0x7625DF72 (KernelBase.dll) in XamlIslandTest3.exe: WinRT originate error - 0x8007007F : 'The specified procedure could not be found.'.
Exception thrown at 0x7625DF72 in XamlIslandTest3.exe: Microsoft C++ exception: winrt::hresult_error at memory location 0x008FF190.

Original Walkthrough witn WinUI example has such point:

<!--In order to host the C# component from C++, you must add the following Extension group and list the activatable classes-->
<Extensions>
    <Extension Category="windows.activatableClass.inProcessServer">
        <InProcessServer>
            <Path>WinRT.Host.dll</Path>
            <ActivatableClass ActivatableClassId="WinUIComponentCs.NameReporter" ThreadingModel="both" />
            <ActivatableClass ActivatableClassId="WinUIComponentCs.WinUIComponentCs_XamlTypeInfo.XamlMetaDataProvider" ThreadingModel="both" />
        </InProcessServer>
    </Extension>
</Extensions>

I'm wondering if that also is relevant in this case, the change was in Package.appxmanifest which win32 app is not having?

@DarranRowe
Copy link

Well, for the entire MFC thing. I didn't have a clue.
I installed the MFC libraries for Visual Studio, tried the project and it failed. I looked at the source around what was being shown, and I eventually noticed something:

Screenshot 2022-10-12 191441

Notice the colouring on TRY there? That means it is a definition of some kind, and in this case, it is a macro defined by MFC. So, I disabled precompiled headers for the MFC project, moved the C++/WinRT headers out of pch.h and into a separate header, then I included that into IslandApplication.cpp, replacing pch.h in that file. It compiled fine.

This is a simple case of the macros defined by MFC interfering with the C++/WinRT headers.

For the second case, try looking at this.

@tomaszkot
Copy link
Author

Thank you for a MFC hint, it really helped. Macros are evil.

But creation of instance of User Control still crashes.
I'm not sure what exactly was to be applied from the link you provided.
I already had an entry in manifest
image

Adding this was quite obvious as error was:
\XamlIslandTest3\Debug\Generated Files\winrt\base.h(6126)\XamlIslandTest3.exe!00F96D9A: LogHr(1) tid(a4c) 80040154 Class not registered
[get_activation_factory]

While the error I'm facing is:
XamlIslandTest3\Debug\Generated Files\winrt\base.h(6126)\XamlIslandTest3.exe!00636D9A: LogHr(1) tid(5fd4) 8007007F The specified procedure could not be found.
[get_activation_factory]

I added Microsoft.VCRTForwarders.140, but it did not helped.

@tomaszkot
Copy link
Author

Here is the project.
XamlIslandTest3 creates that C# User Control, but it crashes.

XamlIslandTest3CsCrash.zip

@DarranRowe
Copy link

DarranRowe commented Oct 17, 2022

Well, after having a little look at various pieces of documentation and inferring from there, it wasn't that hard to get it working.
If you look at the page that you linked for the component, you should have noticed how the C# component was registered:

<!--In order to host the C# component from C++, you must add the following Extension group and list the activatable classes-->
<Extensions>
    <Extension Category="windows.activatableClass.inProcessServer">
        <InProcessServer>
            <Path>WinRT.Host.dll</Path>
            <ActivatableClass ActivatableClassId="WinUIComponentCs.NameReporter" ThreadingModel="both" />
            <ActivatableClass ActivatableClassId="WinUIComponentCs.WinUIComponentCs_XamlTypeInfo.XamlMetaDataProvider" ThreadingModel="both" />
        </InProcessServer>
    </Extension>
</Extensions>

more specifically, the file name.

Using:

  <file name="WinRT.Host.dll">
    <activatableClass name="WinUIComponentCs.NameReporter" threadingModel="both" xmlns="urn:schemas-microsoft-com:winrt.v1"></activatableClass>
    <activatableClass name="WinUIComponentCs.NameReporterModel" threadingModel="both" xmlns="urn:schemas-microsoft-com:winrt.v1"></activatableClass>
    <activatableClass name="WinUIComponentCs.WinUIComponentCs_XamlTypeInfo.XamlMetaDataProvider" threadingModel="both" xmlns="urn:schemas-microsoft-com:winrt.v1"></activatableClass>
  </file>

as the registration free WinRT registration allows the component to load successfully. There is still a couple of things that I need to do to get things working again properly, but that is what normally happens when you have to reinstall Windows.

---Edit---

Well, after a little more work:

Screenshot 2022-10-17 202432

I am able to load the control and create a new Xaml source for it.

@tomaszkot
Copy link
Author

Thank you, that's exactly what I suspected is lacking

image

@tomaszkot
Copy link
Author

Tried it, changed settings.manifest into XamlIslandTest3.exe.manifest to workaround linker error, and it's crashing :/

image

@DarranRowe
Copy link

That is curious.

Well, this is also one of the annoyances of working with code that you didn't write, also the sample was only ever written to show the initialisation of Xaml Islands.

Anyway, getting things in the right place is key. If you don't do that, and especially don't clean things up properly after you then it does get rather crashy. I guess this is still one of the reasons why Xaml Islands is considered experimental.

@tomaszkot
Copy link
Author

Thx again I think we are close to resolve it.

I took the XamlIslandTest3.zip you posted 8 days ago and somehow the button created in the main_window::on_create is not visible in the main window.

image

@tomaszkot
Copy link
Author

I have the impression it due to the fact I'm using Win10.

@tomaszkot
Copy link
Author

image

So it's there but somehow not visible.
Weird...

@tomaszkot
Copy link
Author

So after forcing manually styles inside the C# control I was able to see it:
image

Yet, events are not arriving (can not focus textbox, can not click a button). There is a lot of low level stuff of there (window_base.cpp, main_window.cpp). I suppose some it it is not working.

@DarranRowe
Copy link

Well, without knowing what you have and have not done then it is tough to say.

Since I am technically on holiday now, I'll give you a bit of a run through about how bad the entire situation is in general.

There is no really good source of information for Xaml Islands in general. The UWP Xaml Islands samples, which was the starting point of this work, are terrible.
The samples only provide enough to get UWP Xaml working, and the code itself is uncommented and doesn't work right anyway. When I started my great adventure into these uncharted waters, it was mostly as a hobby and a huge amount of time went into figuring the code out.
Anyway, as I stated, this sample isn't enough to get WinUI working. This is true of WinUI 3, and it was true for WinUI 2. So, work had to go into figuring out how to load WinUI 2.

After a bit of looking around, I found reference to the XamlApplication class in the Microsoft Community Toolkit. This is what IslandApplication is based upon. But this was one of the requirements to get WinUI loaded. Interestingly, this class also had its own problems. When I was originally figuring things out, I was working with composition in the same application. The XamlApplication class was actually using the presence of a DispatcherQueue to determine if the application was a desktop or UWP application.

The WinUI 3 work ended up being figuring out any differences between WinUI 2 and WinUI 3 and then changing the namespaces. There were some requirement differences. WinUI 2 needed to be loaded using the Dynamic Dependency API, the resources needed to be merged into the main resources.pri and there was also an interface difference. But this actually made working with WinUI 3 a bit easier.

While I was at it, I also ended up running into a few bugs too. For example, the Dynamic Dependency API included with the Windows App SDK has an issue where if you try to use the registry or a file to control the lifetime of the dependency, it throws an exception. This works fine with the Windows 11 built in API though. So obviously I had to report this.

Another bug that I ended up running into is in DesktopWindowXamlSource itself. There is an event named GotFocus which is documented to fire when the source receives focus. This never fires.

Anyway, I finally managed to get the time to update the project and upload it to GitHub. The repository is here. But be warned, I ran across another bug, this time it is in the WinUI 3 DesktopWindowXamlHost. The TakeFocusRequested event isn't firing, so this won't allow you to navigate out of a xaml source. This was part of the reason why I took so long to reply, I was also getting the original WinUI 2 sample into a form that could be used to show that the bug exists.

@tomaszkot
Copy link
Author

At my pc that middle button is not visible:
image

After forcing styles it's working a bit - sometimes is visible , sometimes disappears (if I click it).
Most likely win10 related issue - maybe someone having win10 could confirm that.

I'm going to wait for a official release from Microsoft, currently there is too much effort needed, and to much low level windows messaging related code involved.

Talking about examples quality that repo (subfolder XamlIslands-master\1903_Samples\CppWinRT_Win32_App) has a code that tries to create a User Control with a different approach - it's created inside Windows Runtime Component.
Code in win32 app is like:
m_managedControl = winrt::SampleLibraryCS::CustomUserControl(); m_managedControl.Height(ButtonHeight / dpi); m_managedControl.Width(ButtonWidth / dpi); m_hWndXamlButton1 = wil::unique_hwnd(CreateDesktopWindowsXamlSource(WS_TABSTOP, m_managedControl));

Yet, app is crashing at the startup.
It seemed to me a trick mentioned there (adding
true to the proj) would help , but it is still not working.

@tomaszkot
Copy link
Author

tomaszkot commented Oct 27, 2022

As a proof if that is a win10/11 issue I tried to compile it on win11 machine but got:

Severity Code Description Project File Line Suppression State
Error MSB4062 The "Microsoft.Build.Packaging.Pri.Tasks.ExpandPriContent" task could not be loaded from the assembly C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VisualStudio\v17.0\AppxPackage\Microsoft.Build.Packaging.Pri.Tasks.dll. Could not load file or assembly 'file:///C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Microsoft\VisualStudio\v17.0\AppxPackage\Microsoft.Build.Packaging.Pri.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. XamlIslandTest3 C:\Users\Joanna K\Desktop\testTomekKot\XamlIslandTest3\XamlIslandTest3\packages\Microsoft.WindowsAppSDK.1.2.220909.2-experimental2\build\MrtCore.PriGen.targets 911

Also tried a hint from https://learn.microsoft.com/en-us/windows/apps/windows-app-sdk/experimental-channel

Using dotnet build with a WinAppSDK C# class library project may see a build error "Microsoft.Build.Packaging.Pri.Tasks.ExpandPriContent task could not be loaded". To resolve this issue set true in your project file.

but it's still not compiling.

@DarranRowe
Copy link

From the XamlIslandTest3 build output with the log file set to Diagnostic on Windows 11:

1>Target "AddPriPayloadFilesToCopyToOutputDirectoryItems" in file "C:\Users\Darran\source\repos\XamlIslandTest3\packages\Microsoft.WindowsAppSDK.1.2.220909.2-experimental2\build\MrtCore.PriGen.targets":
1>  Using "ExpandPriContent" task from assembly "D:\Programs64\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VisualStudio\v17.0\AppxPackage\\Microsoft.Build.Packaging.Pri.Tasks.dll".
1>  Task "ExpandPriContent"
1>    Task Parameter:MakePriExeFullPath=C:\Users\Darran\source\repos\XamlIslandTest3\packages\Microsoft.Windows.SDK.BuildTools.10.0.22621.1\bin\10.0.22621.0\x64\makepri.exe
1>    Task Parameter:IntermediateDirectory=x64\Debug\
1>    Task Parameter:ExcludeXamlFromLibraryLayoutsWhenXbfIsPresent=True
1>    Task execution duration: 287 ms.
1>  Done executing task "ExpandPriContent".
1>Done building target "AddPriPayloadFilesToCopyToOutputDirectoryItems" in project "XamlIslandTest3.vcxproj".

There is a few more using that library, but it is loading and using the pri tasks library without issue. So, are you sure this is a Windows problem?

Both versions of Windows 11 (initial release and 22H2) have no issue building here at all. I also don't have a particularly complex Visual Studio install either.

@tomaszkot
Copy link
Author

So, are you sure this is a Windows problem?

I might not described problems precisely. So there are two separate problems:

  1. The application is not working on win10 machines. I tested it on two machines and on both that User Control is not rendered (without forcing styles).

There are some 'No such interface supported' messages in the output, maybe they are saying it's basically not meant to be run on win10.

XamlIslandTest3.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.WindowsAppRuntime.1.2-experimental2_2000.616.1852.0_x64__8wekyb3d8bbwe\MRM.dll'.
onecoreuap\windows\frameworkudk\mrtcore.cpp(388)\Microsoft.Internal.FrameworkUdk.dll!00007FFF5F7656D8: (caller: 00007FFF5F79F08D) ReturnHr(1) tid(6448) 80073D54 The process has no package identity.
D:\a_work\1\s\dev\DynamicDependency\API\PackageGraphManager.cpp(219)\Microsoft.WindowsAppRuntime.dll!00007FFF60C7B41E: (caller: 00007FFF60C71C59) ReturnHr(1) tid(6448) 8007007A The data area passed to a system call is too small.
D:\a_work\1\s\dev\DynamicDependency\API\WinRTInprocModule.h(55)\Microsoft.WindowsAppRuntime.dll!00007FFF60C7CCEC: (caller: 00007FFF60C7C38A) Exception(1) tid(6448) 80004002 No such interface supported
Msg:[Error 0x80004002 in ifactory->QueryInterface(Microsoft.UI.Xaml.Media.AcrylicBrush)]
D:\a_work\1\s\dev\DynamicDependency\API\MddWinRT.cpp(54)\Microsoft.WindowsAppRuntime.dll!00007FFF60CADD55: (caller: 00007FFF60C7EC1F) ReturnHr(2) tid(6448) 80004002 No such interface supported
Msg:

  1. Compilation problem on win11 - I have limited access to this machine, but I'd try to get more info soon.

@tomaszkot
Copy link
Author

image

I finally got it working on Win11. Initially I did not have that Experimental Windows App SDK.

Summing up (to get idea without reading the whole thread):

  • It works on Win11
  • Requires Experimental Windows App SDK
  • Requires quite a lot of custom code that you had to figure out and provided in the XamlIslandTest3 project

@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 3, 2023
@tomaszkot
Copy link
Author

Tried again with [Windows App SDK, looks like it could work but there is strange exception, code at: https://github.com/microsoft/WindowsAppSDK-Samples/issues/328

@microsoft-github-policy-service microsoft-github-policy-service bot added the needs-triage Issue needs to be triaged by the area owners label Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Islands Xaml Islands feature documentation An issue with existing documentation or a request for documenation of a new topic needs-triage Issue needs to be triaged by the area owners no-issue-activity question
Projects
None yet
Development

No branches or pull requests

3 participants