From 9a2ee6a7c29c6bb4c25314acf0e8993594cfbca9 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 19 Jul 2022 12:30:26 -0500 Subject: [PATCH] Cleanup, comments, etc. --- src/host/srvinit.cpp | 16 +++++++++++++++ .../win32/SystemConfigurationProvider.cpp | 20 +++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/host/srvinit.cpp b/src/host/srvinit.cpp index b414406be22..a6505a84d2e 100644 --- a/src/host/srvinit.cpp +++ b/src/host/srvinit.cpp @@ -199,6 +199,22 @@ static bool s_IsOnDesktop() // strong nudge in that direction. If an application _doesn't_ want VT // processing, it's free to disable this setting, even in conpty mode. settings.SetVirtTermLevel(1); + + // GH#9458 - In the case of a DefTerm handoff, the OriginalTitle might + // be stashed in the lnk. We want to crack that lnk open, so we can get + // that title from it, but we want to discard everything else. So build + // a dummy Settings object here, and read the link settings into it. + // `Title` will get filled with the title from the lnk, which we'll use + // below. + + Settings temp; + // We're not gonna copy over StartupFlags to the main gci settings, + // because we generally don't think those are valuable in ConPTY mode. + // However, we do need to apply them to the temp we've created, so that + // GetSettingsFromLink will actually look for the link settings (it will + // skip that if STARTF_TITLEISLINKNAME is not set). + temp.SetStartupFlags(pStartupSettings->GetStartupFlags()); + ServiceLocator::LocateSystemConfigurationProvider()->GetSettingsFromLink(&temp, Title, &TitleLength, CurDir, AppName, nullptr); } // 1. The settings we were passed contains STARTUPINFO structure settings to be applied last. diff --git a/src/interactivity/win32/SystemConfigurationProvider.cpp b/src/interactivity/win32/SystemConfigurationProvider.cpp index a15b28bafa5..c8b595d813c 100644 --- a/src/interactivity/win32/SystemConfigurationProvider.cpp +++ b/src/interactivity/win32/SystemConfigurationProvider.cpp @@ -73,11 +73,21 @@ void SystemConfigurationProvider::GetSettingsFromLink( // Did we get started from a link? if (pLinkSettings->GetStartupFlags() & STARTF_TITLEISLINKNAME) { - auto initializeCom = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); - // If it's RPC_E_CHANGED_MODE, that's okay, we're doing a defterm and already started COM - if (SUCCEEDED(initializeCom) || initializeCom == RPC_E_CHANGED_MODE) + auto initializedCom = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + // GH#9458: If it's RPC_E_CHANGED_MODE, that's okay, we're doing a + // defterm and have already started COM. We can continue on here. + if (SUCCEEDED(initializedCom) || initializedCom == RPC_E_CHANGED_MODE) { - + // Don't CoUninitialize if we still need COM for defterm. + auto unInitCom = wil::scope_exit[initializedCom]() + { + if (SUCCEEDED(initializedCom)) + { + CoUninitialize(); + } + }; + const auto cch = *pdwTitleLength / sizeof(wchar_t); gci.SetLinkTitle(std::wstring(pwszTitle, cch)); @@ -160,8 +170,6 @@ void SystemConfigurationProvider::GetSettingsFromLink( // settings based on title. pLinkSettings->UnsetStartupFlag(STARTF_TITLEISLINKNAME); } - if (SUCCEEDED(initializeCom)) { - CoUninitialize(); } } }