]> git.mxchange.org Git - simgear.git/commitdiff
Windows SGPath::desktop() impl
authorJames Turner <zakalawe@mac.com>
Wed, 19 Jun 2013 22:58:57 +0000 (23:58 +0100)
committerJames Turner <zakalawe@mac.com>
Wed, 19 Jun 2013 22:58:57 +0000 (23:58 +0100)
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.

simgear/misc/sg_path.cxx

index 9267cedf6a1c6971cc76d28ca1bb8d415579f290..69d1ac4494f73302181f4a0693afb63918d42824 100644 (file)
@@ -519,11 +519,32 @@ SGPath SGPath::home()
 #endif
 
 #ifdef _WIN32
+
+#include <ShlObj.h> // for CSIDL
+
 //------------------------------------------------------------------------------
 SGPath SGPath::desktop()
 {
-  // TODO
-  return SGPath();
+       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__
 #include <CoreServices/CoreServices.h>