Release 950403
[wine/multimedia.git] / misc / shell.c
blobf412887e1f06fa801b4602a460e87821b82284c7
1 /*
2 * Shell Library Functions
3 */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include "windows.h"
9 #include "library.h"
10 #include "shell.h"
11 #include "neexe.h"
12 #include "selectors.h"
13 #include "../rc/sysres.h"
14 #include "stddebug.h"
15 /* #define DEBUG_REG */
16 #include "debug.h"
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()
27 HKEY hNewKey;
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;
36 lphRootKey->hKey = 1;
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;
48 lphTopKey->hKey = 0;
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");
57 return ERROR_SUCCESS;
60 /*************************************************************************
61 * RegOpenKey [SHELL.1]
63 LONG RegOpenKey(HKEY hKey, LPCSTR lpSubKey, HKEY FAR *lphKey)
65 LPKEYSTRUCT lpKey;
66 LPCSTR ptr;
67 char str[128];
68 LONG dwRet;
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;
76 switch(hKey) {
77 case 0:
78 lpKey = lphTopKey; break;
79 case HKEY_CLASSES_ROOT: /* == 1 */
80 lpKey = lphRootKey; break;
81 default:
82 dprintf_reg(stddeb,"RegOpenKey // specific key = %08lX !\n", hKey);
83 lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
85 if (!*lpSubKey) { *lphKey = hKey; return ERROR_SUCCESS; }
86 while(*lpSubKey) {
87 ptr = strchr(lpSubKey,'\\');
88 if (!ptr) ptr = lpSubKey + strlen(lpSubKey);
89 strncpy(str,lpSubKey,ptr-lpSubKey);
90 str[ptr-lpSubKey] = 0;
91 lpSubKey = ptr;
92 if (*lpSubKey) lpSubKey++;
94 lpKey = lpKey->lpSubLvl;
95 while(lpKey != NULL && strcmp(lpKey->lpSubKey, str) != 0) { lpKey = lpKey->lpNextKey; }
96 if (lpKey == NULL) {
97 dprintf_reg(stddeb,"RegOpenKey: key %s not found!\n",str);
98 return ERROR_BADKEY;
101 *lphKey = lpKey->hKey;
102 return ERROR_SUCCESS;
106 /*************************************************************************
107 * RegCreateKey [SHELL.2]
109 LONG RegCreateKey(HKEY hKey, LPCSTR lpSubKey, HKEY FAR *lphKey)
111 HKEY hNewKey;
112 LPKEYSTRUCT lpNewKey;
113 LPKEYSTRUCT lpKey;
114 LPKEYSTRUCT lpPrevKey;
115 LONG dwRet;
116 LPCSTR ptr;
117 char str[128];
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;
124 switch(hKey) {
125 case 0:
126 lpKey = lphTopKey; break;
127 case HKEY_CLASSES_ROOT: /* == 1 */
128 lpKey = lphRootKey; break;
129 default:
130 dprintf_reg(stddeb,"RegCreateKey // specific key = %08lX !\n", hKey);
131 lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
133 if (!*lpSubKey) { *lphKey = hKey; return ERROR_SUCCESS; }
134 while (*lpSubKey) {
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;
140 lpSubKey = ptr;
141 if (*lpSubKey) lpSubKey++;
143 lpPrevKey = lpKey;
144 lpKey = lpKey->lpSubLvl;
145 while(lpKey != NULL && strcmp(lpKey->lpSubKey, str) != 0) {
146 lpKey = lpKey->lpNextKey;
148 if (lpKey == NULL) {
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;
169 *lphKey = hNewKey;
170 dprintf_reg(stddeb,"RegCreateKey // successful '%s' key=%08lX !\n", str, hNewKey);
171 lpKey = lpNewKey;
172 } else {
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",
197 hKey, lpSubKey);
198 return ERROR_INVALID_PARAMETER;
202 /*************************************************************************
203 * RegSetValue [SHELL.5]
205 LONG RegSetValue(HKEY hKey, LPCSTR lpSubKey, DWORD dwType,
206 LPCSTR lpVal, DWORD dwIgnored)
208 HKEY hRetKey;
209 LPKEYSTRUCT lpKey;
210 LONG dwRet;
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);
219 return 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)
237 HKEY hRetKey;
238 LPKEYSTRUCT lpKey;
239 LONG dwRet;
240 int size;
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");
250 return dwRet;
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);
257 lpVal[*lpcb-1] = 0;
258 } else {
259 strcpy(lpVal,lpKey->lpValue);
260 *lpcb = size;
262 } else {
263 *lpVal = 0;
264 *lpcb = (LONG)1;
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)
276 LPKEYSTRUCT lpKey;
277 LONG dwRet;
278 LONG len;
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;
284 switch(hKey) {
285 case 0:
286 lpKey = lphTopKey; break;
287 case HKEY_CLASSES_ROOT: /* == 1 */
288 lpKey = lphRootKey; break;
289 default:
290 dprintf_reg(stddeb,"RegEnumKey // specific key = %08lX !\n", hKey);
291 lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
294 lpKey = lpKey->lpSubLvl;
295 while(lpKey != NULL){
296 if (!dwSubKey){
297 len = min(dwSize-1,strlen(lpKey->lpSubKey));
298 strncpy(lpBuf,lpKey->lpSubKey,len);
299 lpBuf[len] = 0;
300 dprintf_reg(stddeb, "RegEnumKey: found %s\n",lpBuf);
301 return ERROR_SUCCESS;
303 dwSubKey--;
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");
345 return FALSE;
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");
370 return 0;
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);*/
383 if (szApp)
384 strcpy(AppName, szApp);
385 else
386 *AppName = 0;
388 if (szOtherStuff)
389 strcpy(AppMisc, szOtherStuff);
390 else
391 *AppMisc = 0;
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)
404 char temp[256];
406 switch(msg) {
407 case WM_INITDIALOG:
408 sprintf(temp, "About %s", AppName);
409 SetWindowText(hWnd, temp);
410 SetWindowText(GetDlgItem(hWnd,100), AppMisc );
411 break;
413 case WM_COMMAND:
414 switch (wParam) {
415 case IDOK:
416 EndDialog(hWnd, TRUE);
417 return TRUE;
420 return FALSE;
423 /*************************************************************************
424 * ExtractIcon [SHELL.34]
426 HICON ExtractIcon(HINSTANCE hInst, LPCSTR lpszExeFileName, UINT nIconIndex)
428 int count;
429 HICON hIcon = 0;
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);
439 return (HICON)count;
441 if (hInst2 != hInst && hInst2 != 0) {
442 FreeLibrary(hInst2);
444 return hIcon;
448 /*************************************************************************
449 * ExtractAssociatedIcon [SHELL.36]
451 HICON ExtractAssociatedIcon(HINSTANCE hInst,LPSTR lpIconPath, LPWORD lpiIcon)
453 dprintf_reg(stdnimp, "ExtractAssociatedIcon : Empty Stub !!!\n");
454 return 0;
457 /*************************************************************************
458 * RegisterShellHook [SHELL.102]
460 int RegisterShellHook(void *ptr)
462 dprintf_reg(stdnimp, "RegisterShellHook : Empty Stub !!!\n");
463 return 0;
467 /*************************************************************************
468 * ShellHookProc [SHELL.103]
470 int ShellHookProc(void)
472 dprintf_reg(stdnimp, "ShellHookProc : Empty Stub !!!\n");
473 return 0;