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.dlland extract a function pointer out of it pointing to a private function (CreateCoreWindow). - Cast that into the
PrivateCreateCoreWindowdelegate - Init winrt (
winrt::init_apartment()) - Create a standard hWnd window (
CreateWindowExandWNDCLASS) - 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
ICoreDispatcherwith ptr to CoreWindow dispatcher - Process dispatcher messages.
DllImporttheWindows.UI.dlllibrary at ordinal 1500.- Create a standard hWnd window (
CreateWindowExandWNDCLASSEX) - Call
CreateCoreWindowon the main thread and discard its output. (It's still initialized on the thread, so we don't need the output directly.) - Set the
ICoreWindowinstance 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
ICoreDispatcheras aWindows.UI.Core.CoreDispatcher. - Command
CoreDispatcherto start processing dispatcher messages.
