THIS WORKS, if you paste M.T.Core.winmd into the appx manually

This commit is contained in:
Mike Griese 2021-05-05 10:22:37 -05:00
parent b4f842ecba
commit 1fcef41871
17 changed files with 353 additions and 19 deletions

View file

@ -31,6 +31,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Common Props", "Common Prop
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fmt", "src\dep\fmt\fmt.vcxproj", "{6BAE5851-50D5-4934-8D5E-30361A8A40F3}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Types", "src\types\lib\types.vcxproj", "{18D09A24-8240-42D6-8CB6-236EEE820263}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dependencies", "dependencies", "{75AC9360-76FD-4ABC-AFEC-EF342BD2B3E9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
AuditMode|ARM64 = AuditMode|ARM64
@ -179,10 +183,38 @@ Global
{6BAE5851-50D5-4934-8D5E-30361A8A40F3}.Release|x64.Build.0 = Release|x64
{6BAE5851-50D5-4934-8D5E-30361A8A40F3}.Release|x86.ActiveCfg = Release|Win32
{6BAE5851-50D5-4934-8D5E-30361A8A40F3}.Release|x86.Build.0 = Release|Win32
{18D09A24-8240-42D6-8CB6-236EEE820263}.AuditMode|ARM64.ActiveCfg = AuditMode|ARM64
{18D09A24-8240-42D6-8CB6-236EEE820263}.AuditMode|ARM64.Build.0 = AuditMode|ARM64
{18D09A24-8240-42D6-8CB6-236EEE820263}.AuditMode|x64.ActiveCfg = AuditMode|x64
{18D09A24-8240-42D6-8CB6-236EEE820263}.AuditMode|x64.Build.0 = AuditMode|x64
{18D09A24-8240-42D6-8CB6-236EEE820263}.AuditMode|x86.ActiveCfg = AuditMode|Win32
{18D09A24-8240-42D6-8CB6-236EEE820263}.AuditMode|x86.Build.0 = AuditMode|Win32
{18D09A24-8240-42D6-8CB6-236EEE820263}.Debug|ARM64.ActiveCfg = Debug|ARM64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Debug|ARM64.Build.0 = Debug|ARM64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Debug|x64.ActiveCfg = Debug|x64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Debug|x64.Build.0 = Debug|x64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Debug|x86.ActiveCfg = Debug|Win32
{18D09A24-8240-42D6-8CB6-236EEE820263}.Debug|x86.Build.0 = Debug|Win32
{18D09A24-8240-42D6-8CB6-236EEE820263}.Fuzzing|ARM64.ActiveCfg = Fuzzing|ARM64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Fuzzing|ARM64.Build.0 = Fuzzing|ARM64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Fuzzing|x64.ActiveCfg = Fuzzing|x64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Fuzzing|x64.Build.0 = Fuzzing|x64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Fuzzing|x86.ActiveCfg = Fuzzing|Win32
{18D09A24-8240-42D6-8CB6-236EEE820263}.Fuzzing|x86.Build.0 = Fuzzing|Win32
{18D09A24-8240-42D6-8CB6-236EEE820263}.Release|ARM64.ActiveCfg = Release|ARM64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Release|ARM64.Build.0 = Release|ARM64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Release|x64.ActiveCfg = Release|x64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Release|x64.Build.0 = Release|x64
{18D09A24-8240-42D6-8CB6-236EEE820263}.Release|x86.ActiveCfg = Release|Win32
{18D09A24-8240-42D6-8CB6-236EEE820263}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{6BAE5851-50D5-4934-8D5E-30361A8A40F3} = {75AC9360-76FD-4ABC-AFEC-EF342BD2B3E9}
{18D09A24-8240-42D6-8CB6-236EEE820263} = {75AC9360-76FD-4ABC-AFEC-EF342BD2B3E9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {05EAE315-9188-4D7B-B889-7D5F480A8915}
EndGlobalSection

View file

@ -48,6 +48,7 @@
<Import Project="$(OpenConsoleDir)src\wap-common.build.post.props" />
<ItemGroup>
<ProjectReference Include="..\WindowExe\WindowExe.vcxproj" />
<!-- <ProjectReference Include="$(OpenConsoleDir)src\cascadia\WindowsTerminal\WindowsTerminal.vcxproj" /> -->
</ItemGroup>
<ItemGroup>

View file

@ -3,9 +3,11 @@
#include "pch.h"
#include "MyPage.h"
#include "MySettings.h"
#include <LibraryResources.h>
#include "MyPage.g.cpp"
#include "..\..\..\src\cascadia\UnitTests_Control\MockControlSettings.h"
#include "..\..\..\src\types\inc\utils.hpp"
using namespace std::chrono_literals;
using namespace winrt::Microsoft::Terminal;
@ -32,6 +34,93 @@ namespace winrt::SampleApp::implementation
Control::TermControl control{ *settings, conn };
InProcContent().Children().Append(control);
CreateOutOfProcTerminal();
}
static wil::unique_process_information _createHostClassProcess(const winrt::guid& g)
{
auto guidStr{ ::Microsoft::Console::Utils::GuidToString(g) };
std::wstring commandline{ fmt::format(L"windowsterminal.exe --content {}", guidStr) };
STARTUPINFO siOne{ 0 };
siOne.cb = sizeof(STARTUPINFOW);
wil::unique_process_information piOne;
auto succeeded = CreateProcessW(
nullptr,
commandline.data(),
nullptr, // lpProcessAttributes
nullptr, // lpThreadAttributes
false, // bInheritHandles
CREATE_UNICODE_ENVIRONMENT, // dwCreationFlags
nullptr, // lpEnvironment
nullptr, // startingDirectory
&siOne, // lpStartupInfo
&piOne // lpProcessInformation
);
THROW_IF_WIN32_BOOL_FALSE(succeeded);
// if (!succeeded)
// {
// printf("Failed to create host process\n");
// return;
// }
// Ooof this is dumb, but we need a sleep here to make the server starts.
// That's _sub par_. Maybe we could use the host's stdout to have them emit
// a byte when they're set up?
Sleep(2000);
// TODO MONDAY - It seems like it takes conhost too long to start up to
// host the ScratchWinRTServer that even a sleep 100 is too short. However,
// any longer, and XAML will just crash, because some frame took too long.
// So we _need_ to do the "have the server explicitly tell us it's ready"
// thing, and maybe also do it on a bg thread (and signal to the UI thread
// that it can attach now)
return std::move(piOne);
}
winrt::fire_and_forget MyPage::CreateOutOfProcTerminal()
{
// 1. Generate a GUID.
winrt::guid contentGuid{ ::Microsoft::Console::Utils::CreateGuid() };
// Capture calling context.
winrt::apartment_context ui_thread;
co_await winrt::resume_background();
// 2. Spawn a Server.exe, with the guid on the commandline
auto piContent{ std::move(_createHostClassProcess(contentGuid)) };
Control::ContentProcess content = create_instance<Control::ContentProcess>(contentGuid, CLSCTX_LOCAL_SERVER);
TerminalConnection::EchoConnection conn{};
auto settings = winrt::make_self<implementation::MySettings>();
Control::IControlSettings s = *settings;
Core::ICoreAppearance testCoreAppearance = *settings;
Control::IControlAppearance testControlAppearance = *settings;
Core::ICoreSettings testCoreSettings = *settings;
testCoreAppearance;
testControlAppearance;
testCoreSettings;
auto foo = s.try_as<Core::ICoreAppearance>();
auto c1 = testCoreAppearance.DefaultBackground();
auto c2 = s.DefaultBackground();
auto c3 = foo.DefaultBackground();
c1;
c2;
c3;
if (s)
{
content.Initialize(s, conn);
// Switch back to the UI thread.
co_await ui_thread;
Control::TermControl control{ contentGuid, s, conn };
OutOfProcContent().Children().Append(control);
}
}
// Method Description:

View file

@ -16,6 +16,7 @@ namespace winrt::SampleApp::implementation
void Create();
hstring Title();
winrt::fire_and_forget CreateOutOfProcTerminal();
private:
friend struct MyPageT<MyPage>; // for Xaml to bind events

View file

@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#include "pch.h"
#include "MySettings.h"
#include "MySettings.g.cpp"
namespace winrt::SampleApp::implementation
{
}

View file

@ -0,0 +1,96 @@
/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
--*/
#pragma once
#include "../../inc/cppwinrt_utils.h"
// #include "../../src/inc/cppwinrt_utils.h"
#include <DefaultSettings.h>
#include <conattrs.hpp>
#include "MySettings.g.h"
namespace winrt::SampleApp::implementation
{
struct MySettings : MySettingsT<MySettings>
{
public:
MySettings() = default;
// --------------------------- Core Settings ---------------------------
// All of these settings are defined in ICoreSettings.
WINRT_PROPERTY(til::color, DefaultForeground, DEFAULT_FOREGROUND);
WINRT_PROPERTY(til::color, DefaultBackground, DEFAULT_BACKGROUND);
WINRT_PROPERTY(til::color, SelectionBackground, DEFAULT_FOREGROUND);
WINRT_PROPERTY(int32_t, HistorySize, DEFAULT_HISTORY_SIZE);
WINRT_PROPERTY(int32_t, InitialRows, 30);
WINRT_PROPERTY(int32_t, InitialCols, 80);
WINRT_PROPERTY(bool, SnapOnInput, true);
WINRT_PROPERTY(bool, AltGrAliasing, true);
WINRT_PROPERTY(til::color, CursorColor, DEFAULT_CURSOR_COLOR);
WINRT_PROPERTY(winrt::Microsoft::Terminal::Core::CursorStyle, CursorShape, winrt::Microsoft::Terminal::Core::CursorStyle::Vintage);
WINRT_PROPERTY(uint32_t, CursorHeight, DEFAULT_CURSOR_HEIGHT);
WINRT_PROPERTY(winrt::hstring, WordDelimiters, DEFAULT_WORD_DELIMITERS);
WINRT_PROPERTY(bool, CopyOnSelect, false);
WINRT_PROPERTY(bool, InputServiceWarning, true);
WINRT_PROPERTY(bool, FocusFollowMouse, false);
WINRT_PROPERTY(winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color>, TabColor, nullptr);
WINRT_PROPERTY(winrt::Windows::Foundation::IReference<winrt::Microsoft::Terminal::Core::Color>, StartingTabColor, nullptr);
winrt::Microsoft::Terminal::Core::ICoreAppearance UnfocusedAppearance() { return {}; };
WINRT_PROPERTY(bool, TrimBlockSelection, false);
// ------------------------ End of Core Settings -----------------------
WINRT_PROPERTY(winrt::hstring, ProfileName);
WINRT_PROPERTY(bool, UseAcrylic, false);
WINRT_PROPERTY(double, TintOpacity, 0.5);
WINRT_PROPERTY(winrt::hstring, Padding, DEFAULT_PADDING);
WINRT_PROPERTY(winrt::hstring, FontFace, L"Consolas");
WINRT_PROPERTY(int32_t, FontSize, DEFAULT_FONT_SIZE);
WINRT_PROPERTY(winrt::Windows::UI::Text::FontWeight, FontWeight);
WINRT_PROPERTY(winrt::hstring, BackgroundImage);
WINRT_PROPERTY(double, BackgroundImageOpacity, 1.0);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::Media::Stretch, BackgroundImageStretchMode, winrt::Windows::UI::Xaml::Media::Stretch::UniformToFill);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::HorizontalAlignment, BackgroundImageHorizontalAlignment, winrt::Windows::UI::Xaml::HorizontalAlignment::Center);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::VerticalAlignment, BackgroundImageVerticalAlignment, winrt::Windows::UI::Xaml::VerticalAlignment::Center);
WINRT_PROPERTY(winrt::Microsoft::Terminal::Control::IKeyBindings, KeyBindings, nullptr);
WINRT_PROPERTY(winrt::hstring, Commandline);
WINRT_PROPERTY(winrt::hstring, StartingDirectory);
WINRT_PROPERTY(winrt::hstring, StartingTitle);
WINRT_PROPERTY(bool, SuppressApplicationTitle);
WINRT_PROPERTY(winrt::hstring, EnvironmentVariables);
WINRT_PROPERTY(winrt::Microsoft::Terminal::Control::ScrollbarState, ScrollState, winrt::Microsoft::Terminal::Control::ScrollbarState::Visible);
WINRT_PROPERTY(winrt::Microsoft::Terminal::Control::TextAntialiasingMode, AntialiasingMode, winrt::Microsoft::Terminal::Control::TextAntialiasingMode::Grayscale);
WINRT_PROPERTY(bool, RetroTerminalEffect, false);
WINRT_PROPERTY(bool, ForceFullRepaintRendering, false);
WINRT_PROPERTY(bool, SoftwareRendering, false);
WINRT_PROPERTY(bool, ForceVTInput, false);
WINRT_PROPERTY(winrt::hstring, PixelShaderPath);
private:
std::array<winrt::Microsoft::Terminal::Core::Color, COLOR_TABLE_SIZE> _ColorTable;
public:
winrt::Microsoft::Terminal::Core::Color GetColorTableEntry(int32_t index) noexcept { return _ColorTable.at(index); }
std::array<winrt::Microsoft::Terminal::Core::Color, 16> ColorTable() { return _ColorTable; }
void ColorTable(std::array<winrt::Microsoft::Terminal::Core::Color, 16> /*colors*/) {}
};
}
namespace winrt::SampleApp::factory_implementation
{
BASIC_FACTORY(MySettings);
}

