Hosting a raw CoreWindow on hWnd from C# or C++.
This is the project containing the C++ version of the code.
This is the project containing the C# version of the code.
Note
There are minor differences between the two to conform to each languages' standards, but they both achieve the same end result.
- Load
Windows.UI.dll
and extract a function pointer out of it pointing to a private function (CreateCoreWindow
). - Cast that into the
PrivateCreateCoreWindow
delegate - Init winrt (
winrt::init_apartment()
) - Create a standard hWnd window (
CreateWindowEx
andWNDCLASS
) - Create a GUID referring to CoreWindow.
- Call the func pointer delegate, passing in the handle of that hWnd window and the GUID.
- Initialize the
XamlPresenter
(found in the internal version ofWindows.UI.Xaml.Hosting
) - Init winrt components and set the content of the
XamlPresenter
. - Init
ICoreDispatcher
with ptr to CoreWindow dispatcher - Process dispatcher messages.
DllImport
theWindows.UI.dll
library at ordinal 1500.- Create a standard hWnd window (
CreateWindowEx
andWNDCLASSEX
) - Call
CreateCoreWindow
on the main thread and discard its output. (It's still initialized on the thread, so we don't need the output directly.) - Set the
ICoreWindow
instance toCoreWindow.GetForCurrentThread()
. - Initialize the
XamlPresenter
(found in the internal version ofWindows.UI.Xaml.Hosting
). - Init winrt components and set the content of the
XamlPresenter
. - Extract the
ICoreDispatcher
as aWindows.UI.Core.CoreDispatcher
. - Command
CoreDispatcher
to start processing dispatcher messages.