Skip to content

Commit 9a2ee6a

Browse files
committed
Cleanup, comments, etc.
1 parent dc78b32 commit 9a2ee6a

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/host/srvinit.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,22 @@ static bool s_IsOnDesktop()
199199
// strong nudge in that direction. If an application _doesn't_ want VT
200200
// processing, it's free to disable this setting, even in conpty mode.
201201
settings.SetVirtTermLevel(1);
202+
203+
// GH#9458 - In the case of a DefTerm handoff, the OriginalTitle might
204+
// be stashed in the lnk. We want to crack that lnk open, so we can get
205+
// that title from it, but we want to discard everything else. So build
206+
// a dummy Settings object here, and read the link settings into it.
207+
// `Title` will get filled with the title from the lnk, which we'll use
208+
// below.
209+
210+
Settings temp;
211+
// We're not gonna copy over StartupFlags to the main gci settings,
212+
// because we generally don't think those are valuable in ConPTY mode.
213+
// However, we do need to apply them to the temp we've created, so that
214+
// GetSettingsFromLink will actually look for the link settings (it will
215+
// skip that if STARTF_TITLEISLINKNAME is not set).
216+
temp.SetStartupFlags(pStartupSettings->GetStartupFlags());
217+
ServiceLocator::LocateSystemConfigurationProvider()->GetSettingsFromLink(&temp, Title, &TitleLength, CurDir, AppName, nullptr);
202218
}
203219

204220
// 1. The settings we were passed contains STARTUPINFO structure settings to be applied last.

src/interactivity/win32/SystemConfigurationProvider.cpp

+14-6
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,21 @@ void SystemConfigurationProvider::GetSettingsFromLink(
7373
// Did we get started from a link?
7474
if (pLinkSettings->GetStartupFlags() & STARTF_TITLEISLINKNAME)
7575
{
76-
auto initializeCom = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
77-
// If it's RPC_E_CHANGED_MODE, that's okay, we're doing a defterm and already started COM
78-
if (SUCCEEDED(initializeCom) || initializeCom == RPC_E_CHANGED_MODE)
76+
auto initializedCom = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
77+
78+
// GH#9458: If it's RPC_E_CHANGED_MODE, that's okay, we're doing a
79+
// defterm and have already started COM. We can continue on here.
80+
if (SUCCEEDED(initializedCom) || initializedCom == RPC_E_CHANGED_MODE)
7981
{
80-
82+
// Don't CoUninitialize if we still need COM for defterm.
83+
auto unInitCom = wil::scope_exit[initializedCom]()
84+
{
85+
if (SUCCEEDED(initializedCom))
86+
{
87+
CoUninitialize();
88+
}
89+
};
90+
8191
const auto cch = *pdwTitleLength / sizeof(wchar_t);
8292

8393
gci.SetLinkTitle(std::wstring(pwszTitle, cch));
@@ -160,8 +170,6 @@ void SystemConfigurationProvider::GetSettingsFromLink(
160170
// settings based on title.
161171
pLinkSettings->UnsetStartupFlag(STARTF_TITLEISLINKNAME);
162172
}
163-
if (SUCCEEDED(initializeCom)) {
164-
CoUninitialize(); }
165173
}
166174
}
167175

0 commit comments

Comments
 (0)