本文整理汇总了C++中SHGetKnownFolderPath函数的典型用法代码示例。如果您正苦于以下问题:C++ SHGetKnownFolderPath函数的具体用法?C++ SHGetKnownFolderPath怎么用?C++ SHGetKnownFolderPath使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SHGetKnownFolderPath函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CString
CString CodeCollaboratorInfo::GetPathToCollabGuiExe()
{
// this will work for X86 and X64 if the matching 'bitness' client has been installed
PWSTR pszPath = NULL;
if (SHGetKnownFolderPath(FOLDERID_ProgramFiles, KF_FLAG_CREATE, NULL, &pszPath) != S_OK)
return CString();
CString path = pszPath;
CoTaskMemFree(pszPath);
path += L"Collaborator Client\\ccollabgui.exe";
if (PathFileExists(path))
return path;
#ifdef _WIN64
// if running on x64 OS, but installed X86 client - get try getting directory from there
// on X86 this just returns %ProgramFiles%
if (SHGetKnownFolderPath(FOLDERID_ProgramFilesX86, KF_FLAG_CREATE, NULL, &pszPath) != S_OK)
return CString();
path += L"Collaborator Client\\ccollabgui.exe";
if (PathFileExists(path))
return path;
#endif
return CString();
}
示例2: if
/// <summary>
///
/// </summary>
void TileGroup::AddNameFilter(LPCWSTR name) {
if (_wcsicmp(name, L".computer") == 0) {
mHiddenItems.emplace(L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}");
} else if (_wcsicmp(name, L".recycleBin") == 0) {
mHiddenItems.emplace(L"::{645FF040-5081-101B-9F08-00AA002F954E}");
} else if (_wcsicmp(name, L".controlPanel") == 0) {
mHiddenItems.emplace(L"::{26EE0668-A00A-44D7-9371-BEB064C98683}");
mHiddenItems.emplace(L"::{5399E694-6CE5-4D6C-8FCE-1D8870FDCBA0}");
} else if (_wcsicmp(name, L".libraries") == 0) {
mHiddenItems.emplace(L"::{031E4825-7B94-4DC3-B131-E946B44C8DD5}");
} else if (_wcsicmp(name, L".network") == 0) {
mHiddenItems.emplace(L"::{F02C1A0D-BE21-4350-88B0-7367FC96EF3C}");
} else if (_wcsicmp(name, L".homegroup") == 0) {
mHiddenItems.emplace(L"::{B4FB3F98-C1EA-428D-A78A-D1F5659CBA93}");
} else if (_wcsicmp(name, L".onedrive") == 0) {
LPWSTR path;
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_SkyDrive, 0, nullptr, &path))) {
mHiddenItems.emplace(path);
CoTaskMemFree(path);
}
} else if (_wcsicmp(name, L".user") == 0) {
LPWSTR path;
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Profile, 0, nullptr, &path))) {
mHiddenItems.emplace(path);
CoTaskMemFree(path);
}
} else {
mHiddenItems.emplace(name);
}
}
示例3: getKnownFolderPath
QString getKnownFolderPath(REFKNOWNFOLDERID id)
{
wchar_t* result;
win_throw_on_fail( SHGetKnownFolderPath(id, 0, nullptr, &result) );
OLEPtr<wchar_t> ptr(result);
return QString((QChar*)ptr.get());
}
示例4: m_hInstance
MacroApp::MacroApp(HINSTANCE hInstance, HWND hWnd) : m_hInstance(hInstance), m_hWnd(hWnd), m_systray(hInstance, hWnd) {
static NotificationThreadData data;
WCHAR * filepath;
if (!SUCCEEDED(SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &filepath))) {
MessageBox(0, "SHGetKnownFolderPath() failed.", 0, MB_OK);
return;
}
m_settingsPath = filepath;
m_settingsPath += L"\\Macro";
CreateDirectoryW(m_settingsPath.c_str(), NULL);
m_settingsFile = m_settingsPath + L"\\macro-settings.py";
if (!fileExists(m_settingsFile.c_str())) {
std::ofstream out(m_settingsFile.c_str());
extern const char * DEFAULT_CONFIG_FILE;
out << DEFAULT_CONFIG_FILE;
out.close();
}
data.notificationHandle = FindFirstChangeNotificationW(m_settingsPath.c_str(), FALSE, FILE_NOTIFY_CHANGE_LAST_WRITE);
if (data.notificationHandle != INVALID_HANDLE_VALUE) {
data.hwnd = m_hWnd;
CreateThread(NULL, 0, FileChangeNotificationThread, &data, 0, NULL);
}
}
示例5: user_cache_directory
std::string user_cache_directory()
{
#if UTILS_OS_LINUX
auto xds_cache_home = std::getenv("XDS_CACHE_HOME");
if (xds_cache_home && *xds_cache_home != '\0')
return xds_cache_home;
auto home = user_home_directory();
if (!home.empty())
return home + "/.cache";
#elif UTILS_OS_MAC
auto home = user_home_directory();
if (!home.empty())
return home + "/Library/Caches";
#elif UTILS_OS_WINDOWS
wchar_t* utf16Path = nullptr;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, nullptr, &utf16Path) != S_OK)
return {};
char utf8Path[4 * MAX_PATH];
int len = WideCharToMultiByte(CP_UTF8, 0, utf16Path, lstrlenW(utf16Path), utf8Path, sizeof(utf8Path), nullptr, nullptr);
CoTaskMemFree(utf16Path);
return {utf8Path, len};
#else
static_assert(false, "Unsupported OS");
#endif
return {};
}
示例6: GetAppDataPath
std::wstring GetAppDataPath()
{
if (appDataPath.empty())
{
if (IsWindowsVistaOrLater())
{
WCHAR* pathBuffer;
if (FAILED(SHGetKnownFolderPath(FOLDERID_LocalAppDataLow, 0, 0, &pathBuffer)))
throw std::runtime_error("Unable to find app data directory");
appDataPath.assign(pathBuffer);
CoTaskMemFree(pathBuffer);
}
else
{
std::auto_ptr<wchar_t> pathBuffer(new wchar_t[MAX_PATH]);
if (!SHGetSpecialFolderPathW(0, pathBuffer.get(), CSIDL_LOCAL_APPDATA, true))
throw std::runtime_error("Unable to find app data directory");
appDataPath.assign(pathBuffer.get());
}
appDataPath += L"\\Adblock Plus for IE";
// Ignore errors here, this isn't a critical operation
::CreateDirectoryW(appDataPath.c_str(), NULL);
}
return appDataPath;
}
示例7: OnBnClickedRegedt
void CSetOverlayHandlers::OnBnClickedRegedt()
{
PWSTR pszPath = nullptr;
if (SHGetKnownFolderPath(FOLDERID_Windows, KF_FLAG_CREATE, nullptr, &pszPath) == S_OK)
{
CString path = pszPath;
CoTaskMemFree(pszPath);
path += L"\\regedit.exe";
// regedit stores the key it showed last in
// HKEY_Current_User\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit\LastKey
// we set that here to
// HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\ShellIconOverlayIdentifiers
// so when we start regedit, it will show that key on start
CRegString regLastKey(L"Software\\Microsoft\\Windows\\CurrentVersion\\Applets\\Regedit\\LastKey");
regLastKey = L"HKEY_Local_Machine\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\ShellIconOverlayIdentifiers";
SHELLEXECUTEINFO si = { sizeof(SHELLEXECUTEINFO) };
si.hwnd = GetSafeHwnd();
si.lpVerb = L"open";
si.lpFile = path;
si.nShow = SW_SHOW;
ShellExecuteEx(&si);
}
}
示例8: GetOriginalSavePath
// get a xliveless-compatible save game directory
static std::wstring GetOriginalSavePath()
{
PWSTR documentsPath;
// get the Documents folder
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Documents, 0, nullptr, &documentsPath)))
{
// put it into a string and free it
std::wstring savePath(documentsPath);
CoTaskMemFree(documentsPath);
// append the R* bits
AppendPathComponent(savePath, L"\\Rockstar Games");
AppendPathComponent(savePath, L"\\GTA IV");
AppendPathComponent(savePath, L"\\savegames");
// append a final separator
savePath += L"\\";
// and return the path
return savePath;
}
// if not working, panic
FatalError("Could not get Documents folder path for save games.");
}
示例9: GetCitizenSavePath
// get our Citizen save game directory
static std::wstring GetCitizenSavePath()
{
PWSTR saveBasePath;
// get the 'Saved Games' shell directory
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_SavedGames, 0, nullptr, &saveBasePath)))
{
// create a STL string and free the used memory
std::wstring savePath(saveBasePath);
CoTaskMemFree(saveBasePath);
// append our path components
AppendPathComponent(savePath, L"\\CitizenFX");
AppendPathComponent(savePath, L"\\GTA4");
// append a final separator
savePath += L"\\";
// and return the path
return savePath;
}
return GetOriginalSavePath();
}
示例10: while
wstring CFileSystemServiceImpl::makeValidPath(const wstring& path1) {
wstring path = path1;
size_t p = path.find(L'%');
while (p != wstring::npos) {
size_t e = path.find(L'%', p+1);
if (e == wstring::npos) break;
wstring variableName = path.substr(p+1, e-p-1);
wstring variableValue = getenv(variableName);
replaceStringInPlace(path, path.substr(p, e+1-p), variableValue);
p = path.find(L'%');
}
p = path.find(L'{');
while (p != wstring::npos) {
size_t e = path.find(L'}', p+1);
if (e == wstring::npos) break;
wstring variableName = path.substr(p, e-p+1);
GUID guid;
if (CLSIDFromString(variableName.c_str(), &guid) == S_OK) {
LPWSTR folderPath = NULL;
SHGetKnownFolderPath(guid, 0, NULL, &folderPath);
if (folderPath) {
replaceStringInPlace(path, path.substr(p, e+1-p), folderPath);
CoTaskMemFree(folderPath);
}
}
p = path.find(L'{');
}
return path;
}
示例11: PWSTR
UnicodeString Logfile::getFilename(const UnicodeString& logfileName)
{
auto logsDirectory = UnicodeString::Period;
#ifdef WINDOWS
// On Windows logfiles are put into the current user's AppData/Roaming/<client name> directory
auto path = PWSTR();
SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &path);
logsDirectory = FileSystem::joinPaths(fromUTF16(path), Globals::getClientName());
CoTaskMemFree(path);
#elif defined(LINUX)
// On Linux logfiles are put into the ~/.<client name> directory
logsDirectory = FileSystem::joinPaths(FileSystem::getHomeDirectory(), String::Period + Globals::getClientName());
#elif defined(APPLE)
// Put logfiles under ~/Library/Logs
logsDirectory = FileSystem::joinPaths(FileSystem::getUserLibraryDirectory(), "Logs");
#ifdef MACOS
logsDirectory = FileSystem::joinPaths(logsDirectory, Globals::getClientName());
#endif
#endif
return FileSystem::joinPaths(logsDirectory, logfileName + ".html");
}
示例12: CreateSampleFiles
// Creates a set of sample files in the current user's Documents directory to use as items in the
// custom category inserted into the Jump List.
HRESULT CreateSampleFiles()
{
PWSTR pszPathDocuments;
HRESULT hr = SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_CREATE, NULL, &pszPathDocuments);
if (SUCCEEDED(hr))
{
for (UINT i = 0; SUCCEEDED(hr) && i < ARRAYSIZE(c_rgpszFiles); i++)
{
WCHAR szPathSample[MAX_PATH];
hr = PathCombine(szPathSample, pszPathDocuments, c_rgpszFiles[i]) ? S_OK : E_FAIL;
if (SUCCEEDED(hr))
{
IStream *pstm;
hr = SHCreateStreamOnFileEx(szPathSample, (STGM_WRITE | STGM_FAILIFTHERE), FILE_ATTRIBUTE_NORMAL, TRUE, NULL, &pstm);
if (SUCCEEDED(hr))
{
PCWSTR pszText = L"This is a sample file for the CustomJumpListSample.\r\n";
ULONG cb = (sizeof(pszText[0]) * (lstrlen(pszText) + 1));
hr = IStream_Write(pstm, pszText, cb);
pstm->Release();
}
else if (HRESULT_FROM_WIN32(ERROR_FILE_EXISTS) == hr)
{
// If the file exists, we're ok, we'll just reuse it
hr = S_OK;
}
}
}
CoTaskMemFree(pszPathDocuments);
}
return hr;
}
示例13: initialize_launchers
static void initialize_launchers( HWND hwnd )
{
HRESULT hr, init;
TEXTMETRICW tm;
int icon_size;
if (!(get_icon_text_metrics( hwnd, &tm ))) return;
icon_cx = GetSystemMetrics( SM_CXICON );
icon_cy = GetSystemMetrics( SM_CYICON );
icon_size = max( icon_cx, icon_cy );
title_cy = tm.tmHeight * 2;
title_cx = max( tm.tmAveCharWidth * TITLE_CHARS, icon_size + PADDING_SIZE + title_cy );
launcher_size = BORDER_SIZE + title_cx + BORDER_SIZE;
icon_offset_cx = (launcher_size - icon_cx) / 2;
icon_offset_cy = BORDER_SIZE + (icon_size - icon_cy) / 2;
title_offset_cx = BORDER_SIZE;
title_offset_cy = BORDER_SIZE + icon_size + PADDING_SIZE;
desktop_width = GetSystemMetrics( SM_CXSCREEN );
launchers_per_row = desktop_width / launcher_size;
hr = SHGetKnownFolderPath( &FOLDERID_Desktop, KF_FLAG_CREATE, NULL, &desktop_folder );
if (FAILED( hr ))
{
WINE_ERR("Could not get user desktop folder\n");
return;
}
hr = SHGetKnownFolderPath( &FOLDERID_PublicDesktop, KF_FLAG_CREATE, NULL, &desktop_folder_public );
if (FAILED( hr ))
{
WINE_ERR("Could not get public desktop folder\n");
CoTaskMemFree( desktop_folder );
return;
}
if ((launchers = HeapAlloc( GetProcessHeap(), 0, 2 * sizeof(launchers[0]) )))
{
nb_allocated = 2;
init = CoInitialize( NULL );
add_folder( desktop_folder );
add_folder( desktop_folder_public );
if (SUCCEEDED( init )) CoUninitialize();
CreateThread( NULL, 0, watch_desktop_folders, hwnd, 0, NULL );
}
}
示例14: InitLua
void InitLua()
{
CHAR version[64];
lua = luaL_newstate();
if(lua == nullptr)
{
return;
}
luaL_openlibs(lua);
luaL_newlib(lua, luaFuncs);
lua_setglobal(lua, u8"crvmgr");
//skk-version
_snprintf_s(version, _TRUNCATE, "%s", WCTOU8(TEXTSERVICE_NAME L" " TEXTSERVICE_VER));
lua_pushstring(lua, version);
lua_setglobal(lua, u8"SKK_VERSION");
//%AppData%\\CorvusSKK\\init.lua
if(luaL_dofile(lua, WCTOU8(pathinitlua)) == LUA_OK)
{
return;
}
ZeroMemory(pathinitlua, sizeof(pathinitlua));
#ifdef _DEBUG
//<module directory>\\init.lua
if(GetModuleFileNameW(nullptr, pathinitlua, _countof(pathinitlua)) != 0)
{
WCHAR *pdir = wcsrchr(pathinitlua, L'\\');
if(pdir != nullptr)
{
*(pdir + 1) = L'\0';
wcsncat_s(pathinitlua, fninitlua, _TRUNCATE);
}
}
#else
PWSTR knownfolderpath = nullptr;
//%SystemRoot%\\IME\\IMCRVSKK\\init.lua
if(SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Windows, KF_FLAG_DONT_VERIFY, nullptr, &knownfolderpath)))
{
_snwprintf_s(pathinitlua, _TRUNCATE, L"%s\\%s\\%s\\%s", knownfolderpath, L"IME", TEXTSERVICE_DIR, fninitlua);
CoTaskMemFree(knownfolderpath);
}
#endif
if(luaL_dofile(lua, WCTOU8(pathinitlua)) == LUA_OK)
{
return;
}
UninitLua();
}
示例15: loggedInEvent
SpotifySession::SpotifySession() :
loggedInEvent(CreateEvent(NULL, FALSE, FALSE, NULL)),
threadData(spotifyCS), decoderOwner(NULL) {
processEventsEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
threadData.processEventsEvent = processEventsEvent;
threadData.sess = getAnyway();
memset(&initOnce, 0, sizeof(INIT_ONCE));
static sp_session_callbacks session_callbacks = {};
static sp_session_config spconfig = {};
PWSTR path;
if (SHGetKnownFolderPath(FOLDERID_LocalAppData, 0, NULL, &path))
throw pfc::exception("couldn't get local app data path");
size_t num;
char lpath[MAX_PATH];
if (wcstombs_s(&num, lpath, MAX_PATH, path, MAX_PATH)) {
CoTaskMemFree(path);
throw pfc::exception("couldn't convert local app data path");
}
CoTaskMemFree(path);
if (strcat_s(lpath, "\\foo_input_spotify"))
throw pfc::exception("couldn't append to path");
spconfig.api_version = SPOTIFY_API_VERSION,
spconfig.cache_location = lpath;
spconfig.settings_location = lpath;
spconfig.application_key = g_appkey;
spconfig.application_key_size = g_appkey_size;
spconfig.user_agent = "spotify-foobar2000-faux-" MYVERSION;
spconfig.userdata = this;
spconfig.callbacks = &session_callbacks;
session_callbacks.logged_in = &logged_in;
session_callbacks.notify_main_thread = ¬ify_main_thread;
session_callbacks.music_delivery = &music_delivery;
session_callbacks.play_token_lost = &play_token_lost;
session_callbacks.end_of_track = &end_of_track;
session_callbacks.log_message = &log_message;
session_callbacks.message_to_user = &message_to_user;
session_callbacks.start_playback = &start_playback;
{
LockedCS lock(spotifyCS);
if (NULL == CreateThread(NULL, 0, &spotifyThread, &threadData, 0, NULL)) {
throw pfc::exception("Couldn't create thread");
}
assertSucceeds("creating session", sp_session_create(&spconfig, &sp));
}
}