Windows SGPath::desktop() impl

Basic SHGetSpecialFolderPath wrapper, with dynamic
finding of the function since linking to shell32.dll
is painful. Obviously could be generalised to other
CSIDLs in the future.
This commit is contained in:
James Turner 2013-06-19 23:58:57 +01:00
parent aea2dab0d7
commit 23172bcdd0

View File

@ -519,10 +519,31 @@ SGPath SGPath::home()
#endif
#ifdef _WIN32
#include <ShlObj.h> // for CSIDL
//------------------------------------------------------------------------------
SGPath SGPath::desktop()
{
// TODO
typedef BOOL (WINAPI*GetSpecialFolderPath)(HWND, LPSTR, int, BOOL);
static GetSpecialFolderPath SHGetSpecialFolderPath = NULL;
// lazy open+resolve of shell32
if (!SHGetSpecialFolderPath) {
HINSTANCE shellDll = ::LoadLibrary("shell32");
SHGetSpecialFolderPath = (GetSpecialFolderPath) GetProcAddress(shellDll, "SHGetSpecialFolderPathA");
}
if (!SHGetSpecialFolderPath){
return SGPath();
}
char path[MAX_PATH];
if (SHGetSpecialFolderPath(0, path, CSIDL_DESKTOPDIRECTORY, false)) {
return SGPath(path);
}
SG_LOG(SG_GENERAL, SG_ALERT, "SGPath::desktop() failed, bad" );
return SGPath();
}
#elif __APPLE__