Bug 1865597 - Add error checking when initializing parallel marking and disable on...
[gecko.git] / mozglue / misc / GetKnownFolderPath.cpp
blob676a1c8056502c9a2178203893fecffd55883407
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "GetKnownFolderPath.h"
7 namespace mozilla {
9 UniquePtr<wchar_t, LoadedCoTaskMemFreeDeleter> GetKnownFolderPath(
10 REFKNOWNFOLDERID folderId) {
11 static decltype(SHGetKnownFolderPath)* shGetKnownFolderPath = nullptr;
12 if (!shGetKnownFolderPath) {
13 // We could go out of our way to `FreeLibrary` on this, decrementing its
14 // ref count and potentially unloading it. However doing so would be either
15 // effectively a no-op, or counterproductive. Just let it get cleaned up
16 // when the process is terminated, because we're going to load it anyway
17 // elsewhere.
18 HMODULE shell32Dll = ::LoadLibraryW(L"shell32");
19 if (!shell32Dll) {
20 return nullptr;
22 shGetKnownFolderPath = reinterpret_cast<decltype(shGetKnownFolderPath)>(
23 ::GetProcAddress(shell32Dll, "SHGetKnownFolderPath"));
24 if (!shGetKnownFolderPath) {
25 return nullptr;
28 PWSTR path = nullptr;
29 shGetKnownFolderPath(folderId, 0, nullptr, &path);
30 return UniquePtr<wchar_t, LoadedCoTaskMemFreeDeleter>(path);
33 } // namespace mozilla