47 lines
1.6 KiB
C
47 lines
1.6 KiB
C
#include "common.h"
|
|
#include "shell32.h"
|
|
#include <shlobj.h>
|
|
|
|
DLL_EXPORT WINAPI HRESULT SHGetFolderPathW(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath) {
|
|
if (hwnd != NULL) {
|
|
logWarn("SHGetFolderPathW: Reserved hwnd not NULL");
|
|
}
|
|
if (hToken != NULL) {
|
|
logWarn("SHGetFolderPathW: Ignoring unsupported hToken");
|
|
}
|
|
if (csidl & CSIDL_FLAG_CREATE) {
|
|
logDebug("SHGetFolderPathW: CSIDL_FLAG_CREATE used");
|
|
csidl &= ~CSIDL_FLAG_CREATE;
|
|
}
|
|
if (dwFlags != SHGFP_TYPE_CURRENT) {
|
|
logWarn("SHGetFolderPathW: Ignoring non SHGFP_TYPE_CURRENT flag");
|
|
}
|
|
logDebug("SHGetFolderPathW: Called with CSIDL %x", csidl);
|
|
PIDLIST_ABSOLUTE list;
|
|
HRESULT result = SHGetSpecialFolderLocation(hwnd, csidl, &list);
|
|
if (result != S_OK) {
|
|
logError("SHGetFolderPathW: SHGetSpecialFolderLocation failed: %x", result);
|
|
*pszPath = L'\0';
|
|
return result;
|
|
}
|
|
if (!SHGetPathFromIDListW(list, pszPath)) {
|
|
logError("SHGetFolderPathW: SHGetPathFromIDListW failed");
|
|
*pszPath = L'\0';
|
|
return result;
|
|
}
|
|
char path[MAX_PATH];
|
|
wcstombs(path, pszPath, MAX_PATH);
|
|
logDebug("SHGetFolderPathW: %d=%s", csidl, path);
|
|
|
|
CoTaskMemFree(list);
|
|
return S_OK;
|
|
}
|
|
|
|
DLL_EXPORT WINAPI BOOL SHGetSpecialFolderPathW(HWND hwnd, LPWSTR pszPath, int csidl, BOOL fCreate) {
|
|
logDebug("SHGetSpecialFolderPathW: Wrapping SHGetFolderPathW");
|
|
if (fCreate) {
|
|
csidl |= CSIDL_FLAG_CREATE;
|
|
}
|
|
return SHGetFolderPathW(hwnd, csidl, NULL, SHGFP_TYPE_CURRENT, pszPath) == S_OK;
|
|
}
|