diff --git a/src/host/ft_host/API_FontTests.cpp b/src/host/ft_host/API_FontTests.cpp index 5d48e1e0241c..6222769a96bf 100644 --- a/src/host/ft_host/API_FontTests.cpp +++ b/src/host/ft_host/API_FontTests.cpp @@ -206,9 +206,9 @@ void FontTests::TestFontScenario() void FontTests::TestLongFontNameScenario() { - wistd::unique_ptr expandedLongFontPath; - VERIFY_SUCCEEDED(ExpandPathToMutable(pwszLongFontPath, expandedLongFontPath)); - if (!CheckIfFileExists(expandedLongFontPath.get())) + std::wstring expandedLongFontPath = wil::ExpandEnvironmentStringsW(pwszLongFontPath); + + if (!CheckIfFileExists(expandedLongFontPath.c_str())) { Log::Comment(L"Lucida Sans Typewriter doesn't exist; skipping long font test."); Log::Result(WEX::Logging::TestResults::Result::Skipped); diff --git a/src/host/ft_host/CanaryTests.cpp b/src/host/ft_host/CanaryTests.cpp index 26bd6c4f09bb..50742ce5a408 100644 --- a/src/host/ft_host/CanaryTests.cpp +++ b/src/host/ft_host/CanaryTests.cpp @@ -24,10 +24,9 @@ static PCWSTR pwszConhostV1Path = L"%WINDIR%\\system32\\conhostv1.dll"; void CanaryTests::LaunchV1Console() { // First ensure that this system has the v1 console to test. - wistd::unique_ptr ConhostV1Path; - VERIFY_SUCCEEDED(ExpandPathToMutable(pwszConhostV1Path, ConhostV1Path)); + std::wstring ConhostV1Path = wil::ExpandEnvironmentStringsW(pwszConhostV1Path); - if (!CheckIfFileExists(ConhostV1Path.get())) + if (!CheckIfFileExists(ConhostV1Path.c_str())) { Log::Comment(L"This system does not have the legacy conhostv1.dll module. Skipping test."); Log::Result(WEX::Logging::TestResults::Skipped); @@ -39,8 +38,7 @@ void CanaryTests::LaunchV1Console() // Attempt to launch CMD.exe in a new window // Expand any environment variables present in the command line string. - wistd::unique_ptr CmdLineMutable; - VERIFY_SUCCEEDED(ExpandPathToMutable(pwszCmdPath, CmdLineMutable)); + std::wstring CmdLine = wil::ExpandEnvironmentStringsW(pwszCmdPath); // Create output handle for redirection. We'll read from it to make sure CMD started correctly. // We'll let it have a default input handle to make sure it binds to the new console host window that will be created. @@ -67,7 +65,7 @@ void CanaryTests::LaunchV1Console() wil::unique_process_information ProcessInformation; VERIFY_WIN32_BOOL_SUCCEEDED(CreateProcessW(NULL, - CmdLineMutable.get(), + const_cast(CmdLine.c_str()), NULL, NULL, TRUE, diff --git a/src/host/ft_host/Common.cpp b/src/host/ft_host/Common.cpp index 6fcf491f32af..8716060d2e57 100644 --- a/src/host/ft_host/Common.cpp +++ b/src/host/ft_host/Common.cpp @@ -112,25 +112,6 @@ bool CheckLastError(HANDLE handle, PCWSTR pwszFunc) } } -HRESULT ExpandPathToMutable(_In_ PCWSTR pwszPath, _Out_ wistd::unique_ptr& MutablePath) noexcept -{ - // Find how many characters we need. - const DWORD cchExpanded = ExpandEnvironmentStringsW(pwszPath, nullptr, 0); - RETURN_LAST_ERROR_IF(0 == cchExpanded); - - // Allocate space to hold result - wistd::unique_ptr NewMutable = wil::make_unique_nothrow(cchExpanded); - RETURN_IF_NULL_ALLOC(NewMutable); - - // Expand string into allocated space - RETURN_LAST_ERROR_IF(0 == ExpandEnvironmentStringsW(pwszPath, NewMutable.get(), cchExpanded)); - - // On success, give our string back out (swapping with what was given and we'll free it for the caller.) - MutablePath.swap(NewMutable); - - return S_OK; -} - bool CheckIfFileExists(_In_ PCWSTR pwszPath) noexcept { wil::unique_hfile hFile(CreateFileW(pwszPath, diff --git a/src/host/ft_host/Common.hpp b/src/host/ft_host/Common.hpp index 8b6aba5def75..d4eb89cd0301 100644 --- a/src/host/ft_host/Common.hpp +++ b/src/host/ft_host/Common.hpp @@ -59,8 +59,6 @@ bool CheckLastError(HANDLE handle, PCWSTR pwszFunc); [[nodiscard]] bool CheckIfFileExists(_In_ PCWSTR pwszPath) noexcept; -[[nodiscard]] HRESULT ExpandPathToMutable(_In_ PCWSTR pwszPath, _Out_ wistd::unique_ptr& MutablePath) noexcept; - //http://blogs.msdn.com/b/oldnewthing/archive/2013/10/17/10457292.aspx BOOL UnadjustWindowRectEx( LPRECT prc, diff --git a/src/server/Entrypoints.cpp b/src/server/Entrypoints.cpp index 7eb941238b14..930b994096ba 100644 --- a/src/server/Entrypoints.cpp +++ b/src/server/Entrypoints.cpp @@ -154,21 +154,11 @@ } // Expand any environment variables present in the command line string. - // - Get needed size - DWORD cchCmdLineExpanded = ExpandEnvironmentStringsW(pwszCmdLine, nullptr, 0); - RETURN_LAST_ERROR_IF(0 == cchCmdLineExpanded); - - // - Allocate space to hold result - wistd::unique_ptr CmdLineMutable = wil::make_unique_nothrow(cchCmdLineExpanded); - RETURN_IF_NULL_ALLOC(CmdLineMutable); - - // - Expand string into allocated space - RETURN_LAST_ERROR_IF(0 == ExpandEnvironmentStringsW(pwszCmdLine, CmdLineMutable.get(), cchCmdLineExpanded)); - + std::wstring cmdLine = wil::ExpandEnvironmentStringsW(pwszCmdLine); // Call create process wil::unique_process_information ProcessInformation; RETURN_IF_WIN32_BOOL_FALSE(CreateProcessW(NULL, - CmdLineMutable.get(), + const_cast(cmdLine.c_str()), NULL, NULL, TRUE,