2 * Shell Library Functions
12 #include "selectors.h"
13 #include "../rc/sysres.h"
15 /* #define DEBUG_REG */
18 LPKEYSTRUCT lphRootKey
= NULL
,lphTopKey
= NULL
;
20 static char RootKeyName
[]=".classes", TopKeyName
[] = "(null)";
22 /*************************************************************************
23 * SHELL_RegCheckForRoot() internal use only
25 static LONG
SHELL_RegCheckForRoot()
29 if (lphRootKey
== NULL
){
30 hNewKey
= GlobalAlloc(GMEM_MOVEABLE
,sizeof(KEYSTRUCT
));
31 lphRootKey
= (LPKEYSTRUCT
) GlobalLock(hNewKey
);
32 if (lphRootKey
== NULL
) {
33 printf("SHELL_RegCheckForRoot: Couldn't allocate root key!\n");
34 return ERROR_OUTOFMEMORY
;
37 lphRootKey
->lpSubKey
= RootKeyName
;
38 lphRootKey
->dwType
= 0;
39 lphRootKey
->lpValue
= NULL
;
40 lphRootKey
->lpSubLvl
= lphRootKey
->lpNextKey
= lphRootKey
->lpPrevKey
= NULL
;
42 hNewKey
= GlobalAlloc(GMEM_MOVEABLE
,sizeof(KEYSTRUCT
));
43 lphTopKey
= (LPKEYSTRUCT
) GlobalLock(hNewKey
);
44 if (lphTopKey
== NULL
) {
45 printf("SHELL_RegCheckForRoot: Couldn't allocate top key!\n");
46 return ERROR_OUTOFMEMORY
;
49 lphTopKey
->lpSubKey
= TopKeyName
;
50 lphTopKey
->dwType
= 0;
51 lphTopKey
->lpValue
= NULL
;
52 lphTopKey
->lpSubLvl
= lphRootKey
;
53 lphTopKey
->lpNextKey
= lphTopKey
->lpPrevKey
= NULL
;
55 dprintf_reg(stddeb
,"SHELL_RegCheckForRoot: Root/Top created\n");
60 /*************************************************************************
61 * RegOpenKey [SHELL.1]
63 LONG
RegOpenKey(HKEY hKey
, LPCSTR lpSubKey
, HKEY FAR
*lphKey
)
70 dwRet
= SHELL_RegCheckForRoot();
71 if (dwRet
!= ERROR_SUCCESS
) return dwRet
;
72 dprintf_reg(stddeb
, "RegOpenKey(%08lX, %p='%s', %p)\n",
73 hKey
, lpSubKey
, lpSubKey
, lphKey
);
74 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
75 if (lphKey
== NULL
) return ERROR_INVALID_PARAMETER
;
78 lpKey
= lphTopKey
; break;
79 case HKEY_CLASSES_ROOT
: /* == 1 */
80 lpKey
= lphRootKey
; break;
82 dprintf_reg(stddeb
,"RegOpenKey // specific key = %08lX !\n", hKey
);
83 lpKey
= (LPKEYSTRUCT
)GlobalLock(hKey
);
85 if (!*lpSubKey
) { *lphKey
= hKey
; return ERROR_SUCCESS
; }
87 ptr
= strchr(lpSubKey
,'\\');
88 if (!ptr
) ptr
= lpSubKey
+ strlen(lpSubKey
);
89 strncpy(str
,lpSubKey
,ptr
-lpSubKey
);
90 str
[ptr
-lpSubKey
] = 0;
92 if (*lpSubKey
) lpSubKey
++;
94 lpKey
= lpKey
->lpSubLvl
;
95 while(lpKey
!= NULL
&& strcmp(lpKey
->lpSubKey
, str
) != 0) { lpKey
= lpKey
->lpNextKey
; }
97 dprintf_reg(stddeb
,"RegOpenKey: key %s not found!\n",str
);
101 *lphKey
= lpKey
->hKey
;
102 return ERROR_SUCCESS
;
106 /*************************************************************************
107 * RegCreateKey [SHELL.2]
109 LONG
RegCreateKey(HKEY hKey
, LPCSTR lpSubKey
, HKEY FAR
*lphKey
)
112 LPKEYSTRUCT lpNewKey
;
114 LPKEYSTRUCT lpPrevKey
;
119 dwRet
= SHELL_RegCheckForRoot();
120 if (dwRet
!= ERROR_SUCCESS
) return dwRet
;
121 dprintf_reg(stddeb
, "RegCreateKey(%08lX, '%s', %p)\n", hKey
, lpSubKey
, lphKey
);
122 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
123 if (lphKey
== NULL
) return ERROR_INVALID_PARAMETER
;
126 lpKey
= lphTopKey
; break;
127 case HKEY_CLASSES_ROOT
: /* == 1 */
128 lpKey
= lphRootKey
; break;
130 dprintf_reg(stddeb
,"RegCreateKey // specific key = %08lX !\n", hKey
);
131 lpKey
= (LPKEYSTRUCT
)GlobalLock(hKey
);
133 if (!*lpSubKey
) { *lphKey
= hKey
; return ERROR_SUCCESS
; }
135 dprintf_reg(stddeb
, "RegCreateKey: Looking for subkey %s\n", lpSubKey
);
136 ptr
= strchr(lpSubKey
,'\\');
137 if (!ptr
) ptr
= lpSubKey
+ strlen(lpSubKey
);
138 strncpy(str
,lpSubKey
,ptr
-lpSubKey
);
139 str
[ptr
-lpSubKey
] = 0;
141 if (*lpSubKey
) lpSubKey
++;
144 lpKey
= lpKey
->lpSubLvl
;
145 while(lpKey
!= NULL
&& strcmp(lpKey
->lpSubKey
, str
) != 0) {
146 lpKey
= lpKey
->lpNextKey
;
149 hNewKey
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(KEYSTRUCT
));
150 lpNewKey
= (LPKEYSTRUCT
) GlobalLock(hNewKey
);
151 if (lpNewKey
== NULL
) {
152 printf("RegCreateKey // Can't alloc new key !\n");
153 return ERROR_OUTOFMEMORY
;
155 lpNewKey
->hKey
= hNewKey
;
156 lpNewKey
->lpSubKey
= malloc(strlen(str
) + 1);
157 if (lpNewKey
->lpSubKey
== NULL
) {
158 printf("RegCreateKey // Can't alloc key string !\n");
159 return ERROR_OUTOFMEMORY
;
161 strcpy(lpNewKey
->lpSubKey
, str
);
162 lpNewKey
->lpNextKey
= lpPrevKey
->lpSubLvl
;
163 lpNewKey
->lpPrevKey
= NULL
;
164 lpPrevKey
->lpSubLvl
= lpNewKey
;
166 lpNewKey
->dwType
= 0;
167 lpNewKey
->lpValue
= NULL
;
168 lpNewKey
->lpSubLvl
= NULL
;
170 dprintf_reg(stddeb
,"RegCreateKey // successful '%s' key=%08lX !\n", str
, hNewKey
);
173 *lphKey
= lpKey
->hKey
;
174 dprintf_reg(stddeb
,"RegCreateKey // found '%s', key=%08lX\n", str
, *lphKey
);
177 return ERROR_SUCCESS
;
181 /*************************************************************************
182 * RegCloseKey [SHELL.3]
184 LONG
RegCloseKey(HKEY hKey
)
186 dprintf_reg(stdnimp
, "EMPTY STUB !!! RegCloseKey(%08lX);\n", hKey
);
187 return ERROR_INVALID_PARAMETER
;
191 /*************************************************************************
192 * RegDeleteKey [SHELL.4]
194 LONG
RegDeleteKey(HKEY hKey
, LPCSTR lpSubKey
)
196 dprintf_reg(stdnimp
, "EMPTY STUB !!! RegDeleteKey(%08lX, '%s');\n",
198 return ERROR_INVALID_PARAMETER
;
202 /*************************************************************************
203 * RegSetValue [SHELL.5]
205 LONG
RegSetValue(HKEY hKey
, LPCSTR lpSubKey
, DWORD dwType
,
206 LPCSTR lpVal
, DWORD dwIgnored
)
211 dprintf_reg(stddeb
, "RegSetValue(%08lX, '%s', %08lX, '%s', %08lX);\n",
212 hKey
, lpSubKey
, dwType
, lpVal
, dwIgnored
);
213 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
214 if (lpVal
== NULL
) return ERROR_INVALID_PARAMETER
;
215 if ((dwRet
= RegOpenKey(hKey
, lpSubKey
, &hRetKey
)) != ERROR_SUCCESS
) {
216 dprintf_reg(stddeb
, "RegSetValue // key not found ... so create it !\n");
217 if ((dwRet
= RegCreateKey(hKey
, lpSubKey
, &hRetKey
)) != ERROR_SUCCESS
) {
218 fprintf(stderr
, "RegSetValue // key creation error %08lX !\n", dwRet
);
222 lpKey
= (LPKEYSTRUCT
)GlobalLock(hRetKey
);
223 if (lpKey
== NULL
) return ERROR_BADKEY
;
224 if (lpKey
->lpValue
!= NULL
) free(lpKey
->lpValue
);
225 lpKey
->lpValue
= malloc(strlen(lpVal
) + 1);
226 strcpy(lpKey
->lpValue
, lpVal
);
227 dprintf_reg(stddeb
,"RegSetValue // successful key='%s' val='%s' !\n", lpSubKey
, lpKey
->lpValue
);
228 return ERROR_SUCCESS
;
232 /*************************************************************************
233 * RegQueryValue [SHELL.6]
235 LONG
RegQueryValue(HKEY hKey
, LPCSTR lpSubKey
, LPSTR lpVal
, LONG FAR
*lpcb
)
241 dprintf_reg(stddeb
, "RegQueryValue(%08lX, '%s', %p, %p);\n",
242 hKey
, lpSubKey
, lpVal
, lpcb
);
243 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
244 if (lpVal
== NULL
) return ERROR_INVALID_PARAMETER
;
245 if (lpcb
== NULL
) return ERROR_INVALID_PARAMETER
;
246 if (!*lpcb
) return ERROR_INVALID_PARAMETER
;
248 if ((dwRet
= RegOpenKey(hKey
, lpSubKey
, &hRetKey
)) != ERROR_SUCCESS
) {
249 fprintf(stderr
, "RegQueryValue // key not found !\n");
252 lpKey
= (LPKEYSTRUCT
)GlobalLock(hRetKey
);
253 if (lpKey
== NULL
) return ERROR_BADKEY
;
254 if (lpKey
->lpValue
!= NULL
) {
255 if ((size
= strlen(lpKey
->lpValue
)+1) > *lpcb
){
256 strncpy(lpVal
,lpKey
->lpValue
,*lpcb
-1);
259 strcpy(lpVal
,lpKey
->lpValue
);
266 dprintf_reg(stddeb
,"RegQueryValue // return '%s' !\n", lpVal
);
267 return ERROR_SUCCESS
;
271 /*************************************************************************
272 * RegEnumKey [SHELL.7]
274 LONG
RegEnumKey(HKEY hKey
, DWORD dwSubKey
, LPSTR lpBuf
, DWORD dwSize
)
280 dwRet
= SHELL_RegCheckForRoot();
281 if (dwRet
!= ERROR_SUCCESS
) return dwRet
;
282 dprintf_reg(stddeb
, "RegEnumKey(%08lX, %ld)\n", hKey
, dwSubKey
);
283 if (lpBuf
== NULL
) return ERROR_INVALID_PARAMETER
;
286 lpKey
= lphTopKey
; break;
287 case HKEY_CLASSES_ROOT
: /* == 1 */
288 lpKey
= lphRootKey
; break;
290 dprintf_reg(stddeb
,"RegEnumKey // specific key = %08lX !\n", hKey
);
291 lpKey
= (LPKEYSTRUCT
)GlobalLock(hKey
);
294 lpKey
= lpKey
->lpSubLvl
;
295 while(lpKey
!= NULL
){
297 len
= min(dwSize
-1,strlen(lpKey
->lpSubKey
));
298 strncpy(lpBuf
,lpKey
->lpSubKey
,len
);
300 dprintf_reg(stddeb
, "RegEnumKey: found %s\n",lpBuf
);
301 return ERROR_SUCCESS
;
304 lpKey
= lpKey
->lpNextKey
;
306 dprintf_reg(stddeb
, "RegEnumKey: key not found!\n");
307 return ERROR_INVALID_PARAMETER
;
310 /*************************************************************************
311 * DragAcceptFiles [SHELL.9]
313 void DragAcceptFiles(HWND hWnd
, BOOL b
)
315 dprintf_reg(stdnimp
, "DragAcceptFiles : Empty Stub !!!\n");
319 /*************************************************************************
320 * DragQueryFile [SHELL.11]
322 void DragQueryFile(HDROP h
, UINT u
, LPSTR u2
, UINT u3
)
324 dprintf_reg(stdnimp
, "DragQueryFile : Empty Stub !!!\n");
329 /*************************************************************************
330 * DragFinish [SHELL.12]
332 void DragFinish(HDROP h
)
334 dprintf_reg(stdnimp
, "DragFinish : Empty Stub !!!\n");
339 /*************************************************************************
340 * DragQueryPoint [SHELL.13]
342 BOOL
DragQueryPoint(HDROP h
, POINT FAR
*p
)
344 dprintf_reg(stdnimp
, "DragQueryPoinyt : Empty Stub !!!\n");
349 /*************************************************************************
350 * ShellExecute [SHELL.20]
352 HINSTANCE
ShellExecute(HWND hWnd
, LPCSTR lpOperation
, LPCSTR lpFile
, LPCSTR lpParameters
, LPCSTR lpDirectory
, int iShowCmd
)
354 dprintf_reg(stdnimp
, "ShellExecute // hWnd=%04X\n", hWnd
);
355 dprintf_reg(stdnimp
, "ShellExecute // lpOperation='%s'\n", lpOperation
);
356 dprintf_reg(stdnimp
, "ShellExecute // lpFile='%s'\n", lpFile
);
357 dprintf_reg(stdnimp
, "ShellExecute // lpParameters='%s'\n", lpParameters
);
358 dprintf_reg(stdnimp
, "ShellExecute // lpDirectory='%s'\n", lpDirectory
);
359 dprintf_reg(stdnimp
, "ShellExecute // iShowCmd=%04X\n", iShowCmd
);
360 return 2; /* file not found */
364 /*************************************************************************
365 * FindExecutable [SHELL.21]
367 HINSTANCE
FindExecutable(LPCSTR lpFile
, LPCSTR lpDirectory
, LPSTR lpResult
)
369 dprintf_reg(stdnimp
, "FindExecutable : Empty Stub !!!\n");
373 char AppName
[256], AppMisc
[256];
374 INT
AboutDlgProc(HWND hWnd
, WORD msg
, WORD wParam
, LONG lParam
);
376 /*************************************************************************
377 * ShellAbout [SHELL.22]
379 INT
ShellAbout(HWND hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
, HICON hIcon
)
381 /* fprintf(stderr, "ShellAbout ! (%s, %s)\n", szApp, szOtherStuff);*/
384 strcpy(AppName
, szApp
);
389 strcpy(AppMisc
, szOtherStuff
);
393 return DialogBoxIndirectPtr( GetWindowWord(hWnd
, GWW_HINSTANCE
),
394 sysres_DIALOG_SHELL_ABOUT_MSGBOX
,
395 hWnd
, GetWndProcEntry16("AboutDlgProc"));
399 /*************************************************************************
400 * AboutDlgProc [SHELL.33]
402 INT
AboutDlgProc(HWND hWnd
, WORD msg
, WORD wParam
, LONG lParam
)
408 sprintf(temp
, "About %s", AppName
);
409 SetWindowText(hWnd
, temp
);
410 SetWindowText(GetDlgItem(hWnd
,100), AppMisc
);
416 EndDialog(hWnd
, TRUE
);
423 /*************************************************************************
424 * ExtractIcon [SHELL.34]
426 HICON
ExtractIcon(HINSTANCE hInst
, LPCSTR lpszExeFileName
, UINT nIconIndex
)
430 HINSTANCE hInst2
= hInst
;
431 dprintf_reg(stddeb
, "ExtractIcon(%04X, '%s', %d\n",
432 hInst
, lpszExeFileName
, nIconIndex
);
433 if (lpszExeFileName
!= NULL
) {
434 hInst2
= LoadLibrary(lpszExeFileName
);
436 if (hInst2
!= 0 && nIconIndex
== (UINT
)-1) {
437 count
= GetRsrcCount(hInst2
, NE_RSCTYPE_GROUP_ICON
);
438 dprintf_reg(stddeb
, "ExtractIcon // '%s' has %d icons !\n", lpszExeFileName
, count
);
441 if (hInst2
!= hInst
&& hInst2
!= 0) {
448 /*************************************************************************
449 * ExtractAssociatedIcon [SHELL.36]
451 HICON
ExtractAssociatedIcon(HINSTANCE hInst
,LPSTR lpIconPath
, LPWORD lpiIcon
)
453 dprintf_reg(stdnimp
, "ExtractAssociatedIcon : Empty Stub !!!\n");
457 /*************************************************************************
458 * RegisterShellHook [SHELL.102]
460 int RegisterShellHook(void *ptr
)
462 dprintf_reg(stdnimp
, "RegisterShellHook : Empty Stub !!!\n");
467 /*************************************************************************
468 * ShellHookProc [SHELL.103]
470 int ShellHookProc(void)
472 dprintf_reg(stdnimp
, "ShellHookProc : Empty Stub !!!\n");