Remove dynamic loading of SHGetFolderPath and SHGetSpecialFolderPath.
SHGetFolderPath is available since Win2k and no fallback to the outdated SHGetSpecialFolderPath is required.
This commit is contained in:
@@ -42,8 +42,6 @@
|
||||
// types
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
typedef HRESULT (WINAPI *SHGetFolderPath_t)(HWND, int, HANDLE, DWORD, LPTSTR);
|
||||
typedef HRESULT (WINAPI *SHGetSpecialFolderPath_t)(HWND, LPTSTR, int, BOOL);
|
||||
typedef HRESULT (WINAPI *SHGetKnownFolderPath_t)(const GUID&, DWORD, HANDLE, PWSTR *);
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
@@ -95,13 +93,10 @@ struct ShellFunctions
|
||||
{
|
||||
ShellFunctions()
|
||||
{
|
||||
pSHGetFolderPath = NULL;
|
||||
pSHGetSpecialFolderPath = NULL;
|
||||
pSHGetKnownFolderPath = NULL;
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
SHGetFolderPath_t pSHGetFolderPath;
|
||||
SHGetSpecialFolderPath_t pSHGetSpecialFolderPath;
|
||||
SHGetKnownFolderPath_t pSHGetKnownFolderPath;
|
||||
|
||||
bool initialized;
|
||||
@@ -134,30 +129,9 @@ void ResolveShellFunctions()
|
||||
// with this
|
||||
wxLogNull noLog;
|
||||
|
||||
#if wxUSE_UNICODE
|
||||
static const wchar_t UNICODE_SUFFIX = L'W';
|
||||
#else // !Unicode
|
||||
static const char UNICODE_SUFFIX = 'A';
|
||||
#endif // Unicode/!Unicode
|
||||
|
||||
wxString funcname(wxT("SHGetFolderPath"));
|
||||
gs_shellFuncs.pSHGetFolderPath =
|
||||
(SHGetFolderPath_t)dllShellFunctions.GetSymbol(funcname + UNICODE_SUFFIX);
|
||||
|
||||
// then for SHGetSpecialFolderPath (shell32.dll 4.71)
|
||||
if ( !gs_shellFuncs.pSHGetFolderPath )
|
||||
{
|
||||
funcname = wxT("SHGetSpecialFolderPath");
|
||||
gs_shellFuncs.pSHGetSpecialFolderPath = (SHGetSpecialFolderPath_t)
|
||||
dllShellFunctions.GetSymbol(funcname + UNICODE_SUFFIX);
|
||||
}
|
||||
|
||||
gs_shellFuncs.pSHGetKnownFolderPath = (SHGetKnownFolderPath_t)
|
||||
dllShellFunctions.GetSymbol("SHGetKnownFolderPath");
|
||||
|
||||
// finally we fall back on SHGetSpecialFolderLocation (shell32.dll 4.0),
|
||||
// but we don't need to test for it -- it is available even under Win95
|
||||
|
||||
// shell32.dll is going to be unloaded, but it still remains in memory
|
||||
// because we also link to it statically, so it's ok
|
||||
|
||||
@@ -178,74 +152,35 @@ void ResolveShellFunctions()
|
||||
/* static */
|
||||
wxString wxStandardPaths::DoGetDirectory(int csidl)
|
||||
{
|
||||
if ( !gs_shellFuncs.initialized )
|
||||
ResolveShellFunctions();
|
||||
|
||||
wxString dir;
|
||||
HRESULT hr = E_FAIL;
|
||||
|
||||
// test whether the function is available during compile-time (it must be
|
||||
// defined as either "SHGetFolderPathA" or "SHGetFolderPathW")
|
||||
#ifdef SHGetFolderPath
|
||||
// and now test whether we have it during run-time
|
||||
if ( gs_shellFuncs.pSHGetFolderPath )
|
||||
{
|
||||
hr = gs_shellFuncs.pSHGetFolderPath
|
||||
(
|
||||
NULL, // parent window, not used
|
||||
csidl,
|
||||
NULL, // access token (current user)
|
||||
SHGFP_TYPE_CURRENT, // current path, not just default value
|
||||
wxStringBuffer(dir, MAX_PATH)
|
||||
);
|
||||
hr = ::SHGetFolderPath
|
||||
(
|
||||
NULL, // parent window, not used
|
||||
csidl,
|
||||
NULL, // access token (current user)
|
||||
SHGFP_TYPE_CURRENT, // current path, not just default value
|
||||
wxStringBuffer(dir, MAX_PATH)
|
||||
);
|
||||
|
||||
// somewhat incredibly, the error code in the Unicode version is
|
||||
// different from the one in ASCII version for this function
|
||||
// somewhat incredibly, the error code in the Unicode version is
|
||||
// different from the one in ASCII version for this function
|
||||
#if wxUSE_UNICODE
|
||||
if ( hr == E_FAIL )
|
||||
if ( hr == E_FAIL )
|
||||
#else
|
||||
if ( hr == S_FALSE )
|
||||
if ( hr == S_FALSE )
|
||||
#endif
|
||||
{
|
||||
// directory doesn't exist, maybe we can get its default value?
|
||||
hr = gs_shellFuncs.pSHGetFolderPath
|
||||
(
|
||||
NULL,
|
||||
csidl,
|
||||
NULL,
|
||||
SHGFP_TYPE_DEFAULT,
|
||||
wxStringBuffer(dir, MAX_PATH)
|
||||
);
|
||||
}
|
||||
}
|
||||
#endif // SHGetFolderPath
|
||||
|
||||
#ifdef SHGetSpecialFolderPath
|
||||
if ( FAILED(hr) && gs_shellFuncs.pSHGetSpecialFolderPath )
|
||||
{
|
||||
hr = gs_shellFuncs.pSHGetSpecialFolderPath
|
||||
(
|
||||
NULL, // parent window
|
||||
wxStringBuffer(dir, MAX_PATH),
|
||||
// directory doesn't exist, maybe we can get its default value?
|
||||
hr = ::SHGetFolderPath
|
||||
(
|
||||
NULL,
|
||||
csidl,
|
||||
FALSE // don't create if doesn't exist
|
||||
);
|
||||
}
|
||||
#endif // SHGetSpecialFolderPath
|
||||
|
||||
// SHGetSpecialFolderLocation should be available with all compilers and
|
||||
// under all Win32 systems, so don't test for it (and as it doesn't exist
|
||||
// in "A" and "W" versions anyhow, testing would be more involved, too)
|
||||
if ( FAILED(hr) )
|
||||
{
|
||||
LPITEMIDLIST pidl;
|
||||
hr = SHGetSpecialFolderLocation(NULL, csidl, &pidl);
|
||||
|
||||
if ( SUCCEEDED(hr) )
|
||||
{
|
||||
// creating this temp object has (nice) side effect of freeing pidl
|
||||
dir = wxItemIdList(pidl).GetPath();
|
||||
}
|
||||
NULL,
|
||||
SHGFP_TYPE_DEFAULT,
|
||||
wxStringBuffer(dir, MAX_PATH)
|
||||
);
|
||||
}
|
||||
|
||||
return dir;
|
||||
|
Reference in New Issue
Block a user