Release 950109
[wine/multimedia.git] / misc / shell.c
blob97a9653a287398e9558d481f48e629d7348dfe36
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 "../rc/sysres.h"
13 #include "stddebug.h"
14 /* #define DEBUG_REG */
15 #include "debug.h"
17 LPKEYSTRUCT lphRootKey = NULL;
19 /*************************************************************************
20 * RegOpenKey [SHELL.1]
22 LONG RegOpenKey(HKEY hKey, LPCSTR lpSubKey, HKEY FAR *lphKey)
24 LPKEYSTRUCT lpKey = lphRootKey;
25 LPSTR ptr;
26 char str[128];
28 dprintf_reg(stddeb, "RegOpenKey(%08lX, %p='%s', %p)\n",
29 hKey, lpSubKey, lpSubKey, lphKey);
30 if (lpKey == NULL) return ERROR_BADKEY;
31 if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
32 if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
33 if (hKey != HKEY_CLASSES_ROOT) {
34 dprintf_reg(stddeb,"RegOpenKey // specific key = %08lX !\n", hKey);
35 lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
37 while ( (ptr = strchr(lpSubKey, '\\')) != NULL ) {
38 strncpy(str, lpSubKey, (LONG)ptr - (LONG)lpSubKey);
39 str[(LONG)ptr - (LONG)lpSubKey] = '\0';
40 lpSubKey = ptr + 1;
41 dprintf_reg(stddeb,"RegOpenKey // next level '%s' !\n", str);
42 while(TRUE) {
43 dprintf_reg(stddeb,"RegOpenKey // '%s' <-> '%s' !\n", str, lpKey->lpSubKey);
44 if (lpKey->lpSubKey != NULL && lpKey->lpSubKey[0] != '\0' &&
45 strcmp(lpKey->lpSubKey, str) == 0) {
46 lpKey = lpKey->lpSubLvl;
47 if (lpKey == NULL) {
48 printf("RegOpenKey // can't find subkey '%s' !\n", str);
49 return ERROR_BADKEY;
51 break;
53 if (lpKey->lpNextKey == NULL) {
54 printf("RegOpenKey // can't find subkey '%s' !\n", str);
55 return ERROR_BADKEY;
57 lpKey = lpKey->lpNextKey;
60 while(TRUE) {
61 if (lpKey->lpSubKey != NULL &&
62 strcmp(lpKey->lpSubKey, lpSubKey) == 0) break;
63 if (lpKey->lpNextKey == NULL) {
64 printf("RegOpenKey // can't find subkey '%s' !\n", str);
65 return ERROR_BADKEY;
67 lpKey = lpKey->lpNextKey;
69 *lphKey = lpKey->hKey;
70 dprintf_reg(stddeb,"RegOpenKey // return hKey=%08lX !\n", lpKey->hKey);
71 return ERROR_SUCCESS;
75 /*************************************************************************
76 * RegCreateKey [SHELL.2]
78 LONG RegCreateKey(HKEY hKey, LPCSTR lpSubKey, HKEY FAR *lphKey)
80 HKEY hNewKey;
81 LPKEYSTRUCT lpNewKey;
82 LPKEYSTRUCT lpKey = lphRootKey;
83 LPKEYSTRUCT lpPrevKey;
84 LONG dwRet;
85 LPSTR ptr;
86 char str[128];
87 dprintf_reg(stddeb, "RegCreateKey(%08lX, '%s', %p)\n", hKey, lpSubKey, lphKey);
88 if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
89 if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
90 if (hKey != HKEY_CLASSES_ROOT) {
91 dprintf_reg(stddeb,"RegCreateKey // specific key = %08lX !\n", hKey);
92 lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
94 while ( (ptr = strchr(lpSubKey, '\\')) != NULL ) {
95 strncpy(str, lpSubKey, (LONG)ptr - (LONG)lpSubKey);
96 str[(LONG)ptr - (LONG)lpSubKey] = '\0';
97 lpSubKey = ptr + 1;
98 dprintf_reg(stddeb,"RegCreateKey // next level '%s' !\n", str);
99 lpPrevKey = lpKey;
100 while(TRUE) {
101 dprintf_reg(stddeb,"RegCreateKey // '%s' <-> '%s' !\n", str, lpKey->lpSubKey);
102 if (lpKey->lpSubKey != NULL &&
103 strcmp(lpKey->lpSubKey, str) == 0) {
104 if (lpKey->lpSubLvl == NULL) {
105 dprintf_reg(stddeb,"RegCreateKey // '%s' found !\n", str);
106 if ( (ptr = strchr(lpSubKey, '\\')) != NULL ) {
107 strncpy(str, lpSubKey, (LONG)ptr - (LONG)lpSubKey);
108 str[(LONG)ptr - (LONG)lpSubKey] = '\0';
109 lpSubKey = ptr + 1;
111 else
112 strcpy(str, lpSubKey);
113 dwRet = RegCreateKey(lpKey->hKey, str, &hNewKey);
114 if (dwRet != ERROR_SUCCESS) {
115 printf("RegCreateKey // can't create subkey '%s' !\n", str);
116 return dwRet;
118 lpKey->lpSubLvl = (LPKEYSTRUCT)GlobalLock(hNewKey);
120 lpKey = lpKey->lpSubLvl;
121 break;
123 if (lpKey->lpNextKey == NULL) {
124 dwRet = RegCreateKey(lpPrevKey->hKey, str, &hNewKey);
125 if (dwRet != ERROR_SUCCESS) {
126 printf("RegCreateKey // can't create subkey '%s' !\n", str);
127 return dwRet;
129 lpKey = (LPKEYSTRUCT)GlobalLock(hNewKey);
130 break;
132 lpKey = lpKey->lpNextKey;
135 hNewKey = GlobalAlloc(GMEM_MOVEABLE, sizeof(KEYSTRUCT));
136 lpNewKey = (LPKEYSTRUCT) GlobalLock(hNewKey);
137 if (lpNewKey == NULL) {
138 printf("RegCreateKey // Can't alloc new key !\n");
139 return ERROR_OUTOFMEMORY;
141 if (lphRootKey == NULL) {
142 lphRootKey = lpNewKey;
143 lpNewKey->lpPrevKey = NULL;
145 else {
146 lpKey->lpNextKey = lpNewKey;
147 lpNewKey->lpPrevKey = lpKey;
149 lpNewKey->hKey = hNewKey;
150 lpNewKey->lpSubKey = malloc(strlen(lpSubKey) + 1);
151 if (lpNewKey->lpSubKey == NULL) {
152 printf("RegCreateKey // Can't alloc key string !\n");
153 return ERROR_OUTOFMEMORY;
155 strcpy(lpNewKey->lpSubKey, lpSubKey);
156 lpNewKey->dwType = 0;
157 lpNewKey->lpValue = NULL;
158 lpNewKey->lpNextKey = NULL;
159 lpNewKey->lpSubLvl = NULL;
160 *lphKey = hNewKey;
161 dprintf_reg(stddeb,"RegCreateKey // successful '%s' key=%08lX !\n", lpSubKey, hNewKey);
162 return ERROR_SUCCESS;
166 /*************************************************************************
167 * RegCloseKey [SHELL.3]
169 LONG RegCloseKey(HKEY hKey)
171 dprintf_reg(stdnimp, "EMPTY STUB !!! RegCloseKey(%08lX);\n", hKey);
172 return ERROR_INVALID_PARAMETER;
176 /*************************************************************************
177 * RegDeleteKey [SHELL.4]
179 LONG RegDeleteKey(HKEY hKey, LPCSTR lpSubKey)
181 dprintf_reg(stdnimp, "EMPTY STUB !!! RegDeleteKey(%08lX, '%s');\n",
182 hKey, lpSubKey);
183 return ERROR_INVALID_PARAMETER;
187 /*************************************************************************
188 * RegSetValue [SHELL.5]
190 LONG RegSetValue(HKEY hKey, LPCSTR lpSubKey, DWORD dwType,
191 LPCSTR lpVal, DWORD dwIgnored)
193 HKEY hRetKey;
194 LPKEYSTRUCT lpKey;
195 LONG dwRet;
196 dprintf_reg(stddeb, "RegSetValue(%08lX, '%s', %08lX, '%s', %08lX);\n",
197 hKey, lpSubKey, dwType, lpVal, dwIgnored);
198 if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
199 if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
200 if ((dwRet = RegOpenKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
201 dprintf_reg(stddeb, "RegSetValue // key not found ... so create it !\n");
202 if ((dwRet = RegCreateKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
203 fprintf(stderr, "RegSetValue // key creation error %08lX !\n", dwRet);
204 return dwRet;
207 lpKey = (LPKEYSTRUCT)GlobalLock(hRetKey);
208 if (lpKey == NULL) return ERROR_BADKEY;
209 if (lpKey->lpValue != NULL) free(lpKey->lpValue);
210 lpKey->lpValue = malloc(strlen(lpVal) + 1);
211 strcpy(lpKey->lpValue, lpVal);
212 dprintf_reg(stddeb,"RegSetValue // successful key='%s' val='%s' !\n", lpSubKey, lpVal);
213 return ERROR_SUCCESS;
217 /*************************************************************************
218 * RegQueryValue [SHELL.6]
220 LONG RegQueryValue(HKEY hKey, LPCSTR lpSubKey, LPSTR lpVal, LONG FAR *lpcb)
222 HKEY hRetKey;
223 LPKEYSTRUCT lpKey;
224 LONG dwRet;
225 int size;
226 dprintf_reg(stddeb, "RegQueryValue(%08lX, '%s', %p, %p);\n",
227 hKey, lpSubKey, lpVal, lpcb);
228 if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;
229 if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
230 if (lpcb == NULL) return ERROR_INVALID_PARAMETER;
231 if ((dwRet = RegOpenKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
232 fprintf(stderr, "RegQueryValue // key not found !\n");
233 return dwRet;
235 lpKey = (LPKEYSTRUCT)GlobalLock(hRetKey);
236 if (lpKey == NULL) return ERROR_BADKEY;
237 if (lpKey->lpValue != NULL) {
238 size = min(strlen(lpKey->lpValue), *lpcb);
239 strncpy(lpVal, lpKey->lpValue, size);
240 *lpcb = (LONG)size;
242 else {
243 lpVal[0] = '\0';
244 *lpcb = (LONG)0;
246 dprintf_reg(stddeb,"RegQueryValue // return '%s' !\n", lpVal);
247 return ERROR_SUCCESS;
251 /*************************************************************************
252 * RegEnumKey [SHELL.7]
254 LONG RegEnumKey(HKEY hKey, DWORD dwSubKey, LPSTR lpBuf, DWORD dwSize)
256 dprintf_reg(stdnimp, "RegEnumKey : Empty Stub !!!\n");
257 return ERROR_INVALID_PARAMETER;
260 /*************************************************************************
261 * DragAcceptFiles [SHELL.9]
263 void DragAcceptFiles(HWND hWnd, BOOL b)
265 dprintf_reg(stdnimp, "DragAcceptFiles : Empty Stub !!!\n");
269 /*************************************************************************
270 * DragQueryFile [SHELL.11]
272 void DragQueryFile(HDROP h, UINT u, LPSTR u2, UINT u3)
274 dprintf_reg(stdnimp, "DragQueryFile : Empty Stub !!!\n");
279 /*************************************************************************
280 * DragFinish [SHELL.12]
282 void DragFinish(HDROP h)
284 dprintf_reg(stdnimp, "DragFinish : Empty Stub !!!\n");
289 /*************************************************************************
290 * DragQueryPoint [SHELL.13]
292 BOOL DragQueryPoint(HDROP h, POINT FAR *p)
294 dprintf_reg(stdnimp, "DragQueryPoinyt : Empty Stub !!!\n");
295 return FALSE;
299 /*************************************************************************
300 * ShellExecute [SHELL.20]
302 HINSTANCE ShellExecute(HWND hWnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, int iShowCmd)
304 dprintf_reg(stdnimp, "ShellExecute // hWnd=%04X\n", hWnd);
305 dprintf_reg(stdnimp, "ShellExecute // lpOperation='%s'\n", lpOperation);
306 dprintf_reg(stdnimp, "ShellExecute // lpFile='%s'\n", lpFile);
307 dprintf_reg(stdnimp, "ShellExecute // lpParameters='%s'\n", lpParameters);
308 dprintf_reg(stdnimp, "ShellExecute // lpDirectory='%s'\n", lpDirectory);
309 dprintf_reg(stdnimp, "ShellExecute // iShowCmd=%04X\n", iShowCmd);
310 return 2; /* file not found */
314 /*************************************************************************
315 * FindExecutable [SHELL.21]
317 HINSTANCE FindExecutable(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
319 dprintf_reg(stdnimp, "FindExecutable : Empty Stub !!!\n");
320 return 0;
323 char AppName[256], AppMisc[256];
324 INT AboutDlgProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam);
326 /*************************************************************************
327 * ShellAbout [SHELL.22]
329 INT ShellAbout(HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon)
331 /* fprintf(stderr, "ShellAbout ! (%s, %s)\n", szApp, szOtherStuff);*/
333 if (szApp)
334 strcpy(AppName, szApp);
335 else
336 *AppName = 0;
338 if (szOtherStuff)
339 strcpy(AppMisc, szOtherStuff);
340 else
341 *AppMisc = 0;
343 return DialogBoxIndirectPtr(hSysRes, sysres_DIALOG_SHELL_ABOUT_MSGBOX, hWnd, (WNDPROC)AboutDlgProc);
347 /*************************************************************************
348 * AboutDlgProc [SHELL.33]
350 INT AboutDlgProc(HWND hWnd, WORD msg, WORD wParam, LONG lParam)
352 char temp[256];
354 switch(msg) {
355 case WM_INITDIALOG:
356 sprintf(temp, "About %s", AppName);
357 SetWindowText(hWnd, temp);
358 SetDlgItemText(hWnd, 100, AppMisc);
359 break;
361 case WM_COMMAND:
362 switch (wParam) {
363 case IDOK:
364 EndDialog(hWnd, TRUE);
365 return TRUE;
368 return FALSE;
371 /*************************************************************************
372 * ExtractIcon [SHELL.34]
374 HICON ExtractIcon(HINSTANCE hInst, LPCSTR lpszExeFileName, UINT nIconIndex)
376 int count;
377 HICON hIcon = 0;
378 HINSTANCE hInst2 = hInst;
379 dprintf_reg(stddeb, "ExtractIcon(%04X, '%s', %d\n",
380 hInst, lpszExeFileName, nIconIndex);
381 if (lpszExeFileName != NULL) {
382 hInst2 = LoadLibrary(lpszExeFileName);
384 if (hInst2 != 0 && nIconIndex == (UINT)-1) {
385 count = GetRsrcCount(hInst2, NE_RSCTYPE_GROUP_ICON);
386 dprintf_reg(stddeb, "ExtractIcon // '%s' has %d icons !\n", lpszExeFileName, count);
387 return (HICON)count;
389 if (hInst2 != hInst && hInst2 != 0) {
390 FreeLibrary(hInst2);
392 return hIcon;
396 /*************************************************************************
397 * ExtractAssociatedIcon [SHELL.36]
399 HICON ExtractAssociatedIcon(HINSTANCE hInst,LPSTR lpIconPath, LPWORD lpiIcon)
401 dprintf_reg(stdnimp, "ExtractAssociatedIcon : Empty Stub !!!\n");
402 return 0;
405 /*************************************************************************
406 * RegisterShellHook [SHELL.102]
408 int RegisterShellHook(void *ptr)
410 dprintf_reg(stdnimp, "RegisterShellHook : Empty Stub !!!\n");
411 return 0;
415 /*************************************************************************
416 * ShellHookProc [SHELL.103]
418 int ShellHookProc(void)
420 dprintf_reg(stdnimp, "ShellHookProc : Empty Stub !!!\n");
421 return 0;