View file

@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
namespace SampleApp
{
[default_interface] runtimeclass MySettings : Microsoft.Terminal.Core.ICoreSettings,
Microsoft.Terminal.Control.IControlSettings,
Microsoft.Terminal.Core.ICoreAppearance,
Microsoft.Terminal.Control.IControlAppearance
{
MySettings();
}
}

View file

@ -49,6 +49,7 @@
<!-- ========================= Headers ======================== -->
<ItemGroup>
<ClInclude Include="App.base.h" />
<ClInclude Include="MySettings.h" />
<ClInclude Include="MyPage.h">
<DependentUpon>MyPage.xaml</DependentUpon>
<SubType>Code</SubType>
@ -63,6 +64,7 @@
<!-- ========================= Cpp Files ======================== -->
<ItemGroup>
<ClCompile Include="init.cpp" />
<ClCompile Include="MySettings.cpp" />
<ClCompile Include="MyPage.cpp">
<DependentUpon>MyPage.xaml</DependentUpon>
<SubType>Code</SubType>
@ -87,6 +89,7 @@
<DependentUpon>App.xaml</DependentUpon>
</Midl>
<Midl Include="SampleAppLogic.idl" />
<Midl Include="MySettings.idl" />
<Midl Include="MyPage.idl">
<DependentUpon>MyPage.xaml</DependentUpon>
<SubType>Code</SubType>
@ -105,7 +108,9 @@
make sure that if you add a cppwinrt dependency to any of these projects,
you also update all the consumers
-->
<!-- <ProjectReference Include="$(OpenConsoleDir)src\types\lib\types.vcxproj" /> -->
<ProjectReference Include="$(OpenConsoleDir)src\types\lib\types.vcxproj">
<Project>{18D09A24-8240-42D6-8CB6-236EEE820263}</Project>
</ProjectReference>
<!-- <ProjectReference Include="$(OpenConsoleDir)src\cascadia\WinRTUtils\WinRTUtils.vcxproj">
<Project>{CA5CAD1A-039A-4929-BA2A-8BEB2E4106FE}</Project>
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>

