2 * Shell Library Functions
11 #include "selectors.h"
12 #include "../rc/sysres.h"
16 /* #define DEBUG_REG */
19 LPKEYSTRUCT lphRootKey
= NULL
,lphTopKey
= NULL
;
21 static char RootKeyName
[]=".classes", TopKeyName
[] = "(null)";
23 /*************************************************************************
24 * SHELL_RegCheckForRoot() internal use only
26 static LONG
SHELL_RegCheckForRoot()
30 if (lphRootKey
== NULL
){
31 hNewKey
= GlobalAlloc(GMEM_MOVEABLE
,sizeof(KEYSTRUCT
));
32 lphRootKey
= (LPKEYSTRUCT
) GlobalLock(hNewKey
);
33 if (lphRootKey
== NULL
) {
34 printf("SHELL_RegCheckForRoot: Couldn't allocate root key!\n");
35 return ERROR_OUTOFMEMORY
;
38 lphRootKey
->lpSubKey
= RootKeyName
;
39 lphRootKey
->dwType
= 0;
40 lphRootKey
->lpValue
= NULL
;
41 lphRootKey
->lpSubLvl
= lphRootKey
->lpNextKey
= lphRootKey
->lpPrevKey
= NULL
;
43 hNewKey
= GlobalAlloc(GMEM_MOVEABLE
,sizeof(KEYSTRUCT
));
44 lphTopKey
= (LPKEYSTRUCT
) GlobalLock(hNewKey
);
45 if (lphTopKey
== NULL
) {
46 printf("SHELL_RegCheckForRoot: Couldn't allocate top key!\n");
47 return ERROR_OUTOFMEMORY
;
50 lphTopKey
->lpSubKey
= TopKeyName
;
51 lphTopKey
->dwType
= 0;
52 lphTopKey
->lpValue
= NULL
;
53 lphTopKey
->lpSubLvl
= lphRootKey
;
54 lphTopKey
->lpNextKey
= lphTopKey
->lpPrevKey
= NULL
;
56 dprintf_reg(stddeb
,"SHELL_RegCheckForRoot: Root/Top created\n");
61 /*************************************************************************
62 * RegOpenKey [SHELL.1]
64 LONG
RegOpenKey(HKEY hKey
, LPCSTR lpSubKey
, HKEY FAR
*lphKey
)
71 dwRet
= SHELL_RegCheckForRoot();
72 if (dwRet
!= ERROR_SUCCESS
) return dwRet
;
73 dprintf_reg(stddeb
, "RegOpenKey(%08lX, %p='%s', %p)\n",
74 hKey
, lpSubKey
, lpSubKey
, lphKey
);
75 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
76 if (lphKey
== NULL
) return ERROR_INVALID_PARAMETER
;
79 lpKey
= lphTopKey
; break;
80 case HKEY_CLASSES_ROOT
: /* == 1 */
81 lpKey
= lphRootKey
; break;
83 dprintf_reg(stddeb
,"RegOpenKey // specific key = %08lX !\n", hKey
);
84 lpKey
= (LPKEYSTRUCT
)GlobalLock(hKey
);
86 if (!*lpSubKey
) { *lphKey
= hKey
; return ERROR_SUCCESS
; }
88 ptr
= strchr(lpSubKey
,'\\');
89 if (!ptr
) ptr
= lpSubKey
+ strlen(lpSubKey
);
90 strncpy(str
,lpSubKey
,ptr
-lpSubKey
);
91 str
[ptr
-lpSubKey
] = 0;
93 if (*lpSubKey
) lpSubKey
++;
95 lpKey
= lpKey
->lpSubLvl
;
96 while(lpKey
!= NULL
&& strcmp(lpKey
->lpSubKey
, str
) != 0) { lpKey
= lpKey
->lpNextKey
; }
98 dprintf_reg(stddeb
,"RegOpenKey: key %s not found!\n",str
);
102 *lphKey
= lpKey
->hKey
;
103 return ERROR_SUCCESS
;
107 /*************************************************************************
108 * RegCreateKey [SHELL.2]
110 LONG
RegCreateKey(HKEY hKey
, LPCSTR lpSubKey
, HKEY FAR
*lphKey
)
113 LPKEYSTRUCT lpNewKey
;
115 LPKEYSTRUCT lpPrevKey
;
120 dwRet
= SHELL_RegCheckForRoot();
121 if (dwRet
!= ERROR_SUCCESS
) return dwRet
;
122 dprintf_reg(stddeb
, "RegCreateKey(%08lX, '%s', %p)\n", hKey
, lpSubKey
, lphKey
);
123 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
124 if (lphKey
== NULL
) return ERROR_INVALID_PARAMETER
;
127 lpKey
= lphTopKey
; break;
128 case HKEY_CLASSES_ROOT
: /* == 1 */
129 lpKey
= lphRootKey
; break;
131 dprintf_reg(stddeb
,"RegCreateKey // specific key = %08lX !\n", hKey
);
132 lpKey
= (LPKEYSTRUCT
)GlobalLock(hKey
);
134 if (!*lpSubKey
) { *lphKey
= hKey
; return ERROR_SUCCESS
; }
136 dprintf_reg(stddeb
, "RegCreateKey: Looking for subkey %s\n", lpSubKey
);
137 ptr
= strchr(lpSubKey
,'\\');
138 if (!ptr
) ptr
= lpSubKey
+ strlen(lpSubKey
);
139 strncpy(str
,lpSubKey
,ptr
-lpSubKey
);
140 str
[ptr
-lpSubKey
] = 0;
142 if (*lpSubKey
) lpSubKey
++;
145 lpKey
= lpKey
->lpSubLvl
;
146 while(lpKey
!= NULL
&& strcmp(lpKey
->lpSubKey
, str
) != 0) {
147 lpKey
= lpKey
->lpNextKey
;
150 hNewKey
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(KEYSTRUCT
));
151 lpNewKey
= (LPKEYSTRUCT
) GlobalLock(hNewKey
);
152 if (lpNewKey
== NULL
) {
153 printf("RegCreateKey // Can't alloc new key !\n");
154 return ERROR_OUTOFMEMORY
;
156 lpNewKey
->hKey
= hNewKey
;
157 lpNewKey
->lpSubKey
= malloc(strlen(str
) + 1);
158 if (lpNewKey
->lpSubKey
== NULL
) {
159 printf("RegCreateKey // Can't alloc key string !\n");
160 return ERROR_OUTOFMEMORY
;
162 strcpy(lpNewKey
->lpSubKey
, str
);
163 lpNewKey
->lpNextKey
= lpPrevKey
->lpSubLvl
;
164 lpNewKey
->lpPrevKey
= NULL
;
165 lpPrevKey
->lpSubLvl
= lpNewKey
;
167 lpNewKey
->dwType
= 0;
168 lpNewKey
->lpValue
= NULL
;
169 lpNewKey
->lpSubLvl
= NULL
;
171 dprintf_reg(stddeb
,"RegCreateKey // successful '%s' key=%08lX !\n", str
, hNewKey
);
174 *lphKey
= lpKey
->hKey
;
175 dprintf_reg(stddeb
,"RegCreateKey // found '%s', key=%08lX\n", str
, *lphKey
);
178 return ERROR_SUCCESS
;
182 /*************************************************************************
183 * RegCloseKey [SHELL.3]
185 LONG
RegCloseKey(HKEY hKey
)
187 dprintf_reg(stdnimp
, "EMPTY STUB !!! RegCloseKey(%08lX);\n", hKey
);
188 return ERROR_INVALID_PARAMETER
;
192 /*************************************************************************
193 * RegDeleteKey [SHELL.4]
195 LONG
RegDeleteKey(HKEY hKey
, LPCSTR lpSubKey
)
197 dprintf_reg(stdnimp
, "EMPTY STUB !!! RegDeleteKey(%08lX, '%s');\n",
199 return ERROR_INVALID_PARAMETER
;
203 /*************************************************************************
204 * RegSetValue [SHELL.5]
206 LONG
RegSetValue(HKEY hKey
, LPCSTR lpSubKey
, DWORD dwType
,
207 LPCSTR lpVal
, DWORD dwIgnored
)
212 dprintf_reg(stddeb
, "RegSetValue(%08lX, '%s', %08lX, '%s', %08lX);\n",
213 hKey
, lpSubKey
, dwType
, lpVal
, dwIgnored
);
214 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
215 if (lpVal
== NULL
) return ERROR_INVALID_PARAMETER
;
216 if ((dwRet
= RegOpenKey(hKey
, lpSubKey
, &hRetKey
)) != ERROR_SUCCESS
) {
217 dprintf_reg(stddeb
, "RegSetValue // key not found ... so create it !\n");
218 if ((dwRet
= RegCreateKey(hKey
, lpSubKey
, &hRetKey
)) != ERROR_SUCCESS
) {
219 fprintf(stderr
, "RegSetValue // key creation error %08lX !\n", dwRet
);
223 lpKey
= (LPKEYSTRUCT
)GlobalLock(hRetKey
);
224 if (lpKey
== NULL
) return ERROR_BADKEY
;
225 if (lpKey
->lpValue
!= NULL
) free(lpKey
->lpValue
);
226 lpKey
->lpValue
= malloc(strlen(lpVal
) + 1);
227 strcpy(lpKey
->lpValue
, lpVal
);
228 dprintf_reg(stddeb
,"RegSetValue // successful key='%s' val='%s' !\n", lpSubKey
, lpKey
->lpValue
);
229 return ERROR_SUCCESS
;
233 /*************************************************************************
234 * RegQueryValue [SHELL.6]
236 LONG
RegQueryValue(HKEY hKey
, LPCSTR lpSubKey
, LPSTR lpVal
, LONG FAR
*lpcb
)
242 dprintf_reg(stddeb
, "RegQueryValue(%08lX, '%s', %p, %p);\n",
243 hKey
, lpSubKey
, lpVal
, lpcb
);
244 if (lpSubKey
== NULL
) return ERROR_INVALID_PARAMETER
;
245 if (lpVal
== NULL
) return ERROR_INVALID_PARAMETER
;
246 if (lpcb
== NULL
) return ERROR_INVALID_PARAMETER
;
247 if (!*lpcb
) return ERROR_INVALID_PARAMETER
;
249 if ((dwRet
= RegOpenKey(hKey
, lpSubKey
, &hRetKey
)) != ERROR_SUCCESS
) {
250 fprintf(stderr
, "RegQueryValue // key not found !\n");
253 lpKey
= (LPKEYSTRUCT
)GlobalLock(hRetKey
);
254 if (lpKey
== NULL
) return ERROR_BADKEY
;
255 if (lpKey
->lpValue
!= NULL
) {
256 if ((size
= strlen(lpKey
->lpValue
)+1) > *lpcb
){
257 strncpy(lpVal
,lpKey
->lpValue
,*lpcb
-1);
260 strcpy(lpVal
,lpKey
->lpValue
);
267 dprintf_reg(stddeb
,"RegQueryValue // return '%s' !\n", lpVal
);
268 return ERROR_SUCCESS
;
272 /*************************************************************************
273 * RegEnumKey [SHELL.7]
275 LONG
RegEnumKey(HKEY hKey
, DWORD dwSubKey
, LPSTR lpBuf
, DWORD dwSize
)
281 dwRet
= SHELL_RegCheckForRoot();
282 if (dwRet
!= ERROR_SUCCESS
) return dwRet
;
283 dprintf_reg(stddeb
, "RegEnumKey(%08lX, %ld)\n", hKey
, dwSubKey
);
284 if (lpBuf
== NULL
) return ERROR_INVALID_PARAMETER
;
287 lpKey
= lphTopKey
; break;
288 case HKEY_CLASSES_ROOT
: /* == 1 */
289 lpKey
= lphRootKey
; break;
291 dprintf_reg(stddeb
,"RegEnumKey // specific key = %08lX !\n", hKey
);
292 lpKey
= (LPKEYSTRUCT
)GlobalLock(hKey
);
295 lpKey
= lpKey
->lpSubLvl
;
296 while(lpKey
!= NULL
){
298 len
= min(dwSize
-1,strlen(lpKey
->lpSubKey
));
299 strncpy(lpBuf
,lpKey
->lpSubKey
,len
);
301 dprintf_reg(stddeb
, "RegEnumKey: found %s\n",lpBuf
);
302 return ERROR_SUCCESS
;
305 lpKey
= lpKey
->lpNextKey
;
307 dprintf_reg(stddeb
, "RegEnumKey: key not found!\n");
308 return ERROR_INVALID_PARAMETER
;
311 /*************************************************************************
312 * DragAcceptFiles [SHELL.9]
314 void DragAcceptFiles(HWND hWnd
, BOOL b
)
316 fprintf(stdnimp
, "DragAcceptFiles : Empty Stub !!!\n");
320 /*************************************************************************
321 * DragQueryFile [SHELL.11]
323 void DragQueryFile(HDROP h
, UINT u
, LPSTR u2
, UINT u3
)
325 fprintf(stdnimp
, "DragQueryFile : Empty Stub !!!\n");
330 /*************************************************************************
331 * DragFinish [SHELL.12]
333 void DragFinish(HDROP h
)
335 fprintf(stdnimp
, "DragFinish : Empty Stub !!!\n");
339 /*************************************************************************
340 * DragQueryPoint [SHELL.13]
342 BOOL
DragQueryPoint(HDROP h
, POINT FAR
*p
)
344 fprintf(stdnimp
, "DragQueryPoint : Empty Stub !!!\n");
349 /*************************************************************************
350 * ShellExecute [SHELL.20]
352 HINSTANCE
ShellExecute(HWND hWnd
, LPCSTR lpOperation
, LPCSTR lpFile
, LPCSTR lpParameters
, LPCSTR lpDirectory
, int iShowCmd
)
354 fprintf(stdnimp
, "ShellExecute: empty stub\n");
356 fprintf(stdnimp
, "ShellExecute // hWnd=%04X\n", hWnd
);
357 fprintf(stdnimp
, "ShellExecute // lpOperation='%s'\n", lpOperation
);
358 fprintf(stdnimp
, "ShellExecute // lpFile='%s'\n", lpFile
);
359 fprintf(stdnimp
, "ShellExecute // lpParameters='%s'\n", lpParameters
);
360 fprintf(stdnimp
, "ShellExecute // lpDirectory='%s'\n", lpDirectory
);
361 fprintf(stdnimp
, "ShellExecute // iShowCmd=%04X\n", iShowCmd
);
362 return 2; /* file not found */
366 /*************************************************************************
367 * FindExecutable [SHELL.21]
369 HINSTANCE
FindExecutable(LPCSTR lpFile
, LPCSTR lpDirectory
, LPSTR lpResult
)
371 fprintf(stdnimp
, "FindExecutable : Empty Stub !!!\n");
375 static char AppName
[512], AppMisc
[512];
377 /*************************************************************************
378 * AboutDlgProc [SHELL.33]
380 INT
AboutDlgProc(HWND hWnd
, WORD msg
, WORD wParam
, LONG lParam
)
384 SendDlgItemMessage(hWnd
,stc1
,STM_SETICON
,LOWORD(lParam
),0);
385 SetWindowText(hWnd
, AppName
);
386 SetWindowText(GetDlgItem(hWnd
,100), AppMisc
);
392 EndDialog(hWnd
, TRUE
);
400 /*************************************************************************
401 * ShellAbout [SHELL.22]
403 INT
ShellAbout(HWND hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
, HICON hIcon
)
406 sprintf(AppName
, "About %s", szApp
);
411 strcpy(AppMisc
, szOtherStuff
);
416 hIcon
= LoadIcon(0,MAKEINTRESOURCE(OIC_WINEICON
));
418 return DialogBoxIndirectParamPtr(GetWindowWord(hWnd
, GWW_HINSTANCE
),
419 sysres_DIALOG_SHELL_ABOUT_MSGBOX
,
420 hWnd
, GetWndProcEntry16("AboutDlgProc"),
424 /*************************************************************************
425 * ExtractIcon [SHELL.34]
427 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) {
438 count
= GetRsrcCount(hInst2
, NE_RSCTYPE_GROUP_ICON
);
439 dprintf_reg(stddeb
, "ExtractIcon // '%s' has %d icons !\n", lpszExeFileName
, count
);
443 if (hInst2
!= hInst
&& hInst2
!= 0) {
450 /*************************************************************************
451 * ExtractAssociatedIcon [SHELL.36]
453 HICON
ExtractAssociatedIcon(HINSTANCE hInst
,LPSTR lpIconPath
, LPWORD lpiIcon
)
455 dprintf_reg(stdnimp
, "ExtractAssociatedIcon : Empty Stub !!!\n");
459 /*************************************************************************
460 * DoEnvironmentSubst [SHELL.37]
461 * I couldn't find any reference, so even the number of bytes on the
462 * stack might be wrong
464 WORD
DoEnvironmentSubst(LPSTR a
,WORD b
,WORD c
)
466 printf(stderr
, "DoEnvironmentSubst: Unknown argument count\n");
467 dprintf_reg(stdnimp
, "DoEnvironmentSubst %x %x %x\n",a
,b
,c
);
471 /*************************************************************************
472 * RegisterShellHook [SHELL.102]
474 int RegisterShellHook(void *ptr
)
476 dprintf_reg(stdnimp
, "RegisterShellHook : Empty Stub !!!\n");
481 /*************************************************************************
482 * ShellHookProc [SHELL.103]
484 int ShellHookProc(void)
486 dprintf_reg(stdnimp
, "ShellHookProc : Empty Stub !!!\n");