tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GetKnownFolderPath.h (1302B)


      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/. */
      4 
      5 #ifndef mozilla_GetKnownFolderPath_h
      6 #define mozilla_GetKnownFolderPath_h
      7 
      8 #include <windows.h>
      9 #include <objbase.h>
     10 #include <shlobj.h>
     11 
     12 #include "mozilla/glue/Debug.h"
     13 #include "mozilla/UniquePtr.h"
     14 
     15 namespace mozilla {
     16 
     17 struct LoadedCoTaskMemFreeDeleter {
     18  void operator()(void* ptr) {
     19    static decltype(CoTaskMemFree)* coTaskMemFree = nullptr;
     20    if (!coTaskMemFree) {
     21      // Just let this get cleaned up when the process is terminated, because
     22      // we're going to load it anyway elsewhere.
     23      HMODULE ole32Dll = ::LoadLibraryW(L"ole32");
     24      if (!ole32Dll) {
     25        printf_stderr(
     26            "Could not load ole32 - will not free with CoTaskMemFree");
     27        return;
     28      }
     29      coTaskMemFree = reinterpret_cast<decltype(coTaskMemFree)>(
     30          ::GetProcAddress(ole32Dll, "CoTaskMemFree"));
     31      if (!coTaskMemFree) {
     32        printf_stderr("Could not find CoTaskMemFree");
     33        return;
     34      }
     35    }
     36    coTaskMemFree(ptr);
     37  }
     38 };
     39 
     40 UniquePtr<wchar_t, LoadedCoTaskMemFreeDeleter> GetKnownFolderPath(
     41    REFKNOWNFOLDERID folderId);
     42 
     43 }  // namespace mozilla
     44 
     45 #endif