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
|
// 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 *);
|
typedef HRESULT (WINAPI *SHGetKnownFolderPath_t)(const GUID&, DWORD, HANDLE, PWSTR *);
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -95,13 +93,10 @@ struct ShellFunctions
|
|||||||
{
|
{
|
||||||
ShellFunctions()
|
ShellFunctions()
|
||||||
{
|
{
|
||||||
pSHGetFolderPath = NULL;
|
pSHGetKnownFolderPath = NULL;
|
||||||
pSHGetSpecialFolderPath = NULL;
|
|
||||||
initialized = false;
|
initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHGetFolderPath_t pSHGetFolderPath;
|
|
||||||
SHGetSpecialFolderPath_t pSHGetSpecialFolderPath;
|
|
||||||
SHGetKnownFolderPath_t pSHGetKnownFolderPath;
|
SHGetKnownFolderPath_t pSHGetKnownFolderPath;
|
||||||
|
|
||||||
bool initialized;
|
bool initialized;
|
||||||
@@ -134,30 +129,9 @@ void ResolveShellFunctions()
|
|||||||
// with this
|
// with this
|
||||||
wxLogNull noLog;
|
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)
|
gs_shellFuncs.pSHGetKnownFolderPath = (SHGetKnownFolderPath_t)
|
||||||
dllShellFunctions.GetSymbol("SHGetKnownFolderPath");
|
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
|
// shell32.dll is going to be unloaded, but it still remains in memory
|
||||||
// because we also link to it statically, so it's ok
|
// because we also link to it statically, so it's ok
|
||||||
|
|
||||||
@@ -178,19 +152,10 @@ void ResolveShellFunctions()
|
|||||||
/* static */
|
/* static */
|
||||||
wxString wxStandardPaths::DoGetDirectory(int csidl)
|
wxString wxStandardPaths::DoGetDirectory(int csidl)
|
||||||
{
|
{
|
||||||
if ( !gs_shellFuncs.initialized )
|
|
||||||
ResolveShellFunctions();
|
|
||||||
|
|
||||||
wxString dir;
|
wxString dir;
|
||||||
HRESULT hr = E_FAIL;
|
HRESULT hr = E_FAIL;
|
||||||
|
|
||||||
// test whether the function is available during compile-time (it must be
|
hr = ::SHGetFolderPath
|
||||||
// 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
|
NULL, // parent window, not used
|
||||||
csidl,
|
csidl,
|
||||||
@@ -208,7 +173,7 @@ wxString wxStandardPaths::DoGetDirectory(int csidl)
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
// directory doesn't exist, maybe we can get its default value?
|
// directory doesn't exist, maybe we can get its default value?
|
||||||
hr = gs_shellFuncs.pSHGetFolderPath
|
hr = ::SHGetFolderPath
|
||||||
(
|
(
|
||||||
NULL,
|
NULL,
|
||||||
csidl,
|
csidl,
|
||||||
@@ -217,36 +182,6 @@ wxString wxStandardPaths::DoGetDirectory(int csidl)
|
|||||||
wxStringBuffer(dir, MAX_PATH)
|
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),
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return dir;
|
return dir;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user