comparison win/dw.c @ 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 db26726118ba
children 0c39705ddd4a
comparison
equal deleted inserted replaced
906:71b0e132d9df 907:3e393a9375c4
11 #include <windows.h> 11 #include <windows.h>
12 #include <windowsx.h> 12 #include <windowsx.h>
13 #include <commctrl.h> 13 #include <commctrl.h>
14 #include <shlwapi.h> 14 #include <shlwapi.h>
15 #include <shlobj.h> 15 #include <shlobj.h>
16 #include <userenv.h>
16 #include <stdlib.h> 17 #include <stdlib.h>
17 #include <string.h> 18 #include <string.h>
18 #include <stdio.h> 19 #include <stdio.h>
19 #include <process.h> 20 #include <process.h>
20 #include <time.h> 21 #include <time.h>
10143 * current user directory. Or the root directory (C:\ on 10144 * current user directory. Or the root directory (C:\ on
10144 * OS/2 and Windows). 10145 * OS/2 and Windows).
10145 */ 10146 */
10146 char * API dw_user_dir(void) 10147 char * API dw_user_dir(void)
10147 { 10148 {
10148 static char _user_dir[1024] = ""; 10149 static char _user_dir[1024] = "";
10149 10150
10150 if(!_user_dir[0]) 10151 if(!_user_dir[0])
10151 { 10152 {
10152 /* Figure out how to do this the "Windows way" */ 10153 HANDLE hToken = 0;
10153 char *home = getenv("HOME"); 10154
10154 10155 /* Use the Windows API to get the user's profile directory */
10155 if(home) 10156 if(OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
10156 strcpy(_user_dir, home); 10157 {
10157 else 10158 DWORD BufSize = 1024;
10158 strcpy(_user_dir, "C:\\"); 10159
10159 } 10160 GetUserProfileDirectory(hToken, _user_dir, &BufSize);
10160 return _user_dir; 10161 CloseHandle(hToken);
10162 }
10163 /* If it fails set it to the root directory */
10164 if(!_user_dir[0])
10165 {
10166 strcpy(_user_dir, "C:\\");
10167 }
10168 }
10169 return _user_dir;
10161 } 10170 }
10162 10171
10163 /* 10172 /*
10164 * Call a function from the window (widget)'s context. 10173 * Call a function from the window (widget)'s context.
10165 * Parameters: 10174 * Parameters: