https://github.com/pdawg-bytes/winrtcorewindow
Hosting a raw CoreWindow on hWnd from C# or C++.
https://github.com/pdawg-bytes/winrtcorewindow
abi corewindow cpp csharp windows winrt winrtxaml wrl wux
Last synced: 6 months ago
JSON representation
Hosting a raw CoreWindow on hWnd from C# or C++.
- Host: GitHub
- URL: https://github.com/pdawg-bytes/winrtcorewindow
- Owner: Pdawg-bytes
- License: mit
- Created: 2024-04-01T03:01:31.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-30T03:29:15.000Z (over 1 year ago)
- Last Synced: 2025-04-11T20:04:23.063Z (12 months ago)
- Topics: abi, corewindow, cpp, csharp, windows, winrt, winrtxaml, wrl, wux
- Language: C#
- Homepage:
- Size: 19.5 KB
- Stars: 10
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WinRTCoreWindow
Hosting a raw CoreWindow on hWnd from C# or C++.
## Projects
### WinRTCoreWindow.vcxproj
This is the project containing the C++ version of the code.
### CoreWindowSharp.csproj
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.
# How does it work?
### C++:
1. Load `Windows.UI.dll` and extract a function pointer out of it pointing to a private function (`CreateCoreWindow`).
2. Cast that into the `PrivateCreateCoreWindow` delegate
3. Init winrt (`winrt::init_apartment()`)
4. Create a standard hWnd window (`CreateWindowEx` and `WNDCLASS`)
5. Create a GUID referring to CoreWindow.
6. Call the func pointer delegate, passing in the handle of that hWnd window and the GUID.
7. Initialize the `XamlPresenter` (found in the internal version of `Windows.UI.Xaml.Hosting`)
8. Init winrt components and set the content of the `XamlPresenter`.
9. Init `ICoreDispatcher` with ptr to CoreWindow dispatcher
10. Process dispatcher messages.
### C#:
1. `DllImport` the `Windows.UI.dll` library at ordinal 1500.
2. Create a standard hWnd window (`CreateWindowEx` and `WNDCLASSEX`)
3. 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.)
4. Set the `ICoreWindow` instance to `CoreWindow.GetForCurrentThread()`.
5. Initialize the `XamlPresenter` (found in the internal version of `Windows.UI.Xaml.Hosting`).
6. Init winrt components and set the content of the `XamlPresenter`.
7. Extract the `ICoreDispatcher` as a `Windows.UI.Core.CoreDispatcher`.
8. Command `CoreDispatcher` to start processing dispatcher messages.
# Demo