View file

@ -42,7 +42,7 @@
<!-- ========================= Project References ======================== -->
<ItemGroup>
<!-- <ProjectReference Include="$(OpenConsoleDir)src\types\lib\types.vcxproj">
<!-- <ProjectReference Include="$(OpenConsoleDir)src\types\lib\types.vcxproj">
<Project>{18D09A24-8240-42D6-8CB6-236EEE820263}</Project>
</ProjectReference> -->
<!-- Reference SampleAppLib here, so we can use it's App.winmd as
@ -65,6 +65,18 @@
<Private>false</Private>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
</Reference>
<Reference Include="Microsoft.Terminal.TerminalConnection">
<HintPath>$(OpenConsoleCommonOutDir)TerminalConnection\Microsoft.Terminal.TerminalConnection.winmd</HintPath>
<IsWinMDFile>true</IsWinMDFile>
<Private>false</Private>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
</Reference>
<Reference Include="Microsoft.Terminal.Control">
<HintPath>$(OpenConsoleCommonOutDir)Microsoft.Terminal.Control\Microsoft.Terminal.Control.winmd</HintPath>
<IsWinMDFile>true</IsWinMDFile>
<Private>false</Private>
<CopyLocalSatelliteAssemblies>false</CopyLocalSatelliteAssemblies>
</Reference>
</ItemGroup>

