changeset 907:3e393a9375c4

Implemented _dw_user_dir() using GetUserProfileDirectory() on Windows. GetUserProfileDirectory is in userenv.dll which is a file only included on NT-based Windows versions. Therefore Windows 95/98/ME are no longer supported by Dynamic Windows.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Tue, 19 Apr 2011 07:55:07 +0000
parents 71b0e132d9df
children 850b2e6cfeab
files makefile.vc win/dw.c
diffstat 2 files changed, 23 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/makefile.vc	Tue Apr 19 05:54:01 2011 +0000
+++ b/makefile.vc	Tue Apr 19 07:55:07 2011 +0000
@@ -48,7 +48,7 @@
 
 CC = cl
 CFLAGS = -c $(PLATFORM_DEF) -D__WIN32__ -DMSVC -DBUILD_DLL -I$(SRCDIR)\platform -I$(SRCDIR)
-LIBS = wsock32.lib kernel32.lib user32.lib comctl32.lib gdi32.lib advapi32.lib shell32.lib comdlg32.lib ole32.lib oleaut32.lib
+LIBS = wsock32.lib kernel32.lib user32.lib comctl32.lib gdi32.lib advapi32.lib shell32.lib comdlg32.lib ole32.lib oleaut32.lib userenv.lib
 RES =
 LINKFLAGS = -machine:$(TARGET_CPU) -manifest $(LINK_DEBUG)
 DLLLINKFLAGS = -dll
--- a/win/dw.c	Tue Apr 19 05:54:01 2011 +0000
+++ b/win/dw.c	Tue Apr 19 07:55:07 2011 +0000
@@ -13,6 +13,7 @@
 #include <commctrl.h>
 #include <shlwapi.h>
 #include <shlobj.h>
+#include <userenv.h>
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
@@ -10145,19 +10146,27 @@
  */
 char * API dw_user_dir(void)
 {
-   static char _user_dir[1024] = "";
-
-   if(!_user_dir[0])
-   {
-      /* Figure out how to do this the "Windows way" */
-      char *home = getenv("HOME");
-
-      if(home)
-         strcpy(_user_dir, home);
-      else
-         strcpy(_user_dir, "C:\\");
-   }
-   return _user_dir;
+    static char _user_dir[1024] = "";
+
+    if(!_user_dir[0])
+    {
+        HANDLE hToken = 0;
+        
+        /* Use the Windows API to get the user's profile directory */
+        if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
+        {
+            DWORD BufSize = 1024;
+        
+            GetUserProfileDirectory(hToken, _user_dir, &BufSize);
+            CloseHandle(hToken);
+        }
+        /* If it fails set it to the root directory */
+        if(!_user_dir[0])
+        {
+            strcpy(_user_dir, "C:\\");
+        }
+    }
+    return _user_dir;
 }
 
 /*