Release 951212
[wine] / misc / shell.c
1 /*
2  *                              Shell Library Functions
3  */
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <ctype.h>
9 #include "windows.h"
10 #include "shell.h"
11 #include "global.h"
12 #include "neexe.h"
13 #include "selectors.h"
14 #include "alias.h"
15 #include "relay32.h"
16 #include "../rc/sysres.h"
17 #include "dlgs.h"
18 #include "win.h"
19 #include "stddebug.h"
20 #include "debug.h"
21 #include "xmalloc.h"
22
23 LPKEYSTRUCT     lphRootKey = NULL,lphTopKey = NULL;
24
25 static char RootKeyName[]=".classes", TopKeyName[] = "[top-null]";
26
27 /*************************************************************************
28  *                        SHELL_Init()
29  */
30 BOOL SHELL_Init()
31 {
32     HKEY hNewKey;
33     
34     hNewKey = GlobalAlloc(GMEM_MOVEABLE,sizeof(KEYSTRUCT));
35     lphRootKey = (LPKEYSTRUCT) GlobalLock(hNewKey);
36     if (lphRootKey == NULL) {
37         printf("SHELL_RegCheckForRoot: Couldn't allocate root key!\n");
38         return FALSE;
39     }
40     lphRootKey->hKey = (HKEY)1;
41     lphRootKey->lpSubKey = RootKeyName;
42     lphRootKey->dwType = 0;
43     lphRootKey->lpValue = NULL;
44     lphRootKey->lpSubLvl = lphRootKey->lpNextKey = lphRootKey->lpPrevKey = NULL;
45     
46     hNewKey = GlobalAlloc(GMEM_MOVEABLE,sizeof(KEYSTRUCT));
47     lphTopKey = (LPKEYSTRUCT) GlobalLock(hNewKey);
48     if (lphTopKey == NULL) {
49         printf("SHELL_RegCheckForRoot: Couldn't allocate top key!\n");
50         return FALSE;
51     }
52     lphTopKey->hKey = 0;
53     lphTopKey->lpSubKey = TopKeyName;
54     lphTopKey->dwType = 0;
55     lphTopKey->lpValue = NULL;
56     lphTopKey->lpSubLvl = lphRootKey;
57     lphTopKey->lpNextKey = lphTopKey->lpPrevKey = NULL;
58
59     dprintf_reg(stddeb,"SHELL_RegCheckForRoot: Root/Top created\n");
60
61     return TRUE;
62 }
63
64 /* FIXME: the loading and saving of the registry database is rather messy.
65  * bad input (while reading) may crash wine.
66  */
67 void
68 _DumpLevel(FILE *f,LPKEYSTRUCT lpTKey,int tabs)
69 {
70         LPKEYSTRUCT     lpKey;
71
72         lpKey=lpTKey->lpSubLvl;
73         while (lpKey) {
74                 int     i;
75                 for (i=0;i<tabs;i++) fprintf(f,"\t");
76                 /* implement different dwTypes ... */
77                 if (lpKey->lpValue)
78                         fprintf(f,"%s=%s\n",lpKey->lpSubKey,lpKey->lpValue);
79                 else
80                         fprintf(f,"%s\n",lpKey->lpSubKey);
81
82                 if (lpKey->lpSubLvl)
83                         _DumpLevel(f,lpKey,tabs+1);
84                 lpKey=lpKey->lpNextKey;
85         }
86 }
87
88 static void
89 _SaveKey(HKEY hKey,char *where)
90 {
91         FILE            *f;
92         LPKEYSTRUCT     lpKey;
93
94         f=fopen(where,"w");
95         if (f==NULL) {
96                 perror("registry-fopen");
97                 return;
98         }
99         switch ((DWORD)hKey) {
100         case HKEY_CLASSES_ROOT:
101                 lpKey=lphRootKey;
102                 break;
103         default:return;
104         }
105         _DumpLevel(f,lpKey,0);
106         fclose(f);
107 }
108
109 void
110 SHELL_SaveRegistry(void)
111 {
112         /* FIXME: 
113          * -implement win95 additional keytypes here
114          * (HKEY_LOCAL_MACHINE,HKEY_CURRENT_USER or whatever)
115          * -choose better filename(s)
116          */
117         _SaveKey((HKEY)HKEY_CLASSES_ROOT,"/tmp/winereg");
118 }
119
120 #define BUFSIZE 256
121 void
122 _LoadLevel(FILE *f,LPKEYSTRUCT lpKey,int tabsexp,char *buf)
123 {
124         int             i;
125         char            *s,*t;
126         HKEY            hNewKey;
127         LPKEYSTRUCT     lpNewKey;
128
129         while (1) {
130                 if (NULL==fgets(buf,BUFSIZE,f)) {
131                         buf[0]=0;
132                         return;
133                 }
134                 for (i=0;buf[i]=='\t';i++) /*empty*/;
135                 s=buf+i;
136                 if (NULL!=(t=strchr(s,'\n'))) *t='\0';
137                 if (NULL!=(t=strchr(s,'\r'))) *t='\0';
138
139                 if (i<tabsexp) return;
140
141                 if (i>tabsexp) {
142                         hNewKey=GlobalAlloc(GMEM_MOVEABLE,sizeof(KEYSTRUCT));
143                         lpNewKey=lpKey->lpSubLvl=(LPKEYSTRUCT)GlobalLock(hNewKey);
144                         lpNewKey->hKey          = hNewKey;
145                         lpNewKey->dwType        = 0;
146                         lpNewKey->lpSubKey      = NULL;
147                         lpNewKey->lpValue       = NULL;
148                         lpNewKey->lpSubLvl      = NULL;
149                         lpNewKey->lpNextKey     = NULL;
150                         lpNewKey->lpPrevKey     = NULL;
151                         if (NULL!=(t=strchr(s,'='))) {
152                                 *t='\0';t++;
153                                 lpNewKey->dwType        = REG_SZ;
154                                 lpNewKey->lpSubKey      = strdup(s);
155                                 lpNewKey->lpValue       = strdup(t);
156                         } else {
157                                 lpNewKey->dwType        = REG_SZ;
158                                 lpNewKey->lpSubKey      = strdup(s);
159                         }
160                         _LoadLevel(f,lpNewKey,tabsexp+1,buf);
161                 }
162                 for (i=0;buf[i]=='\t';i++) /*empty*/;
163                 s=buf+i;
164                 if (i<tabsexp) return;
165                 if (buf[0]=='\0') break; /* marks end of file */
166                 /* we have a buf now. even when returning from _LoadLevel */
167                 hNewKey         = GlobalAlloc(GMEM_MOVEABLE,sizeof(KEYSTRUCT));
168                 lpNewKey        = lpKey->lpNextKey=(LPKEYSTRUCT)GlobalLock(hNewKey);
169                 lpNewKey->lpPrevKey     = lpKey;
170                 lpNewKey->hKey          = hNewKey;
171                 lpNewKey->dwType        = 0;
172                 lpNewKey->lpSubKey      = NULL;
173                 lpNewKey->lpValue       = NULL;
174                 lpNewKey->lpSubLvl      = NULL;
175                 lpNewKey->lpNextKey     = NULL;
176                 if (NULL!=(t=strchr(s,'='))) {
177                         *t='\0';t++;
178                         lpNewKey->dwType        = REG_SZ;
179                         lpNewKey->lpSubKey      = strdup(s);
180                         lpNewKey->lpValue       = strdup(t);
181                 } else {
182                         lpNewKey->dwType        = REG_SZ;
183                         lpNewKey->lpSubKey      = strdup(s);
184                 }
185                 lpKey=lpNewKey;
186         }
187 }
188
189 void
190 _LoadKey(HKEY hKey,char *from) 
191 {
192         FILE            *f;
193         LPKEYSTRUCT     lpKey;
194         char            buf[BUFSIZE]; /* FIXME: long enough? */
195
196         f=fopen(from,"r");
197         if (f==NULL) {
198                 perror("fopen-registry-read");
199                 return;
200         }
201         switch ((DWORD)hKey) {
202         case HKEY_CLASSES_ROOT:
203                 lpKey=lphRootKey;
204                 break;
205         default:return;
206         }
207         _LoadLevel(f,lpKey,-1,buf);
208 }
209
210 void
211 SHELL_LoadRegistry(void) 
212 {
213         _LoadKey((HKEY)HKEY_CLASSES_ROOT,"/tmp/winereg");
214 }
215
216 /*************************************************************************
217  *                              RegOpenKey              [SHELL.1]
218  */
219 LONG RegOpenKey(HKEY hKey, LPCSTR lpSubKey, HKEY FAR *lphKey)
220 {
221         LPKEYSTRUCT     lpKey,lpNextKey;
222         LPCSTR          ptr;
223         char            str[128];
224
225         dprintf_reg(stddeb, "RegOpenKey(%08lX, %p='%s', %p)\n",
226                                        (DWORD)hKey, lpSubKey, lpSubKey, lphKey);
227         if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
228         switch((DWORD)hKey) {
229         case 0: 
230           lpKey = lphTopKey; break;
231         case HKEY_CLASSES_ROOT: /* == 1 */
232         case 0x80000000:
233           lpKey = lphRootKey; break;
234         default: 
235           dprintf_reg(stddeb,"RegOpenKey // specific key = %08lX !\n", (DWORD)hKey);
236           lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
237         }
238         if (lpSubKey == NULL || !*lpSubKey)  { 
239           *lphKey = hKey; 
240           return ERROR_SUCCESS; 
241         }
242         while(*lpSubKey) {
243           ptr = strchr(lpSubKey,'\\');
244           if (!ptr) ptr = lpSubKey + strlen(lpSubKey);
245           strncpy(str,lpSubKey,ptr-lpSubKey);
246           str[ptr-lpSubKey] = 0;
247           lpSubKey = ptr; 
248           if (*lpSubKey) lpSubKey++;
249           
250           lpNextKey = lpKey->lpSubLvl;
251           while(lpKey != NULL && strcmp(lpKey->lpSubKey, str) != 0) { 
252                 lpKey = lpNextKey;
253                 if (lpKey) lpNextKey = lpKey->lpNextKey;
254           }
255           if (lpKey == NULL) {
256             dprintf_reg(stddeb,"RegOpenKey: key %s not found!\n",str);
257             return ERROR_BADKEY;
258           }         
259         }
260         *lphKey = lpKey->hKey;
261         return ERROR_SUCCESS;
262 }
263
264
265 /*************************************************************************
266  *                              RegCreateKey            [SHELL.2]
267  */
268 LONG RegCreateKey(HKEY hKey, LPCSTR lpSubKey, HKEY FAR *lphKey)
269 {
270         HKEY            hNewKey;
271         LPKEYSTRUCT     lpNewKey;
272         LPKEYSTRUCT     lpKey;
273         LPKEYSTRUCT     lpPrevKey;
274         LPCSTR          ptr;
275         char            str[128];
276
277         dprintf_reg(stddeb, "RegCreateKey(%08lX, '%s', %p)\n",  (DWORD)hKey, lpSubKey, lphKey);
278         if (lphKey == NULL) return ERROR_INVALID_PARAMETER;
279         switch((DWORD)hKey) {
280         case 0: 
281           lpKey = lphTopKey; break;
282         case HKEY_CLASSES_ROOT: /* == 1 */
283         case 0x80000000:
284           lpKey = lphRootKey; break;
285         default: 
286           dprintf_reg(stddeb,"RegCreateKey // specific key = %08lX !\n", (DWORD)hKey);
287           lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
288         }
289         if (lpSubKey == NULL || !*lpSubKey)  { 
290           *lphKey = hKey; 
291           return ERROR_SUCCESS;
292         }
293         while (*lpSubKey) {
294           dprintf_reg(stddeb, "RegCreateKey: Looking for subkey %s\n", lpSubKey);
295           ptr = strchr(lpSubKey,'\\');
296           if (!ptr) ptr = lpSubKey + strlen(lpSubKey);
297           strncpy(str,lpSubKey,ptr-lpSubKey);
298           str[ptr-lpSubKey] = 0;
299           lpSubKey = ptr; 
300           if (*lpSubKey) lpSubKey++;
301           
302           lpPrevKey = lpKey;
303           lpKey = lpKey->lpSubLvl;
304           while(lpKey != NULL && strcmp(lpKey->lpSubKey, str) != 0) { 
305             lpKey = lpKey->lpNextKey; 
306           }
307           if (lpKey == NULL) {
308             hNewKey = GlobalAlloc(GMEM_MOVEABLE, sizeof(KEYSTRUCT));
309             lpNewKey = (LPKEYSTRUCT) GlobalLock(hNewKey);
310             if (lpNewKey == NULL) {
311               printf("RegCreateKey // Can't alloc new key !\n");
312               return ERROR_OUTOFMEMORY;
313             }
314             lpNewKey->hKey = hNewKey;
315             lpNewKey->lpSubKey = malloc(strlen(str) + 1);
316             if (lpNewKey->lpSubKey == NULL) {
317               printf("RegCreateKey // Can't alloc key string !\n");
318               return ERROR_OUTOFMEMORY;
319             }
320             strcpy(lpNewKey->lpSubKey, str);
321             lpNewKey->lpNextKey = lpPrevKey->lpSubLvl;
322             lpNewKey->lpPrevKey = NULL;
323             lpPrevKey->lpSubLvl = lpNewKey;
324
325             lpNewKey->dwType = 0;
326             lpNewKey->lpValue = NULL;
327             lpNewKey->lpSubLvl = NULL;
328             *lphKey = hNewKey;
329             dprintf_reg(stddeb,"RegCreateKey // successful '%s' key=%08lX !\n", str, (DWORD)hNewKey);
330             lpKey = lpNewKey;
331           } else {
332             *lphKey = lpKey->hKey;
333             dprintf_reg(stddeb,"RegCreateKey // found '%s', key=%08lX\n", str, (DWORD)*lphKey);
334           }
335         }
336         return ERROR_SUCCESS;
337 }
338
339
340 /*************************************************************************
341  *                              RegCloseKey             [SHELL.3]
342  */
343 LONG RegCloseKey(HKEY hKey)
344 {
345         dprintf_reg(stdnimp, "EMPTY STUB !!! RegCloseKey(%08lX);\n", (DWORD)hKey);
346         return ERROR_SUCCESS;
347 }
348
349
350 /*************************************************************************
351  *                              RegDeleteKey            [SHELL.4]
352  */
353 LONG RegDeleteKey(HKEY hKey, LPCSTR lpSubKey)
354 {
355         dprintf_reg(stdnimp, "EMPTY STUB !!! RegDeleteKey(%08lX, '%s');\n",
356                      (DWORD)hKey, lpSubKey);
357         return ERROR_SUCCESS;
358 }
359
360
361 /*************************************************************************
362  *                              RegSetValue             [SHELL.5]
363  */
364 LONG RegSetValue(HKEY hKey, LPCSTR lpSubKey, DWORD dwType, 
365                  LPCSTR lpVal, DWORD dwIgnored)
366 {
367     HKEY        hRetKey;
368     LPKEYSTRUCT lpKey;
369     LONG        dwRet;
370     dprintf_reg(stddeb, "RegSetValue(%08lX, '%s', %08lX, '%s', %08lX);\n",
371                 (DWORD)hKey, lpSubKey, dwType, lpVal, dwIgnored);
372     /*if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;*/
373     if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
374     if ((dwRet = RegOpenKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
375         dprintf_reg(stddeb, "RegSetValue // key not found ... so create it !\n");
376         if ((dwRet = RegCreateKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
377             fprintf(stderr, "RegSetValue // key creation error %08lX !\n", dwRet);
378             return dwRet;
379         }
380     }
381     lpKey = (LPKEYSTRUCT)GlobalLock(hRetKey);
382     if (lpKey == NULL) return ERROR_BADKEY;
383     if (lpKey->lpValue != NULL) free(lpKey->lpValue);
384     lpKey->lpValue = xmalloc(strlen(lpVal) + 1);
385     strcpy(lpKey->lpValue, lpVal);
386     dprintf_reg(stddeb,"RegSetValue // successful key='%s' val='%s' !\n", lpSubKey, lpKey->lpValue);
387     return ERROR_SUCCESS;
388 }
389
390
391 /*************************************************************************
392  *                              RegQueryValue           [SHELL.6]
393  */
394 LONG RegQueryValue(HKEY hKey, LPCSTR lpSubKey, LPSTR lpVal, LONG FAR *lpcb)
395 {
396         HKEY            hRetKey;
397         LPKEYSTRUCT     lpKey;
398         LONG            dwRet;
399         int                     size;
400         dprintf_reg(stddeb, "RegQueryValue(%08lX, '%s', %p, %p);\n",
401                     (DWORD)hKey, lpSubKey, lpVal, lpcb);
402         /*if (lpSubKey == NULL) return ERROR_INVALID_PARAMETER;*/
403         if (lpVal == NULL) return ERROR_INVALID_PARAMETER;
404         if (lpcb == NULL) return ERROR_INVALID_PARAMETER;
405         if (!*lpcb) return ERROR_INVALID_PARAMETER;
406
407         if ((dwRet = RegOpenKey(hKey, lpSubKey, &hRetKey)) != ERROR_SUCCESS) {
408                 fprintf(stderr, "RegQueryValue // key not found !\n");
409                 return dwRet;
410         }
411         lpKey = (LPKEYSTRUCT)GlobalLock(hRetKey);
412         if (lpKey == NULL) return ERROR_BADKEY;
413         if (lpKey->lpValue != NULL) {
414           if ((size = strlen(lpKey->lpValue)+1) > *lpcb){
415             strncpy(lpVal,lpKey->lpValue,*lpcb-1);
416             lpVal[*lpcb-1] = 0;
417           } else {
418             strcpy(lpVal,lpKey->lpValue);
419             *lpcb = size;
420           }
421         } else {
422           *lpVal = 0;
423           *lpcb = (LONG)1;
424         }
425         dprintf_reg(stddeb,"RegQueryValue // return '%s' !\n", lpVal);
426         return ERROR_SUCCESS;
427 }
428
429
430 /*************************************************************************
431  *                              RegEnumKey              [SHELL.7]
432  */
433 LONG RegEnumKey(HKEY hKey, DWORD dwSubKey, LPSTR lpBuf, DWORD dwSize)
434 {
435         LPKEYSTRUCT     lpKey;
436         LONG            len;
437
438         dprintf_reg(stddeb, "RegEnumKey(%08lX, %ld)\n", (DWORD)hKey, dwSubKey);
439         if (lpBuf == NULL) return ERROR_INVALID_PARAMETER;
440         switch((DWORD)hKey) {
441         case 0: 
442           lpKey = lphTopKey; break;
443         case HKEY_CLASSES_ROOT: /* == 1 */
444         case 0x80000000:
445           lpKey = lphRootKey; break;
446         default: 
447           dprintf_reg(stddeb,"RegEnumKey // specific key = %08lX !\n", (DWORD)hKey);
448           lpKey = (LPKEYSTRUCT)GlobalLock(hKey);
449         }
450         lpKey = lpKey->lpSubLvl;
451         while(lpKey != NULL){
452           if (!dwSubKey){
453             len = MIN(dwSize-1,strlen(lpKey->lpSubKey));
454             strncpy(lpBuf,lpKey->lpSubKey,len);
455             lpBuf[len] = 0;
456             dprintf_reg(stddeb, "RegEnumKey: found %s\n",lpBuf);
457             return ERROR_SUCCESS;
458           }
459           dwSubKey--;
460           lpKey = lpKey->lpNextKey;
461         }
462         dprintf_reg(stddeb, "RegEnumKey: key not found!\n");
463         return ERROR_INVALID_PARAMETER;
464 }
465
466
467 /*************************************************************************
468  *                              DragAcceptFiles         [SHELL.9]
469  */
470 void DragAcceptFiles(HWND hWnd, BOOL b)
471 {
472     /* flips WS_EX_ACCEPTFILES bit according to the value of b */
473     dprintf_reg(stddeb,"DragAcceptFiles("NPFMT", %u) old exStyle %08lx\n",
474                 hWnd,b,GetWindowLong(hWnd,GWL_EXSTYLE));
475
476     SetWindowLong(hWnd,GWL_EXSTYLE,
477                   GetWindowLong(hWnd,GWL_EXSTYLE) | b*(LONG)WS_EX_ACCEPTFILES);
478 }
479
480
481 /*************************************************************************
482  *                              DragQueryFile           [SHELL.11]
483  */
484 UINT DragQueryFile(HDROP hDrop, WORD wFile, LPSTR lpszFile, WORD wLength)
485 {
486     /* hDrop is a global memory block allocated with GMEM_SHARE 
487      * with DROPFILESTRUCT as a header and filenames following
488      * it, zero length filename is in the end */       
489     
490     LPDROPFILESTRUCT lpDropFileStruct;
491     LPSTR lpCurrent;
492     WORD  i;
493     
494     dprintf_reg(stddeb,"DragQueryFile("NPFMT", %i, %p, %u)\n",
495                 hDrop,wFile,lpszFile,wLength);
496     
497     lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); 
498     if(!lpDropFileStruct)
499     {
500         dprintf_reg(stddeb,"DragQueryFile: unable to lock handle!\n");
501         return 0;
502     } 
503     lpCurrent = (LPSTR) lpDropFileStruct + lpDropFileStruct->wSize;
504     
505     i = 0;
506     while (i++ < wFile)
507     {
508         while (*lpCurrent++);  /* skip filename */
509         if (!*lpCurrent) 
510             return (wFile == 0xFFFF) ? i : 0;  
511     }
512     
513     i = strlen(lpCurrent); 
514     if (!lpszFile) return i+1;   /* needed buffer size */
515     
516     i = (wLength > i) ? i : wLength-1;
517     strncpy(lpszFile, lpCurrent, i);
518     lpszFile[i] = '\0';
519     
520     GlobalUnlock(hDrop);
521     return i;
522 }
523
524
525 /*************************************************************************
526  *                              DragFinish              [SHELL.12]
527  */
528 void DragFinish(HDROP h)
529 {
530     GlobalFree((HGLOBAL)h);
531 }
532
533
534 /*************************************************************************
535  *                              DragQueryPoint          [SHELL.13]
536  */
537 BOOL DragQueryPoint(HDROP hDrop, POINT FAR *p)
538 {
539     LPDROPFILESTRUCT lpDropFileStruct;  
540     BOOL             bRet;
541
542     lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop);
543
544     memcpy(p,&lpDropFileStruct->ptMousePos,sizeof(POINT));
545     bRet = lpDropFileStruct->fInNonClientArea;
546
547     GlobalUnlock(hDrop);
548     return bRet;
549 }
550
551
552 /*************************************************************************
553  *                              ShellExecute            [SHELL.20]
554  */
555 HINSTANCE ShellExecute(HWND hWnd, LPCSTR lpOperation, LPCSTR lpFile, LPCSTR lpParameters, LPCSTR lpDirectory, int iShowCmd)
556 {
557     char cmd[400];
558     char *p,*x;
559     long len;
560     char subclass[200];
561     /* OK. We are supposed to lookup the program associated with lpFile,
562      * then to execute it using that program. If lpFile is a program,
563      * we have to pass the parameters. If an instance is already running,
564      * we might have to send DDE commands.
565      */
566     dprintf_exec(stddeb, "ShellExecute("NPFMT",'%s','%s','%s','%s',%x)\n",
567                 hWnd, lpOperation ? lpOperation:"<null>", lpFile ? lpFile:"<null>",
568                 lpParameters ? lpParameters : "<null>", 
569                 lpDirectory ? lpDirectory : "<null>", iShowCmd);
570     if (lpFile==NULL) return 0; /* should not happen */
571     if (lpOperation==NULL) /* default is open */
572       lpOperation="open";
573     p=strrchr(lpFile,'.');
574     if (p!=NULL) {
575       x=p; /* the suffixes in the register database are lowercased */
576       while (*x) {*x=tolower(*x);x++;}
577     }
578     if (p==NULL || !strcmp(p,".exe")) {
579       p=".exe";
580       if (lpParameters) {
581         sprintf(cmd,"%s %s",lpFile,lpParameters);
582       } else {
583         strcpy(cmd,lpFile);
584       }
585     } else {
586       len=200;
587       if (RegQueryValue((HKEY)HKEY_CLASSES_ROOT,p,subclass,&len)==ERROR_SUCCESS) {
588         if (len>20)
589           fprintf(stddeb,"ShellExecute:subclass with len %ld? (%s), please report.\n",len,subclass);
590         subclass[len]='\0';
591         strcat(subclass,"\\shell\\");
592         strcat(subclass,lpOperation);
593         strcat(subclass,"\\command");
594         dprintf_exec(stddeb,"ShellExecute:looking for %s.\n",subclass);
595         len=400;
596         if (RegQueryValue((HKEY)HKEY_CLASSES_ROOT,subclass,cmd,&len)==ERROR_SUCCESS) {
597           char *t;
598           dprintf_exec(stddeb,"ShellExecute:...got %s\n",cmd);
599           cmd[len]='\0';
600           t=strstr(cmd,"%1");
601           if (t==NULL) {
602             strcat(cmd," ");
603             strcat(cmd,lpFile);
604           } else {
605             char *s;
606             s=xmalloc(len+strlen(lpFile)+10);
607             strncpy(s,cmd,t-cmd);
608             s[t-cmd]='\0';
609             strcat(s,lpFile);
610             strcat(s,t+2);
611             strcpy(cmd,s);
612             free(s);
613           }
614           /* does this use %x magic too? */
615           if (lpParameters) {
616             strcat(cmd," ");
617             strcat(cmd,lpParameters);
618           }
619         } else {
620           fprintf(stddeb,"ShellExecute: No %s\\shell\\%s\\command found for \"%s\" suffix.\n",subclass,lpOperation,p);
621           return (HINSTANCE)14; /* unknown type */
622         }
623       } else {
624         fprintf(stddeb,"ShellExecute: No operation found for \"%s\" suffix.\n",p);
625         return (HINSTANCE)14; /* file not found */
626       }
627     }
628     dprintf_exec(stddeb,"ShellExecute:starting %s\n",cmd);
629     return WinExec(cmd,iShowCmd);
630 }
631
632
633 /*************************************************************************
634  *                              FindExecutable          [SHELL.21]
635  */
636 HINSTANCE FindExecutable(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
637 {
638         fprintf(stdnimp, "FindExecutable : Empty Stub !!!\n");
639         return 0;
640 }
641
642 static char AppName[128], AppMisc[906];
643
644 /*************************************************************************
645  *                              AboutDlgProc            [SHELL.33]
646  */
647 LRESULT AboutDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
648 {
649   char Template[512], AppTitle[512];
650  
651   switch(msg) {
652    case WM_INITDIALOG:
653 #ifdef WINELIB32
654     SendDlgItemMessage(hWnd,stc1,STM_SETICON,lParam,0);
655 #else
656     SendDlgItemMessage(hWnd,stc1,STM_SETICON,LOWORD(lParam),0);
657 #endif
658     GetWindowText(hWnd, Template, 511);
659     sprintf(AppTitle, Template, AppName);
660     SetWindowText(hWnd, AppTitle);
661     SetWindowText(GetDlgItem(hWnd,100), AppMisc);
662     return 1;
663     
664    case WM_COMMAND:
665     switch (wParam) {
666      case IDOK:
667       EndDialog(hWnd, TRUE);
668       return TRUE;
669     }
670     break;
671   }
672   return FALSE;
673 }
674
675 /*************************************************************************
676  *                              ShellAbout              [SHELL.22]
677  */
678 INT ShellAbout(HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON hIcon)
679 {
680     HANDLE handle;
681     BOOL bRet;
682     DWORD WineProc,Win16Proc,Win32Proc;
683     static int initialized=0;
684
685     if (szApp) strncpy(AppName, szApp, sizeof(AppName));
686     else *AppName = 0;
687     AppName[sizeof(AppName)-1]=0;
688
689     if (szOtherStuff) strncpy(AppMisc, szOtherStuff, sizeof(AppMisc));
690     else *AppMisc = 0;
691     AppMisc[sizeof(AppMisc)-1]=0;
692
693     if (!hIcon) hIcon = LoadIcon(0,MAKEINTRESOURCE(OIC_WINEICON));
694     
695     if(!initialized)
696     {
697         WineProc=(DWORD)AboutDlgProc;
698         Win16Proc=(DWORD)GetWndProcEntry16("AboutDlgProc");
699         Win32Proc=(DWORD)RELAY32_GetEntryPoint("WINPROCS32","AboutDlgProc",0);
700         ALIAS_RegisterAlias(WineProc,Win16Proc,Win32Proc);
701         initialized=1;
702     }
703
704     handle = GLOBAL_CreateBlock( GMEM_FIXED,
705                                  sysres_DIALOG_SHELL_ABOUT_MSGBOX.bytes,
706                                  sysres_DIALOG_SHELL_ABOUT_MSGBOX.size,
707                                  GetCurrentPDB(), FALSE, FALSE,
708                                  TRUE, NULL );
709     if (!handle) return FALSE;
710     bRet = DialogBoxIndirectParam( WIN_GetWindowInstance( hWnd ),
711                                    handle, hWnd,
712                                    GetWndProcEntry16("AboutDlgProc"), 
713                                    (LONG)hIcon );
714     GLOBAL_FreeBlock( handle );
715     return bRet;
716 }
717
718 /*************************************************************************
719  *                              ExtractIcon             [SHELL.34]
720  */
721 HICON ExtractIcon(HINSTANCE hInst, LPCSTR lpszExeFileName, UINT nIconIndex)
722 {
723         HICON   hIcon = 0;
724         HINSTANCE hInst2 = hInst;
725         dprintf_reg(stddeb, "ExtractIcon("NPFMT", '%s', %d\n", 
726                         hInst, lpszExeFileName, nIconIndex);
727         return 0;
728         if (lpszExeFileName != NULL) {
729                 hInst2 = LoadModule(lpszExeFileName,(LPVOID)-1);
730         }
731         if (hInst2 != 0 && nIconIndex == (UINT)-1) {
732 #if 0
733                 count = GetRsrcCount(hInst2, NE_RSCTYPE_GROUP_ICON);
734                 dprintf_reg(stddeb, "ExtractIcon // '%s' has %d icons !\n", lpszExeFileName, count);
735                 return (HICON)count;
736 #endif
737         }
738         if (hInst2 != hInst && hInst2 != 0) {
739                 FreeLibrary(hInst2);
740         }
741         return hIcon;
742 }
743
744
745 /*************************************************************************
746  *                              ExtractAssociatedIcon   [SHELL.36]
747  */
748 HICON ExtractAssociatedIcon(HINSTANCE hInst,LPSTR lpIconPath, LPWORD lpiIcon)
749 {
750     dprintf_reg(stdnimp, "ExtractAssociatedIcon : Empty Stub !!!\n");
751     return 0;
752 }
753
754 /*************************************************************************
755  *              DoEnvironmentSubst      [SHELL.37]
756  */
757 DWORD DoEnvironmentSubst(LPSTR str,WORD len)
758 {
759     dprintf_reg(stdnimp, "DoEnvironmentSubst(%s,%x): Empyt Stub !!!\n",str,len);
760     return 0;
761 }
762
763 /*************************************************************************
764  *                              RegisterShellHook       [SHELL.102]
765  */
766 int RegisterShellHook(void *ptr) 
767 {
768         dprintf_reg(stdnimp, "RegisterShellHook : Empty Stub !!!\n");
769         return 0;
770 }
771
772
773 /*************************************************************************
774  *                              ShellHookProc           [SHELL.103]
775  */
776 int ShellHookProc(void) 
777 {
778         dprintf_reg(stdnimp, "ShellHookProc : Empty Stub !!!\n");
779         return 0;
780 }