View file

@ -200,6 +200,17 @@
</PackagingOutputs>
</ItemGroup>
<!-- **END TERMINALCONNECTION HACK** -->
<!-- Same thing again here, with windowsterminal.exe -->
<ItemGroup>
<_WindowsTerminalExe Include="$(OpenConsoleCommonOutDir)\WindowsTerminal\*.exe" />
<PackagingOutputs Include="@(_WindowsTerminalExe)">
<ProjectName>$(ProjectName)</ProjectName>
<OutputGroup>BuiltProjectOutputGroup</OutputGroup>
<TargetPath>%(Filename)%(Extension)</TargetPath>
</PackagingOutputs>
</ItemGroup>
</Target>

View file

@ -19,4 +19,42 @@ namespace winrt::Microsoft::Terminal::Control::implementation
return _interactivity;
}
uint64_t ContentProcess::RequestSwapChainHandle(const uint64_t pid)
{
auto ourPid = GetCurrentProcessId();
HANDLE ourHandle = reinterpret_cast<HANDLE>(_interactivity.GetCore().GetSwapChainHandle());
if (pid == ourPid)
{
return reinterpret_cast<uint64_t>(ourHandle);
}
wil::unique_handle hWindowProcess{ OpenProcess(PROCESS_ALL_ACCESS,
FALSE,
static_cast<DWORD>(pid)) };
if (hWindowProcess.get() == nullptr)
{
const auto gle = GetLastError();
gle;
// TODO! tracelog an error here
return 0;
}
HANDLE theirHandle{ nullptr };
BOOL success = DuplicateHandle(GetCurrentProcess(),
ourHandle,
hWindowProcess.get(),
&theirHandle,
0,
FALSE,
DUPLICATE_SAME_ACCESS);
if (!success)
{
const auto gle = GetLastError();
gle;
// TODO! tracelog an error here
return 0;
}
return reinterpret_cast<uint64_t>(theirHandle);
}
}

