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"
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
18 HMODULE shell32Dll
= ::LoadLibraryW(L
"shell32");
22 shGetKnownFolderPath
= reinterpret_cast<decltype(shGetKnownFolderPath
)>(
23 ::GetProcAddress(shell32Dll
, "SHGetKnownFolderPath"));
24 if (!shGetKnownFolderPath
) {
29 shGetKnownFolderPath(folderId
, 0, nullptr, &path
);
30 return UniquePtr
<wchar_t, LoadedCoTaskMemFreeDeleter
>(path
);
33 } // namespace mozilla