Release 940912
[wine/multimedia.git] / misc / shell.c
blob0b6e55270d18d024fe7ef9020681e4891a98c3c6
1 /*
2 * Shell Library Functions
3 */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include "prototypes.h"
9 #include "windows.h"
10 #include "shell.h"
13 #define DEBUG_REG
16 LPKEYSTRUCT lphRootKey = NULL;
18 DECLARE_HANDLE(HDROP);
20 extern HINSTANCE hSysRes;
22 /*************************************************************************
23 * RegOpenKey [SHELL.1]
25 LONG RegOpenKey(HKEY hKey, LPCSTR lpSubKey, HKEY FAR *lphKey)
27 LPKEYSTRUCT lpKey = lphRootKey;
28 LPSTR ptr;
29 char str[128];
30 int size;
31 #ifdef DEBUG_REG
32 fprintf(stderr, "RegOpenKey(%04X, %08X='%s', %08X)\n",
33 hKey, lpSubKey, lpSubKey, lphKey);
34 #endif
35 if (lpKey == NULL) return ERROR_BADKEY;
36 if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
37 if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
38 if (hKey != HKEY_CLASSES_ROOT) {
39 #ifdef DEBUG_REG
40 printf("RegOpenKey // specific key = %04X !\n", hKey);
41 #endif
42 lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
44 while ( (ptr = strchr(lpSubKey, '\\')) != NULL ) {
45 strncpy(str, lpSubKey, (LONG)ptr - (LONG)lpSubKey);
46 str[(LONG)ptr - (LONG)lpSubKey] = '\0';
47 lpSubKey = ptr + 1;
48 #ifdef DEBUG_REG
49 printf("RegOpenKey // next level '%s' !\n", str);
50 #endif
51 while(TRUE) {
52 #ifdef DEBUG_REG
53 printf("RegOpenKey // '%s' <-> '%s' !\n", str, lpKey->lpSubKey);
54 #endif
55 if (lpKey->lpSubKey != NULL && lpKey->lpSubKey[0] != '\0' &&
56 strcmp(lpKey->lpSubKey, str) == 0) {
57 lpKey = lpKey->lpSubLvl;
58 if (lpKey == NULL) {
59 printf("RegOpenKey // can't find subkey '%s' !\n", str);
60 return ERROR_BADKEY;
62 break;
64 if (lpKey->lpNextKey == NULL) {
65 printf("RegOpenKey // can't find subkey '%s' !\n", str);
66 return ERROR_BADKEY;
68 lpKey = lpKey->lpNextKey;
71 while(TRUE) {
72 if (lpKey->lpSubKey != NULL &&
73 strcmp(lpKey->lpSubKey, lpSubKey) == 0) break;
74 if (lpKey->lpNextKey == NULL) {
75 printf("RegOpenKey // can't find subkey '%s' !\n", str);
76 return ERROR_BADKEY;
78 lpKey = lpKey->lpNextKey;
80 *lphKey = lpKey->hKey;
81 #ifdef DEBUG_REG
82 printf("RegOpenKey // return hKey=%04X !\n", lpKey->hKey);
83 #endif
84 return ERROR_SUCCESS;
88 /*************************************************************************
89 * RegCreateKey [SHELL.2]
91 LONG RegCreateKey(HKEY hKey, LPCSTR lpSubKey, HKEY FAR *lphKey)
93 HKEY hNewKey;
94 LPKEYSTRUCT lpNewKey;
95 LPKEYSTRUCT lpKey = lphRootKey;
96 LPKEYSTRUCT lpPrevKey;
97 LONG dwRet;
98 LPSTR ptr;
99 char str[128];
100 #ifdef DEBUG_REG
101 fprintf(stderr, "RegCreateKey(%04X, '%s', %08X)\n", hKey, lpSubKey, lphKey);
102 #endif
103 if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
104 if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
105 if (hKey != HKEY_CLASSES_ROOT) {
106 #ifdef DEBUG_REG
107 printf("RegCreateKey // specific key = %04X !\n", hKey);
108 #endif
109 lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
111 while ( (ptr = strchr(lpSubKey, '\\')) != NULL ) {
112 strncpy(str, lpSubKey, (LONG)ptr - (LONG)lpSubKey);
113 str[(LONG)ptr - (LONG)lpSubKey] = '\0';
114 lpSubKey = ptr + 1;
115 #ifdef DEBUG_REG
116 printf("RegCreateKey // next level '%s' !\n", str);
117 #endif
118 lpPrevKey = lpKey;
119 while(TRUE) {
120 #ifdef DEBUG_REG
121 printf("RegCreateKey // '%s' <-> '%s' !\n", str, lpKey->lpSubKey);
122 #endif
123 if (lpKey->lpSubKey != NULL &&
124 strcmp(lpKey->lpSubKey, str) == 0) {
125 if (lpKey->lpSubLvl == NULL) {
126 #ifdef DEBUG_REG
127 printf("RegCreateKey // '%s' found !\n", str);
128 #endif
129 if ( (ptr = strchr(lpSubKey, '\\')) != NULL ) {
130 strncpy(str, lpSubKey, (LONG)ptr - (LONG)lpSubKey);
131 str[(LONG)ptr - (LONG)lpSubKey] = '\0';
132 lpSubKey = ptr + 1;
134 else
135 strcpy(str, lpSubKey);
136 dwRet = RegCreateKey(lpKey->hKey, str, &hNewKey);
137 if (dwRet != ERROR_SUCCESS) {
138 printf("RegCreateKey // can't create subkey '%s' !\n", str);
139 return dwRet;
141 lpKey->lpSubLvl = (LPKEYSTRUCT)GlobalLock(hNewKey);
143 lpKey = lpKey->lpSubLvl;
144 break;
146 if (lpKey->lpNextKey == NULL) {
147 dwRet = RegCreateKey(lpPrevKey->hKey, str, &hNewKey);
148 if (dwRet != ERROR_SUCCESS) {
149 printf("RegCreateKey // can't create subkey '%s' !\n", str);
150 return dwRet;
152 lpKey = (LPKEYSTRUCT)GlobalLock(hNewKey);
153 break;
155 lpKey = lpKey->lpNextKey;
158 hNewKey = GlobalAlloc(GMEM_MOVEABLE, sizeof(KEYSTRUCT));
159 lpNewKey = (LPKEYSTRUCT) GlobalLock(hNewKey);
160 if (lpNewKey == NULL) {
161 printf("RegCreateKey // Can't alloc new key !\n");
162 return ERROR_OUTOFMEMORY;
164 if (lphRootKey == NULL) {
165 lphRootKey = lpNewKey;
166 lpNewKey->lpPrevKey = NULL;
168 else {
169 lpKey->lpNextKey = lpNewKey;
170 lpNewKey->lpPrevKey = lpKey;
172 lpNewKey->hKey = hNewKey;
173 lpNewKey->lpSubKey = malloc(strlen(lpSubKey) + 1);
174 if (lpNewKey->lpSubKey == NULL) {
175 printf("RegCreateKey // Can't alloc key string !\n");
176 return ERROR_OUTOFMEMORY;
178 strcpy(lpNewKey->lpSubKey, lpSubKey);
179 lpNewKey->dwType = 0;
180 lpNewKey->lpValue = NULL;
181 lpNewKey->lpNextKey = NULL;
182 lpNewKey->lpSubLvl = NULL;
183 *lphKey = hNewKey;
184 #ifdef DEBUG_REG
185 printf("RegCreateKey // successful '%s' key=%04X !\n", lpSubKey, hNewKey);
186 #endif
187 return ERROR_SUCCESS;
191 /*************************************************************************
192 * RegCloseKey [SHELL.3]
194 LONG RegCloseKey(HKEY hKey)
196 fprintf(stderr, "EMPTY STUB !!! RegCloseKey(%04X);\n", hKey);
197 return ERROR_INVALID_PARAMETER;
201 /*************************************************************************
202 * RegDeleteKey [SHELL.4]
204 LONG RegDeleteKey(HKEY hKey, LPCSTR lpSubKey)
206 fprintf(stderr, "EMPTY STUB !!! RegDeleteKey(%04X, '%s');\n",
207 hKey, lpSubKey);
208 return ERROR_INVALID_PARAMETER;
212 /*************************************************************************
213 * RegSetValue [SHELL.5]
215 LONG RegSetValue(HKEY hKey, LPCSTR lpSubKey, DWORD dwType,
216 LPCSTR lpVal, DWORD dwIgnored)
218 HKEY hRetKey;
219 LPKEYSTRUCT lpKey;
220 LONG dwRet;
221 #ifdef DEBUG_REG
222 fprintf(stderr, "RegSetValue(%04X, '%s', %08X, '%s', %08X);\n",
223 hKey, lpSubKey, dwType, lpVal, dwIgnored);
224 #endif
225 if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
226 if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
227 if ((dwRet = RegOpenKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
228 #ifdef DEBUG_REG
229 fprintf(stderr, "RegSetValue // key not found ... so create it !\n");
230 #endif
231 if ((dwRet = RegCreateKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
232 fprintf(stderr, "RegSetValue // key creation error %04X !\n", dwRet);
233 return dwRet;
236 lpKey = (LPKEYSTRUCT)GlobalLock(hRetKey);
237 if (lpKey == NULL) return ERROR_BADKEY;
238 if (lpKey->lpValue != NULL) free(lpKey->lpValue);
239 lpKey->lpValue = malloc(strlen(lpVal) + 1);
240 strcpy(lpKey->lpValue, lpVal);
241 #ifdef DEBUG_REG
242 printf("RegSetValue // successful key='%s' val='%s' !\n", lpSubKey, lpVal);
243 #endif
244 return ERROR_SUCCESS;
248 /*************************************************************************
249 * RegQueryValue [SHELL.6]
251 LONG RegQueryValue(HKEY hKey, LPCSTR lpSubKey, LPSTR lpVal, LONG FAR *lpcb)
253 HKEY hRetKey;
254 LPKEYSTRUCT lpKey;
255 LONG dwRet;
256 int size;
257 fprintf(stderr, "RegQueryValue(%04X, '%s', %08X, %08X);\n",
258 hKey, lpSubKey, lpVal, lpcb);
259 if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
260 if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
261 if (lpcb == NULL) return ERROR_INVALID_PARAMETER;
262 if ((dwRet = RegOpenKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
263 fprintf(stderr, "RegQueryValue // key not found !\n");
264 return dwRet;
266 lpKey = (LPKEYSTRUCT)GlobalLock(hRetKey);
267 if (lpKey == NULL) return ERROR_BADKEY;
268 if (lpKey->lpValue != NULL) {
269 size = min(strlen(lpKey->lpValue), *lpcb);
270 strncpy(lpVal, lpKey->lpValue, size);
271 *lpcb = (LONG)size;
273 else {
274 lpVal[0] = '\0';
275 *lpcb = (LONG)0;
277 printf("RegQueryValue // return '%s' !\n", lpVal);
278 return ERROR_SUCCESS;
282 /*************************************************************************
283 * RegEnumKey [SHELL.7]
285 LONG RegEnumKey(HKEY hKey, DWORD dwSubKey, LPSTR lpBuf, DWORD dwSize)
287 fprintf(stderr, "RegEnumKey : Empty Stub !!!\n");
288 return ERROR_INVALID_PARAMETER;
291 /*************************************************************************
292 * DragAcceptFiles [SHELL.9]
294 void DragAcceptFiles(HWND hWnd, BOOL b)
296 fprintf(stderr, "DragAcceptFiles : Empty Stub !!!\n");
300 /*************************************************************************
301 * DragQueryFile [SHELL.11]
303 void DragQueryFile(HDROP h, UINT u, LPSTR u2, UINT u3)
305 fprintf(stderr, "DragQueryFile : Empty Stub !!!\n");
310 /*************************************************************************
311 * DragFinish [SHELL.12]
313 void DragFinish(HDROP h)
315 fprintf(stderr, "DragFinish : Empty Stub !!!\n");
320 /*************************************************************************
321 * DragQueryPoint [SHELL.13]
323 BOOL DragQueryPoint(HDROP h, POINT FAR *p)
325 fprintf(stderr, "DragQueryPoinyt : Empty Stub !!!\n");
330 /*************************************************************************
331 * ShellExecute [SHELL.20]
333 HINSTANCE ShellExecute(HWND hWnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, int iShowCmd)
335 fprintf(stderr, "ShellExecute // hWnd=%04X\n", hWnd);
336 fprintf(stderr, "ShellExecute // lpOperation='%s'\n", lpOperation);
337 fprintf(stderr, "ShellExecute // lpFile='%s'\n", lpFile);
338 fprintf(stderr, "ShellExecute // lpParameters='%s'\n", lpParameters);
339 fprintf(stderr, "ShellExecute // lpDirectory='%s'\n", lpDirectory);
340 fprintf(stderr, "ShellExecute // iShowCmd=%04X\n", iShowCmd);
341 return 2; /* file not found */
345 /*************************************************************************
346 * FindExecutable [SHELL.21]
348 HINSTANCE FindExecutable(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
350 fprintf(stderr, "FindExecutable : Empty Stub !!!\n");
354 char AppName[256], AppMisc[256];
355 INT AboutDlgProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam);
357 /*************************************************************************
358 * ShellAbout [SHELL.22]
360 INT ShellAbout(HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon)
362 fprintf(stderr, "ShellAbout ! (%s, %s)\n", szApp, szOtherStuff);
364 strcpy(AppName, szApp);
365 strcpy(AppMisc, szOtherStuff);
367 return DialogBox(hSysRes, "SHELL_ABOUT_MSGBOX", hWnd, (FARPROC)AboutDlgProc);
371 /*************************************************************************
372 * AboutDlgProc [SHELL.33]
374 INT AboutDlgProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam)
376 char temp[256];
378 switch(msg) {
379 case WM_INITDIALOG:
380 sprintf(temp, "About %s", AppName);
381 SetWindowText(hWnd, temp);
382 SetDlgItemText(hWnd, 100, AppMisc);
383 break;
385 case WM_COMMAND:
386 switch (wParam) {
387 case IDOK:
388 EndDialog(hWnd, TRUE);
389 return TRUE;
392 return FALSE;
395 /*************************************************************************
396 * ExtractIcon [SHELL.34]
398 HICON ExtractIcon(HINSTANCE hInst, LPCSTR lpszExeFileName, UINT nIconIndex)
400 int count;
401 HICON hIcon = 0;
402 HINSTANCE hInst2 = hInst;
403 fprintf(stderr, "ExtractIcon(%04X, '%s', %d\n",
404 hInst, lpszExeFileName, nIconIndex);
405 if (lpszExeFileName != NULL) {
406 hInst2 = LoadLibrary(lpszExeFileName);
408 if (hInst2 != 0 && nIconIndex == (UINT)-1) {
409 count = GetRsrcCount(hInst2, NE_RSCTYPE_GROUP_ICON);
410 printf("ExtractIcon // '%s' has %d icons !\n", lpszExeFileName, count);
411 return (HICON)count;
413 if (hInst2 != hInst && hInst2 != 0) {
414 FreeLibrary(hInst2);
416 return hIcon;
420 /*************************************************************************
421 * ExtractAssociatedIcon [SHELL.36]
423 HICON ExtractAssociatedIcon(HINSTANCE hInst,LPSTR lpIconPath, LPWORD lpiIcon)
425 fprintf(stderr, "ExtractAssociatedIcon : Empty Stub !!!\n");
428 /*************************************************************************
429 * RegisterShellHook [SHELL.102]
431 int RegisterShellHook(void *ptr)
433 fprintf(stderr, "RegisterShellHook : Empty Stub !!!\n");
434 return 0;
438 /*************************************************************************
439 * ShellHookProc [SHELL.103]
441 int ShellHookProc(void)
443 fprintf(stderr, "ShellHookProc : Empty Stub !!!\n");