View file

@ -15,6 +15,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void Initialize(Control::IControlSettings settings, TerminalConnection::ITerminalConnection connection);
Control::ControlInteractivity GetInteractivity();
uint64_t RequestSwapChainHandle(const uint64_t pid);
private:
Control::ControlInteractivity _interactivity{ nullptr };
};

View file

@ -13,5 +13,7 @@ namespace Microsoft.Terminal.Control
Microsoft.Terminal.TerminalConnection.ITerminalConnection connection);
ControlInteractivity GetInteractivity();
UInt64 RequestSwapChainHandle(UInt64 pid);
};
}

View file

@ -513,6 +513,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_desiredFont = { _actualFont };
// Update the terminal core with its new Core settings
Core::ICoreSettings coreSettings = _settings.try_as<Core::ICoreSettings>();
Core::ICoreAppearance coreAppearance = _settings.try_as<Core::ICoreAppearance>();
if (!coreSettings)
{
OutputDebugString(L"Failed to get core settings");
}
if (!coreAppearance)
{
OutputDebugString(L"Failed to get coreAppearance");
}
_terminal->UpdateSettings(_settings);
if (!_initializedTerminal)

View file

@ -68,10 +68,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
if (contentGuid != winrt::guid{})
{
Control::ContentProcess content = create_instance<Control::ContentProcess>(contentGuid, CLSCTX_LOCAL_SERVER);
if (content != nullptr)
_contentProc = create_instance<Control::ContentProcess>(contentGuid, CLSCTX_LOCAL_SERVER);
if (_contentProc != nullptr)
{
_interactivity = content.GetInteractivity();
_interactivity = _contentProc.GetInteractivity();
}
}
@ -582,7 +582,10 @@ namespace winrt::Microsoft::Terminal::Control::implementation
if (auto control{ weakThis.get() })
{
const HANDLE chainHandle = reinterpret_cast<HANDLE>(control->_core.GetSwapChainHandle());
// TODO! very good chance we leak this handle
const HANDLE chainHandle = reinterpret_cast<HANDLE>(control->_contentProc ?
control->_contentProc.RequestSwapChainHandle(GetCurrentProcessId()) :
control->_core.GetSwapChainHandle());
_AttachDxgiSwapChainToXaml(chainHandle);
}
}
@ -670,7 +673,11 @@ namespace winrt::Microsoft::Terminal::Control::implementation
}
_interactivity.Initialize();
_AttachDxgiSwapChainToXaml(reinterpret_cast<HANDLE>(_core.GetSwapChainHandle()));
// TODO! very good chance we leak this handle
const HANDLE chainHandle = reinterpret_cast<HANDLE>(_contentProc ?
_contentProc.RequestSwapChainHandle(GetCurrentProcessId()) :
_core.GetSwapChainHandle());
_AttachDxgiSwapChainToXaml(chainHandle);
// Tell the DX Engine to notify us when the swap chain changes. We do
// this after we initially set the swapchain so as to avoid unnecessary

