diff --git a/src/modules/MouseWithoutBorders/ModuleInterface/dllmain.cpp b/src/modules/MouseWithoutBorders/ModuleInterface/dllmain.cpp index 0b259c71f83..d2203e6ff5a 100644 --- a/src/modules/MouseWithoutBorders/ModuleInterface/dllmain.cpp +++ b/src/modules/MouseWithoutBorders/ModuleInterface/dllmain.cpp @@ -198,7 +198,7 @@ class MouseWithoutBorders : public PowertoyModuleIface Logger::error("Failed to delete MWB service"); return; } - + Trace::MouseWithoutBorders::ToggleServiceRegistration(false); } @@ -242,11 +242,10 @@ class MouseWithoutBorders : public PowertoyModuleIface } // Pass local app data of the current user to the service - PWSTR cLocalAppPath; + wil::unique_cotaskmem_string cLocalAppPath; winrt::check_hresult(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &cLocalAppPath)); - CoTaskMemFree(cLocalAppPath); - std::wstring localAppPath{ cLocalAppPath }; + std::wstring localAppPath{ cLocalAppPath.get() }; std::wstring binaryWithArgsPath = L"\""; binaryWithArgsPath += servicePath; binaryWithArgsPath += L"\" "; @@ -259,7 +258,8 @@ class MouseWithoutBorders : public PowertoyModuleIface std::wstring_view existingServicePath{ pServiceConfig->lpBinaryPathName }; alreadyRegistered = true; isServicePathCorrect = (existingServicePath == binaryWithArgsPath); - if (isServicePathCorrect) { + if (isServicePathCorrect) + { Logger::warn(L"The service path is not correct. Current: {} Expected: {}", existingServicePath, binaryWithArgsPath); } @@ -291,18 +291,19 @@ class MouseWithoutBorders : public PowertoyModuleIface if (alreadyRegistered) { - if (!isServicePathCorrect) { + if (!isServicePathCorrect) + { if (!ChangeServiceConfigW(schService, - SERVICE_NO_CHANGE, - SERVICE_NO_CHANGE, - SERVICE_NO_CHANGE, - binaryWithArgsPath.c_str(), - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr)) + SERVICE_NO_CHANGE, + SERVICE_NO_CHANGE, + SERVICE_NO_CHANGE, + binaryWithArgsPath.c_str(), + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + nullptr)) { Logger::error(L"Failed to update the service's path. ERROR: {}", GetLastError()); }