本文整理汇总了C++中SHGetFolderPathW函数的典型用法代码示例。如果您正苦于以下问题:C++ SHGetFolderPathW函数的具体用法?C++ SHGetFolderPathW怎么用?C++ SHGetFolderPathW使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SHGetFolderPathW函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetWildcardPath
gcString GetWildcardPath(gcString wildcard)
{
#ifdef WIN32
if (Safe::stricmp("PROGRAM_FILES", wildcard.c_str()) == 0)
{
wchar_t path[MAX_PATH] = {0};
SHGetFolderPathW(NULL, CSIDL_PROGRAM_FILES, NULL, SHGFP_TYPE_CURRENT, path);
return path;
}
else if (Safe::stricmp("DOCUMENTS", wildcard.c_str()) == 0)
{
return GetSpecialPath(1);
}
else if (Safe::stricmp("JAVA_PATH", wildcard.c_str()) == 0)
{
std::string cur = UTIL::WIN::getRegValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\CurrentVersion");
if (cur.size() > 0)
return UTIL::WIN::getRegValue(gcString("HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Runtime Environment\\{0}\\JavaHome", cur));
}
else if (Safe::stricmp("APP_DATA", wildcard.c_str())==0)
{
wchar_t path[MAX_PATH] = {0};
SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA, NULL, SHGFP_TYPE_CURRENT, path);
return path;
}
else if (Safe::stricmp("USER_APP_DATA", wildcard.c_str())==0)
{
return GetSpecialPath(2);
}
#endif
return "";
}
示例2: _T
// setup baseMenuFolder
void MetaLauncher::setBaseMenuFolder()
{
wchar_t path[MAX_PATH];
if (m_clientconn->m_opts.m_menuLoc == MENULOC_MIXLOCAL) {
if (SHGetFolderPathW(NULL, CSIDL_PROGRAMS, NULL, SHGFP_TYPE_CURRENT, path) != S_OK) {
vnclog.Print(0, _T("Failed to get menu directory.\n"));
return;
}
m_baseMenuFolder = new wchar_t[wcslen(path) + 1];
wcscpy(m_baseMenuFolder, path);
} else {
if (SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, SHGFP_TYPE_CURRENT, path) != S_OK) {
vnclog.Print(0, _T("Failed to get menu directory.\n"));
return;
}
m_baseMenuFolder = new wchar_t[wcslen(path) + wcslen(topMenuFolder) + wcslen(m_desktopFolderName) + 3];
wcscpy(m_baseMenuFolder, path);
wcscat(m_baseMenuFolder, L"\\");
wcscat(m_baseMenuFolder, topMenuFolder);
if (CreateDirectoryW(m_baseMenuFolder, NULL) == 0) {
vnclog.Print(0, _T("Failed to create menu directory. (error %d)\n"), GetLastError());
return;
}
if (m_clientconn->m_opts.m_menuLoc == MENULOC_SEPARATE) {
wcscat(m_baseMenuFolder, L"\\");
wcscat(m_baseMenuFolder, m_desktopFolderName);
if (CreateDirectoryW(m_baseMenuFolder, NULL) == 0) {
vnclog.Print(0, _T("Failed to create menu directory. (error %d)\n"), GetLastError());
return;
}
}
}
}
示例3: uninstall_tox
static int uninstall_tox()
{
if (MessageBox(NULL, "Are you sure you want to uninstall uTox?", "uTox Updater", MB_YESNO | MB_ICONQUESTION | MB_SETFOREGROUND) == IDYES) {
wchar_t wsz[MAX_PATH + 64];
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_STARTMENU, NULL, 0, wsz))) {
wcscat(wsz, L"\\Programs\\Tox.lnk");
DeleteFileW(wsz);
}
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_DESKTOPDIRECTORY, NULL, 0, wsz))) {
wcscat(wsz, L"\\Tox.lnk");
DeleteFileW(wsz);
}
SHDeleteKey(HKEY_CURRENT_USER, "Software\\Classes\\tox");
SHDeleteKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\uTox");
SHDeleteValue(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", "uTox");
DeleteFile(TOX_EXE_NAME);
DeleteFile(TOX_VERSION_FILENAME);
MessageBox(main_window, "uTox uninstalled.", "uTox Updater", MB_OK | MB_SETFOREGROUND);
}
exit(0);
}
示例4: ini_ssl
static void ini_ssl(void) {
static int inited = 0;
if (inited) return;
OpenSSL_add_all_algorithms();
SSL_load_error_strings();
SSL_library_init();
while (!RAND_status()) {
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
RAND_add(&ts.tv_nsec, sizeof(ts.tv_nsec), 0.1);
}
inited = 1;
#ifdef WIN32
{
WCHAR fnm[MAX_PATH];
char buf[MAX_PATH];
static char sbuf[MAX_PATH];
if (SHGetFolderPathW(0, CSIDL_WINDOWS, NULL, 0, fnm) != S_OK) {
check_error(set_errno(ERR_OTHER, "Cannot get WINDOWS folder path"));
}
if (!WideCharToMultiByte(CP_UTF8, 0, fnm, -1, buf, sizeof(buf), NULL, NULL)) {
check_error(set_win32_errno(GetLastError()));
}
snprintf(sbuf, sizeof(sbuf), "%s/TCF", buf);
tcf_dir = sbuf;
}
#endif
}
示例5: update_shell_folder_listview
static void update_shell_folder_listview(HWND dialog) {
int i;
LVITEMW item;
LONG lSelected = SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_GETNEXTITEM, -1,
MAKELPARAM(LVNI_SELECTED,0));
SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_DELETEALLITEMS, 0, 0);
for (i=0; i<NUM_ELEMS(asfiInfo); i++) {
WCHAR buffer[MAX_PATH];
HRESULT hr;
LPITEMIDLIST pidlCurrent;
/* Some acrobatic to get the localized name of the shell folder */
hr = SHGetFolderLocation(dialog, asfiInfo[i].nFolder, NULL, 0, &pidlCurrent);
if (SUCCEEDED(hr)) {
LPSHELLFOLDER psfParent;
LPCITEMIDLIST pidlLast;
hr = SHBindToParent(pidlCurrent, &IID_IShellFolder, (LPVOID*)&psfParent, &pidlLast);
if (SUCCEEDED(hr)) {
STRRET strRet;
hr = IShellFolder_GetDisplayNameOf(psfParent, pidlLast, SHGDN_FORADDRESSBAR, &strRet);
if (SUCCEEDED(hr)) {
hr = StrRetToBufW(&strRet, pidlLast, buffer, MAX_PATH);
}
IShellFolder_Release(psfParent);
}
ILFree(pidlCurrent);
}
/* If there's a dangling symlink for the current shell folder, SHGetFolderLocation
* will fail above. We fall back to the (non-verified) path of the shell folder. */
if (FAILED(hr)) {
hr = SHGetFolderPathW(dialog, asfiInfo[i].nFolder|CSIDL_FLAG_DONT_VERIFY, NULL,
SHGFP_TYPE_CURRENT, buffer);
}
item.mask = LVIF_TEXT | LVIF_PARAM;
item.iItem = i;
item.iSubItem = 0;
item.pszText = buffer;
item.lParam = (LPARAM)&asfiInfo[i];
SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_INSERTITEMW, 0, (LPARAM)&item);
item.mask = LVIF_TEXT;
item.iItem = i;
item.iSubItem = 1;
item.pszText = strdupU2W(asfiInfo[i].szLinkTarget);
SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMW, 0, (LPARAM)&item);
HeapFree(GetProcessHeap(), 0, item.pszText);
}
/* Ensure that the previously selected item is selected again. */
if (lSelected >= 0) {
item.mask = LVIF_STATE;
item.state = LVIS_SELECTED;
item.stateMask = LVIS_SELECTED;
SendDlgItemMessageW(dialog, IDC_LIST_SFPATHS, LVM_SETITEMSTATE, lSelected, (LPARAM)&item);
}
}
示例6: FolderItemImpl_get_Path
static HRESULT WINAPI FolderItemImpl_get_Path(FolderItem *iface, BSTR *pbs)
{
FolderItemImpl *This = impl_from_FolderItem(iface);
HRESULT ret = S_OK;
WCHAR *pathW;
int len;
TRACE("(%p,%p)\n", iface, pbs);
*pbs = NULL;
if (V_VT(&This->dir) == VT_I4)
{
pathW = HeapAlloc(GetProcessHeap(), 0, MAX_PATH * sizeof(WCHAR));
if (!pathW) return E_OUTOFMEMORY;
ret = SHGetFolderPathW(NULL, V_I4(&This->dir), NULL, SHGFP_TYPE_CURRENT,
pathW);
if (ret == S_OK)
*pbs = SysAllocString(pathW);
else if (ret == E_INVALIDARG)
{
FIXME("not implemented for %#x\n", V_I4(&This->dir));
ret = E_NOTIMPL;
}
HeapFree(GetProcessHeap(), 0, pathW);
}
else /* VT_BSTR */
{
pathW = V_BSTR(&This->dir);
len = lstrlenW(pathW);
*pbs = SysAllocStringLen(pathW, pathW[len - 1] == '\\' ? len - 1 : len);
}
if (ret == S_OK && !*pbs)
ret = E_OUTOFMEMORY;
return ret;
}
示例7: SHGetFolderPathW
//Todo Support It
//Don't Support D3D8 Game In Xp And Vista
bool h3d::BeginD3D8CaptureHook() {
wchar_t sD3D8Path[MAX_PATH];
SHGetFolderPathW(NULL, CSIDL_SYSTEM, NULL, SHGFP_TYPE_CURRENT, sD3D8Path);
wcscat_s(sD3D8Path, MAX_PATH, L"\\D3D8.dll");
HMODULE hD3D8Dll = GetModuleHandle(sD3D8Path);
if (hD3D8Dll) {
PTR addr = reinterpret_cast<PTR>(hD3D8Dll);
PTR end_sceneoffset = 0;
UINT version = GetOSVersion();
if (version == 7)
end_sceneoffset = 0x44530;
if (version >= 8)
end_sceneoffset = 0x33540;
if (end_sceneoffset) {
d3d8end_scene.Do((WINAPIPROC)(addr + end_sceneoffset), (WINAPIPROC)EndScne);
return true;
}
}
return false;
}
示例8: WideCharToMultiByte
const char *win32_get_config_system(const char *dir)
{
static char appdir[PATH_MAX] = "";
wchar_t wdir[MAX_PATH];
if (!dir) {
// first call
if (*appdir)
return appdir;
/* Get the "Application Data" folder for all users */
if (S_OK == SHGetFolderPathW(NULL, CSIDL_COMMON_APPDATA | CSIDL_FLAG_CREATE,
NULL, SHGFP_TYPE_CURRENT, wdir)) {
WideCharToMultiByte (CP_UTF8, 0, wdir, -1, appdir, PATH_MAX, NULL, NULL);
return appdir;
} else {
DEBUG(DBG_FILE, "Can't find common configuration directory !\n");
return NULL;
}
} else {
// next call
return NULL;
}
return dir;
}
示例9: talloc_new
char *mp_get_win_config_path(const char *filename)
{
wchar_t w_appdir[MAX_PATH + 1] = {0};
wchar_t w_exedir[MAX_PATH + 1] = {0};
char *res = NULL;
void *tmp = talloc_new(NULL);
#ifndef __CYGWIN__
if (SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA|CSIDL_FLAG_CREATE, NULL,
SHGFP_TYPE_CURRENT, w_appdir) != S_OK)
w_appdir[0] = '\0';
#endif
get_exe_dir(w_exedir);
if (filename && filename[0] && w_exedir[0]) {
char *dir = mp_to_utf8(tmp, w_exedir);
char *temp = mp_path_join(tmp, bstr0(dir), bstr0("mpv"));
res = mp_path_join(NULL, bstr0(temp), bstr0(filename));
if (!mp_path_exists(res) || mp_path_isdir(res)) {
talloc_free(res);
res = NULL;
}
}
if (!res && w_appdir[0]) {
char *dir = mp_to_utf8(tmp, w_appdir);
char *temp = mp_path_join(tmp, bstr0(dir), bstr0("mpv"));
res = mp_path_join(NULL, bstr0(temp), bstr0(filename));
}
talloc_free(tmp);
return res;
}
示例10: mySHGetKnownFolderPath
/**
* Wrapper um SHGetKnownFolderPath, unter Vista und Größer benutzt es das
* originale SHGetKnownFolderPath, ansonsten SHGetFolderPath.
*
* @param[in] rfid
* @param[in] path
*
* @return liefert den Status zurück (S_OK bei OK)
*
* @author FloSoft
*/
static HRESULT mySHGetKnownFolderPath(REFKNOWNFOLDERID rfid, std::string& path)
{
HRESULT retval = S_FALSE;
LPWSTR ppszPath = NULL;
if(!gShell32DLLInst)
gShell32DLLInst = LoadLibraryW(L"Shell32.dll");
if(gShell32DLLInst && !gSHGetKnownFolderPath)
gSHGetKnownFolderPath = (LPSHGetKnownFolderPath)GetProcAddress(gShell32DLLInst, "SHGetKnownFolderPath");
if(gSHGetKnownFolderPath)
retval = gSHGetKnownFolderPath(rfid, KF_FLAG_CREATE, NULL, &ppszPath);
else if(rfid == FOLDERID_Documents)
{
ppszPath = (LPWSTR)CoTaskMemAlloc(MAX_PATH * sizeof(WCHAR));
if(SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 0, ppszPath)))
retval = S_OK;
}
if(ppszPath)
{
LPSTR ppszPathA = UnicodeToAnsi(ppszPath);
path = ppszPathA;
CoTaskMemFree(ppszPath);
delete[] ppszPathA;
}
return retval;
}
示例11: strlen
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
{
/*
* Vista and later has a new API for this, but SHGetFolderPath works there,
* and apparently just wraps the new API. This is the new way to do it:
*
* SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_CREATE,
* NULL, &wszPath);
*/
WCHAR path[MAX_PATH];
char *utf8 = NULL;
size_t len = 0;
char *retval = NULL;
if (!SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
NULL, 0, path)))
BAIL_MACRO(PHYSFS_ERR_OS_ERROR, NULL);
utf8 = unicodeToUtf8Heap(path);
BAIL_IF_MACRO(!utf8, ERRPASS, NULL);
len = strlen(utf8) + strlen(org) + strlen(app) + 4;
retval = allocator.Malloc(len);
if (!retval)
{
allocator.Free(utf8);
BAIL_MACRO(PHYSFS_ERR_OUT_OF_MEMORY, NULL);
} /* if */
sprintf(retval, "%s\\%s\\%s\\", utf8, org, app);
return retval;
} /* __PHYSFS_platformCalcPrefDir */
示例12: getQDevelopPath
//static function to determine the QDevelop directory (used for settings and global ctags database)
// the directory is returnded WITH a trailing slash
QString getQDevelopPath(void)
{
static QString path;
if (!path.isEmpty()) return path;
// if we havn't yet done so, determine the full db file name and make sure the directory exists
// determine path for application data dirs
#ifdef Q_OS_WIN32
wchar_t buf[MAX_PATH];
if (!SHGetFolderPathW(NULL, CSIDL_APPDATA, NULL, 0, buf))
path = QString::fromUtf16((ushort *)buf)+"/";
else
path = QDir::homePath()+"/Application Data/"; // this shouldn't happen
#else
path = QDir::homePath()+"/";
#endif
// create subdir
QDir dir(path);
#ifdef Q_OS_WIN32
dir.mkdir("QDevelop");
path += "QDevelop/";
#else
dir.mkdir(".qdevelop");
path += ".qdevelop/";
#endif
return path;
}
示例13: GAMEUX_buildStatisticsFilePath
/*******************************************************************************
* GAMEUX_buildStatisticsFilePath
* Creates path to file containing statistics of game with given id.
*
* Parameters:
* lpApplicationId [I] application id of game,
* as string
* lpStatisticsFile [O] array where path will be
* stored. Its size must be
* at least MAX_PATH
*/
static HRESULT GAMEUX_buildStatisticsFilePath(
LPCWSTR lpApplicationId,
LPWSTR lpStatisticsFile)
{
static const WCHAR sBackslash[] = {'\\',0};
static const WCHAR sStatisticsDir[] = {'\\','M','i','c','r','o','s','o','f','t',
'\\','W','i','n','d','o','w','s','\\','G','a','m','e','E','x','p',
'l','o','r','e','r','\\','G','a','m','e','S','t','a','t','i','s',
't','i','c','s','\\',0};
static const WCHAR sDotGamestats[] = {'.','g','a','m','e','s','t','a','t','s',0};
HRESULT hr;
hr = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, SHGFP_TYPE_CURRENT, lpStatisticsFile);
if(SUCCEEDED(hr))
{
lstrcatW(lpStatisticsFile, sStatisticsDir);
lstrcatW(lpStatisticsFile, lpApplicationId);
lstrcatW(lpStatisticsFile, sBackslash);
lstrcatW(lpStatisticsFile, lpApplicationId);
lstrcatW(lpStatisticsFile, sDotGamestats);
}
return hr;
}
示例14: ShowSaveDialog
static int ShowSaveDialog(wchar_t* name, size_t nameLength)
{
wchar_t* defaultPath = xmalloc(MAX_PATH * sizeof(wchar_t));
OPENFILENAMEW ofn = {
.lStructSize = sizeof(OPENFILENAMEW),
.lpstrFilter = L"PNG image\0*.png\0",
.nFilterIndex = 1,
.lpstrFile = name,
.nMaxFile = nameLength,
.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST,
};
/* This may seem like an archaic way of getting the default pictures
directory since it doesn't understand Windows 7 libraries, however
GetSaveFileName will open the library anyway if given CSIDL_MYPICTURES
and doing it this way is backwards compatible with Windows Vista */
if (SHGetFolderPathW(NULL, CSIDL_MYPICTURES, NULL, SHGFP_TYPE_CURRENT, defaultPath) == S_OK)
ofn.lpstrInitialDir = defaultPath;
if (!GetSaveFileNameW(&ofn))
{
free(defaultPath);
return 0;
}
free(defaultPath);
return 1;
}
static FILE* OpenFileWrite(wchar_t* name)
{
/* Every Windows program should have a variant of this function to replace
fopen. That is, one that supports Unicode and FILE_SHARE_DELETE. */
HANDLE winHandle = CreateFileW(
name,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_DELETE,
NULL,
CREATE_ALWAYS,
0, NULL);
if (!winHandle)
return NULL;
int crtHandle = _open_osfhandle((intptr_t)winHandle, 0);
if (crtHandle == -1)
{
CloseHandle(winHandle);
return NULL;
}
FILE* result = _fdopen(crtHandle, "wb");
if (!result)
{
_close(crtHandle);
return NULL;
}
return result;
}
示例15: defined
const char *config_GetConfDir (void)
{
static char appdir[PATH_MAX] = "";
wchar_t wdir[MAX_PATH];
#warning FIXME: thread-safety!
if (*appdir)
return appdir;
#if defined (UNDER_CE)
/*There are some errors in cegcc headers*/
#undef SHGetSpecialFolderPath
BOOL WINAPI SHGetSpecialFolderPath(HWND,LPWSTR,int,BOOL);
if( SHGetSpecialFolderPath( NULL, wdir, CSIDL_APPDATA, 1 ) )
#else
/* Get the "Application Data" folder for all users */
if( S_OK == SHGetFolderPathW( NULL, CSIDL_COMMON_APPDATA
| CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, wdir ) )
#endif
{
WideCharToMultiByte (CP_UTF8, 0, wdir, -1,
appdir, PATH_MAX, NULL, NULL);
return appdir;
}
return NULL;
}