View file

@ -135,6 +135,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
Control::ControlCore _core{ nullptr };
Control::ControlInteractivity _interactivity{ nullptr };
Control::ContentProcess _contentProc{ nullptr };
bool _initializedTerminal;

View file

@ -136,7 +136,7 @@ struct HostClassFactory : implements<HostClassFactory, IClassFactory>
if (!g_weak)
{
winrt::Microsoft::Terminal::Control::ContentProcess strong{};// = winrt::make<winrt::Microsoft::Terminal::Control::ContentProcess>();
winrt::Microsoft::Terminal::Control::ContentProcess strong{}; // = winrt::make<winrt::Microsoft::Terminal::Control::ContentProcess>();
winrt::weak_ref<winrt::Microsoft::Terminal::Control::ContentProcess> weak{ strong };
g_weak = weak;
return strong.as(iid, result);
@ -159,6 +159,8 @@ private:
static void doContentProcessThing(const winrt::guid& contentProcessGuid)
{
// !! LOAD BEARING !! - important to be a MTA
winrt::init_apartment();
DWORD registrationHostClass{};
check_hresult(CoRegisterClassObject(contentProcessGuid,
@ -197,17 +199,6 @@ int __stdcall wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
// Make sure to call this so we get WM_POINTER messages.
EnableMouseInPointer(true);
// !!! LOAD BEARING !!!
// We must initialize the main thread as a single-threaded apartment before
// constructing any Xaml objects. Failing to do so will cause some issues
// in accessibility somewhere down the line when a UIAutomation object will
// be queried on the wrong thread at the wrong time.
// We used to initialize as STA only _after_ initializing the application
// host, which loaded the settings. The settings needed to be loaded in MTA
// because we were using the Windows.Storage APIs. Since we're no longer
// doing that, we can safely init as STA before any WinRT dispatches.
winrt::init_apartment(winrt::apartment_type::single_threaded);
winrt::guid contentProcessGuid{};
if (checkIfContentProcess(contentProcessGuid))
{
@ -219,6 +210,17 @@ int __stdcall wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
ExitProcess(0);
}
// !!! LOAD BEARING !!!
// We must initialize the main thread as a single-threaded apartment before
// constructing any Xaml objects. Failing to do so will cause some issues
// in accessibility somewhere down the line when a UIAutomation object will
// be queried on the wrong thread at the wrong time.
// We used to initialize as STA only _after_ initializing the application
// host, which loaded the settings. The settings needed to be loaded in MTA
// because we were using the Windows.Storage APIs. Since we're no longer
// doing that, we can safely init as STA before any WinRT dispatches.
winrt::init_apartment(winrt::apartment_type::single_threaded);
// Create the AppHost object, which will create both the window and the
// Terminal App. This MUST BE constructed before the Xaml manager as TermApp
// provides an implementation of Windows.UI.Xaml.Application.