Partial implementation of the Shell32 call Win32DeleteFile(), required
[wine] / dlls / shell32 / shell.c
1 /*
2  *                              Shell Library Functions
3  *
4  *  1998 Marcus Meissner
5  */
6 #include <assert.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <ctype.h>
11 #include "wine/winuser16.h"
12 #include "wine/winbase16.h"
13 #include "wine/shell16.h"
14 #include "winerror.h"
15 #include "file.h"
16 #include "heap.h"
17 #include "ldt.h"
18 #include "module.h"
19 #include "neexe.h"
20 #include "dlgs.h"
21 #include "cursoricon.h"
22 #include "shellapi.h"
23 #include "shlobj.h"
24 #include "debugtools.h"
25 #include "winreg.h"
26 #include "syslevel.h"
27 #include "imagelist.h"
28
29 DECLARE_DEBUG_CHANNEL(exec)
30 DECLARE_DEBUG_CHANNEL(shell)
31
32 /* .ICO file ICONDIR definitions */
33
34 #include "pshpack1.h"
35
36 typedef struct
37 {
38     BYTE        bWidth;          /* Width, in pixels, of the image      */
39     BYTE        bHeight;         /* Height, in pixels, of the image     */
40     BYTE        bColorCount;     /* Number of colors in image (0 if >=8bpp) */
41     BYTE        bReserved;       /* Reserved ( must be 0)               */
42     WORD        wPlanes;         /* Color Planes                        */
43     WORD        wBitCount;       /* Bits per pixel                      */
44     DWORD       dwBytesInRes;    /* How many bytes in this resource?    */
45     DWORD       dwImageOffset;   /* Where in the file is this image?    */
46 } icoICONDIRENTRY, *LPicoICONDIRENTRY;
47
48 typedef struct
49 {
50     WORD            idReserved;   /* Reserved (must be 0)               */
51     WORD            idType;       /* Resource Type (1 for icons)        */
52     WORD            idCount;      /* How many images?                   */
53     icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */
54 } icoICONDIR, *LPicoICONDIR;
55
56 #include "poppack.h"
57
58 static const char*      lpstrMsgWndCreated = "OTHERWINDOWCREATED";
59 static const char*      lpstrMsgWndDestroyed = "OTHERWINDOWDESTROYED";
60 static const char*      lpstrMsgShellActivate = "ACTIVATESHELLWINDOW";
61
62 static HWND16   SHELL_hWnd = 0;
63 static HHOOK    SHELL_hHook = 0;
64 static UINT16   uMsgWndCreated = 0;
65 static UINT16   uMsgWndDestroyed = 0;
66 static UINT16   uMsgShellActivate = 0;
67 HINSTANCE16     SHELL_hInstance = 0;
68 HINSTANCE SHELL_hInstance32;
69 static int SHELL_Attach = 0;
70
71 /***********************************************************************
72  * SHELL_DllEntryPoint [SHELL.entry]
73  *
74  * Initialization code for shell.dll. Automatically loads the
75  * 32-bit shell32.dll to allow thunking up to 32-bit code.
76  *
77  * RETURNS:
78  */
79 BOOL WINAPI SHELL_DllEntryPoint(DWORD Reason, HINSTANCE16 hInst,
80                                 WORD ds, WORD HeapSize, DWORD res1, WORD res2)
81 {
82     TRACE_(shell)("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n",
83                   Reason, hInst, ds, HeapSize, res1, res2);
84
85     switch(Reason)
86     {
87     case DLL_PROCESS_ATTACH:
88         SHELL_Attach++;
89         if (SHELL_hInstance)
90         {
91             ERR_(shell)("shell.dll instantiated twice!\n");
92             /*
93              * We should return FALSE here, but that will break
94              * most apps that use CreateProcess because we do
95              * not yet support seperate address-spaces.
96              */
97             return TRUE;
98         }
99
100         SHELL_hInstance = hInst;
101         if(!SHELL_hInstance32)
102         {
103             if(!(SHELL_hInstance32 = LoadLibraryA("shell32.dll")))
104             {
105                 ERR_(shell)("Could not load sibling shell32.dll\n");
106                 return FALSE;
107             }
108         }
109         break;
110
111     case DLL_PROCESS_DETACH:
112         if(!--SHELL_Attach)
113         {
114             SHELL_hInstance = 0;
115             if(SHELL_hInstance32)
116                 FreeLibrary(SHELL_hInstance32);
117         }
118         break;
119     }
120     return TRUE;
121 }
122
123 /*************************************************************************
124  *                              DragAcceptFiles32               [SHELL32.54]
125  */
126 void WINAPI DragAcceptFiles(HWND hWnd, BOOL b)
127 {
128   LONG exstyle;
129   
130   
131   if( !IsWindow(hWnd) )
132         return;
133   exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE);
134   if (b)exstyle |= WS_EX_ACCEPTFILES;
135   else  exstyle &= ~WS_EX_ACCEPTFILES;
136   SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle);
137 }
138
139 /*************************************************************************
140  *                              DragAcceptFiles16               [SHELL.9]
141  */
142 void WINAPI DragAcceptFiles16(HWND16 hWnd, BOOL16 b)
143 {
144   DragAcceptFiles(hWnd, b);
145 }
146
147 /*************************************************************************
148  *                              SHELL_DragQueryFile     [internal]
149  * 
150  */
151 static UINT SHELL_DragQueryFile(LPSTR lpDrop, LPWSTR lpwDrop, UINT lFile, 
152                                   LPSTR lpszFile, LPWSTR lpszwFile, UINT lLength)
153 {
154     UINT i;
155
156     i = 0;
157     if (lpDrop) {
158     while (i++ < lFile) {
159         while (*lpDrop++); /* skip filename */
160         if (!*lpDrop) 
161           return (lFile == 0xFFFFFFFF) ? i : 0;  
162       }
163     }
164     if (lpwDrop) {
165       while (i++ < lFile) {
166         while (*lpwDrop++); /* skip filename */
167         if (!*lpwDrop) 
168           return (lFile == 0xFFFFFFFF) ? i : 0;  
169       }
170     }
171     
172     if (lpDrop)  i = lstrlenA(lpDrop);
173     if (lpwDrop) i = lstrlenW(lpwDrop);
174     i++;
175     if (!lpszFile && !lpszwFile) {
176       return i;   /* needed buffer size */
177     }
178     i = (lLength > i) ? i : lLength;
179     if (lpszFile) {
180       if (lpDrop) lstrcpynA (lpszFile,  lpDrop,  i);
181       else        lstrcpynWtoA(lpszFile,  lpwDrop, i);
182     } else {
183       if (lpDrop) lstrcpynAtoW(lpszwFile, lpDrop,  i);
184       else        lstrcpynW (lpszwFile, lpwDrop, i);
185     }
186     return i;
187 }
188
189 /*************************************************************************
190  *                              DragQueryFile32A        [SHELL32.81] [shell32.82]
191  */
192 UINT WINAPI DragQueryFileA(HDROP hDrop, UINT lFile, LPSTR lpszFile,
193                               UINT lLength)
194 { /* hDrop is a global memory block allocated with GMEM_SHARE 
195      * with DROPFILESTRUCT as a header and filenames following
196      * it, zero length filename is in the end */       
197     
198     LPDROPFILESTRUCT lpDropFileStruct;
199     LPSTR lpCurrent;
200     UINT i;
201     
202     TRACE_(shell)("(%08x, %x, %p, %u)\n",       hDrop,lFile,lpszFile,lLength);
203     
204     lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); 
205     if(!lpDropFileStruct)
206       return 0;
207
208     lpCurrent = (LPSTR) lpDropFileStruct + lpDropFileStruct->lSize;
209     i = SHELL_DragQueryFile(lpCurrent, NULL, lFile, lpszFile, NULL, lLength);
210     GlobalUnlock(hDrop);
211     return i;
212 }
213
214 /*************************************************************************
215  *                              DragQueryFile32W        [shell32.133]
216  */
217 UINT WINAPI DragQueryFileW(HDROP hDrop, UINT lFile, LPWSTR lpszwFile,
218                               UINT lLength)
219 {
220     LPDROPFILESTRUCT lpDropFileStruct;
221     LPWSTR lpwCurrent;
222     UINT i;
223     
224     TRACE_(shell)("(%08x, %x, %p, %u)\n",       hDrop,lFile,lpszwFile,lLength);
225     
226     lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); 
227     if(!lpDropFileStruct)
228       return 0;
229
230     lpwCurrent = (LPWSTR) lpDropFileStruct + lpDropFileStruct->lSize;
231     i = SHELL_DragQueryFile(NULL, lpwCurrent, lFile, NULL, lpszwFile,lLength);
232     GlobalUnlock(hDrop);
233     return i;
234 }
235 /*************************************************************************
236  *                              DragQueryFile16         [SHELL.11]
237  */
238 UINT16 WINAPI DragQueryFile16(HDROP16 hDrop, WORD wFile, LPSTR lpszFile,
239                             WORD wLength)
240 { /* hDrop is a global memory block allocated with GMEM_SHARE 
241      * with DROPFILESTRUCT as a header and filenames following
242      * it, zero length filename is in the end */       
243     
244     LPDROPFILESTRUCT16 lpDropFileStruct;
245     LPSTR lpCurrent;
246     WORD  i;
247     
248     TRACE_(shell)("(%04x, %x, %p, %u)\n", hDrop,wFile,lpszFile,wLength);
249     
250     lpDropFileStruct = (LPDROPFILESTRUCT16) GlobalLock16(hDrop); 
251     if(!lpDropFileStruct)
252       return 0;
253     
254     lpCurrent = (LPSTR) lpDropFileStruct + lpDropFileStruct->wSize;
255
256     i = (WORD)SHELL_DragQueryFile(lpCurrent, NULL, wFile==0xffff?0xffffffff:wFile,
257                                   lpszFile, NULL, wLength);
258     GlobalUnlock16(hDrop);
259     return i;
260 }
261
262
263
264 /*************************************************************************
265  *                              DragFinish32            [SHELL32.80]
266  */
267 void WINAPI DragFinish(HDROP h)
268 { TRACE_(shell)("\n");
269     GlobalFree((HGLOBAL)h);
270 }
271
272 /*************************************************************************
273  *                              DragFinish16            [SHELL.12]
274  */
275 void WINAPI DragFinish16(HDROP16 h)
276 { TRACE_(shell)("\n");
277     GlobalFree16((HGLOBAL16)h);
278 }
279
280
281 /*************************************************************************
282  *                              DragQueryPoint32                [SHELL32.135]
283  */
284 BOOL WINAPI DragQueryPoint(HDROP hDrop, POINT *p)
285 {
286   LPDROPFILESTRUCT lpDropFileStruct;  
287   BOOL             bRet;
288   TRACE_(shell)("\n");
289   lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop);
290   
291   memcpy(p,&lpDropFileStruct->ptMousePos,sizeof(POINT));
292   bRet = lpDropFileStruct->fInNonClientArea;
293   
294   GlobalUnlock(hDrop);
295   return bRet;
296 }
297
298 /*************************************************************************
299  *                              DragQueryPoint16                [SHELL.13]
300  */
301 BOOL16 WINAPI DragQueryPoint16(HDROP16 hDrop, POINT16 *p)
302 {
303   LPDROPFILESTRUCT16 lpDropFileStruct;  
304   BOOL16           bRet;
305   TRACE_(shell)("\n");
306   lpDropFileStruct = (LPDROPFILESTRUCT16) GlobalLock16(hDrop);
307   
308   memcpy(p,&lpDropFileStruct->ptMousePos,sizeof(POINT16));
309   bRet = lpDropFileStruct->fInNonClientArea;
310   
311   GlobalUnlock16(hDrop);
312   return bRet;
313 }
314
315 /*************************************************************************
316  *      SHELL_FindExecutable [Internal]
317  *
318  * Utility for code sharing between FindExecutable and ShellExecute
319  */
320 HINSTANCE SHELL_FindExecutable( LPCSTR lpFile, 
321                                          LPCSTR lpOperation,
322                                          LPSTR lpResult)
323 { char *extension = NULL; /* pointer to file extension */
324     char tmpext[5];         /* local copy to mung as we please */
325     char filetype[256];     /* registry name for this filetype */
326     LONG filetypelen=256;   /* length of above */
327     char command[256];      /* command from registry */
328     LONG commandlen=256;    /* This is the most DOS can handle :) */
329     char buffer[256];       /* Used to GetProfileString */
330     HINSTANCE retval=31;  /* default - 'No association was found' */
331     char *tok;              /* token pointer */
332     int i;                  /* random counter */
333     char xlpFile[256];      /* result of SearchPath */
334
335   TRACE_(shell)("%s\n", (lpFile != NULL?lpFile:"-") );
336
337     lpResult[0]='\0'; /* Start off with an empty return string */
338
339     /* trap NULL parameters on entry */
340     if (( lpFile == NULL ) || ( lpResult == NULL ) || ( lpOperation == NULL ))
341   { WARN_(exec)("(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n",
342            lpFile, lpOperation, lpResult);
343         return 2; /* File not found. Close enough, I guess. */
344     }
345
346     if (SearchPathA( NULL, lpFile,".exe",sizeof(xlpFile),xlpFile,NULL))
347   { TRACE_(shell)("SearchPath32A returned non-zero\n");
348         lpFile = xlpFile;
349     }
350
351     /* First thing we need is the file's extension */
352     extension = strrchr( xlpFile, '.' ); /* Assume last "." is the one; */
353                                         /* File->Run in progman uses */
354                                         /* .\FILE.EXE :( */
355   TRACE_(shell)("xlpFile=%s,extension=%s\n", xlpFile, extension);
356
357     if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)]))
358   { WARN_(shell)("Returning 31 - No association\n");
359         return 31; /* no association */
360     }
361
362     /* Make local copy & lowercase it for reg & 'programs=' lookup */
363     lstrcpynA( tmpext, extension, 5 );
364     CharLowerA( tmpext );
365   TRACE_(shell)("%s file\n", tmpext);
366     
367     /* Three places to check: */
368     /* 1. win.ini, [windows], programs (NB no leading '.') */
369     /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
370     /* 3. win.ini, [extensions], extension (NB no leading '.' */
371     /* All I know of the order is that registry is checked before */
372     /* extensions; however, it'd make sense to check the programs */
373     /* section first, so that's what happens here. */
374
375     /* See if it's a program - if GetProfileString fails, we skip this
376      * section. Actually, if GetProfileString fails, we've probably
377      * got a lot more to worry about than running a program... */
378     if ( GetProfileStringA("windows", "programs", "exe pif bat com",
379                                                   buffer, sizeof(buffer)) > 0 )
380   { for (i=0;i<strlen(buffer); i++) buffer[i]=tolower(buffer[i]);
381
382                 tok = strtok(buffer, " \t"); /* ? */
383                 while( tok!= NULL)
384                   {
385                         if (strcmp(tok, &tmpext[1])==0) /* have to skip the leading "." */
386                           {
387                                 strcpy(lpResult, xlpFile);
388                                 /* Need to perhaps check that the file has a path
389                                  * attached */
390         TRACE_(shell)("found %s\n", lpResult);
391                                 return 33;
392
393                 /* Greater than 32 to indicate success FIXME According to the
394                  * docs, I should be returning a handle for the
395                  * executable. Does this mean I'm supposed to open the
396                  * executable file or something? More RTFM, I guess... */
397                           }
398                         tok=strtok(NULL, " \t");
399                   }
400           }
401
402     /* Check registry */
403     if (RegQueryValue16( HKEY_CLASSES_ROOT, tmpext, filetype,
404                          &filetypelen ) == ERROR_SUCCESS )
405     {
406         filetype[filetypelen]='\0';
407   TRACE_(shell)("File type: %s\n", filetype);
408
409         /* Looking for ...buffer\shell\lpOperation\command */
410         strcat( filetype, "\\shell\\" );
411         strcat( filetype, lpOperation );
412         strcat( filetype, "\\command" );
413         
414         if (RegQueryValue16( HKEY_CLASSES_ROOT, filetype, command,
415                              &commandlen ) == ERROR_SUCCESS )
416         {
417             /* Is there a replace() function anywhere? */
418             command[commandlen]='\0';
419             strcpy( lpResult, command );
420             tok=strstr( lpResult, "%1" );
421             if (tok != NULL)
422             {
423                 tok[0]='\0'; /* truncate string at the percent */
424                 strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */
425                 tok=strstr( command, "%1" );
426                 if ((tok!=NULL) && (strlen(tok)>2))
427                 {
428                     strcat( lpResult, &tok[2] );
429                 }
430             }
431             retval=33; /* FIXME see above */
432         }
433     }
434     else /* Check win.ini */
435     {
436         /* Toss the leading dot */
437         extension++;
438         if ( GetProfileStringA( "extensions", extension, "", command,
439                                   sizeof(command)) > 0)
440           {
441                 if (strlen(command)!=0)
442                   {
443                         strcpy( lpResult, command );
444                         tok=strstr( lpResult, "^" ); /* should be ^.extension? */
445                         if (tok != NULL)
446                           {
447                                 tok[0]='\0';
448                                 strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */
449                                 tok=strstr( command, "^" ); /* see above */
450                                 if ((tok != NULL) && (strlen(tok)>5))
451                                   {
452                                         strcat( lpResult, &tok[5]);
453                                   }
454                           }
455                         retval=33; /* FIXME - see above */
456                   }
457           }
458         }
459
460     TRACE_(shell)("returning %s\n", lpResult);
461     return retval;
462 }
463
464 /*************************************************************************
465  *                              ShellExecute16          [SHELL.20]
466  */
467 HINSTANCE16 WINAPI ShellExecute16( HWND16 hWnd, LPCSTR lpOperation,
468                                    LPCSTR lpFile, LPCSTR lpParameters,
469                                    LPCSTR lpDirectory, INT16 iShowCmd )
470 {   HINSTANCE16 retval=31;
471     char old_dir[1024];
472     char cmd[256];
473
474     TRACE_(shell)("(%04x,'%s','%s','%s','%s',%x)\n",
475                 hWnd, lpOperation ? lpOperation:"<null>", lpFile ? lpFile:"<null>",
476                 lpParameters ? lpParameters : "<null>", 
477                 lpDirectory ? lpDirectory : "<null>", iShowCmd);
478
479     if (lpFile==NULL) return 0; /* should not happen */
480     if (lpOperation==NULL) /* default is open */
481       lpOperation="open";
482
483     if (lpDirectory)
484     { GetCurrentDirectoryA( sizeof(old_dir), old_dir );
485         SetCurrentDirectoryA( lpDirectory );
486     }
487
488     retval = SHELL_FindExecutable( lpFile, lpOperation, cmd );
489
490     if (retval > 32)  /* Found */
491     {
492         if (lpParameters)
493         {
494             strcat(cmd," ");
495             strcat(cmd,lpParameters);
496         }
497
498         TRACE_(shell)("starting %s\n",cmd);
499         SYSLEVEL_ReleaseWin16Lock();
500         retval = WinExec( cmd, iShowCmd );
501         SYSLEVEL_RestoreWin16Lock();
502     }
503     if (lpDirectory)
504       SetCurrentDirectoryA( old_dir );
505     return retval;
506 }
507
508 /*************************************************************************
509  *             FindExecutable16   (SHELL.21)
510  */
511 HINSTANCE16 WINAPI FindExecutable16( LPCSTR lpFile, LPCSTR lpDirectory,
512                                      LPSTR lpResult )
513 { return (HINSTANCE16)FindExecutableA( lpFile, lpDirectory, lpResult );
514 }
515
516
517 /*************************************************************************
518  *             AboutDlgProc16   (SHELL.33)
519  */
520 BOOL16 WINAPI AboutDlgProc16( HWND16 hWnd, UINT16 msg, WPARAM16 wParam,
521                                LPARAM lParam )
522 { return AboutDlgProc( hWnd, msg, wParam, lParam );
523 }
524
525
526 /*************************************************************************
527  *             ShellAbout16   (SHELL.22)
528  */
529 BOOL16 WINAPI ShellAbout16( HWND16 hWnd, LPCSTR szApp, LPCSTR szOtherStuff,
530                             HICON16 hIcon )
531 { return ShellAboutA( hWnd, szApp, szOtherStuff, hIcon );
532 }
533
534 /*************************************************************************
535  *                              SHELL_GetResourceTable
536  */
537 static DWORD SHELL_GetResourceTable(HFILE hFile,LPBYTE *retptr)
538 {       IMAGE_DOS_HEADER        mz_header;
539         char                    magic[4];
540         int                     size;
541
542         TRACE_(shell)("\n");  
543
544         *retptr = NULL;
545         _llseek( hFile, 0, SEEK_SET );
546         if ((_lread(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) || (mz_header.e_magic != IMAGE_DOS_SIGNATURE))
547         { /* .ICO file ? */
548           if (mz_header.e_cblp == 1) 
549           { /* ICONHEADER.idType, must be 1 */
550             *retptr = (LPBYTE)-1;
551             return 1;
552           }
553           else
554             return 0; /* failed */
555         }
556         _llseek( hFile, mz_header.e_lfanew, SEEK_SET );
557
558         if (_lread( hFile, magic, sizeof(magic) ) != sizeof(magic))
559           return 0;
560
561         _llseek( hFile, mz_header.e_lfanew, SEEK_SET);
562
563         if (*(DWORD*)magic  == IMAGE_NT_SIGNATURE)
564           return IMAGE_NT_SIGNATURE;
565
566         if (*(WORD*)magic == IMAGE_OS2_SIGNATURE)
567         { IMAGE_OS2_HEADER      ne_header;
568           LPBYTE                pTypeInfo = (LPBYTE)-1;
569
570           if (_lread(hFile,&ne_header,sizeof(ne_header))!=sizeof(ne_header))
571             return 0;
572
573           if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE)
574             return 0;
575
576           size = ne_header.rname_tab_offset - ne_header.resource_tab_offset;
577
578           if( size > sizeof(NE_TYPEINFO) )
579           { pTypeInfo = (BYTE*)HeapAlloc( GetProcessHeap(), 0, size);
580             if( pTypeInfo ) 
581             { _llseek(hFile, mz_header.e_lfanew+ne_header.resource_tab_offset, SEEK_SET);
582               if( _lread( hFile, (char*)pTypeInfo, size) != size )
583               { HeapFree( GetProcessHeap(), 0, pTypeInfo); 
584                 pTypeInfo = NULL;
585               }
586             }
587           }
588           *retptr = pTypeInfo;
589           return IMAGE_OS2_SIGNATURE;
590         }
591         return 0; /* failed */
592 }
593
594 /*************************************************************************
595  *                      SHELL_LoadResource
596  */
597 static HGLOBAL16 SHELL_LoadResource(HINSTANCE16 hInst, HFILE hFile, NE_NAMEINFO* pNInfo, WORD sizeShift)
598 {       BYTE*  ptr;
599         HGLOBAL16 handle = DirectResAlloc16( hInst, 0x10, (DWORD)pNInfo->length << sizeShift);
600
601         TRACE_(shell)("\n");
602
603         if( (ptr = (BYTE*)GlobalLock16( handle )) )
604         { _llseek( hFile, (DWORD)pNInfo->offset << sizeShift, SEEK_SET);
605           _lread( hFile, (char*)ptr, pNInfo->length << sizeShift);
606           return handle;
607         }
608         return 0;
609 }
610
611 /*************************************************************************
612  *                      ICO_LoadIcon
613  */
614 static HGLOBAL16 ICO_LoadIcon(HINSTANCE16 hInst, HFILE hFile, LPicoICONDIRENTRY lpiIDE)
615 {       BYTE*  ptr;
616         HGLOBAL16 handle = DirectResAlloc16( hInst, 0x10, lpiIDE->dwBytesInRes);
617         TRACE_(shell)("\n");
618         if( (ptr = (BYTE*)GlobalLock16( handle )) )
619         { _llseek( hFile, lpiIDE->dwImageOffset, SEEK_SET);
620           _lread( hFile, (char*)ptr, lpiIDE->dwBytesInRes);
621           return handle;
622         }
623         return 0;
624 }
625
626 /*************************************************************************
627  *                      ICO_GetIconDirectory
628  *
629  *  Read .ico file and build phony ICONDIR struct for GetIconID
630  */
631 static HGLOBAL16 ICO_GetIconDirectory(HINSTANCE16 hInst, HFILE hFile, LPicoICONDIR* lplpiID ) 
632 { WORD    id[3];  /* idReserved, idType, idCount */
633   LPicoICONDIR  lpiID;
634   int           i;
635  
636   TRACE_(shell)("\n"); 
637   _llseek( hFile, 0, SEEK_SET );
638   if( _lread(hFile,(char*)id,sizeof(id)) != sizeof(id) ) return 0;
639
640   /* check .ICO header 
641    *
642    * - see http://www.microsoft.com/win32dev/ui/icons.htm
643    */
644
645   if( id[0] || id[1] != 1 || !id[2] ) return 0;
646
647   i = id[2]*sizeof(icoICONDIRENTRY) ;
648
649   lpiID = (LPicoICONDIR)HeapAlloc( GetProcessHeap(), 0, i + sizeof(id));
650
651   if( _lread(hFile,(char*)lpiID->idEntries,i) == i )
652   { HGLOBAL16 handle = DirectResAlloc16( hInst, 0x10,
653                                      id[2]*sizeof(CURSORICONDIRENTRY) + sizeof(id) );
654      if( handle ) 
655     { CURSORICONDIR*     lpID = (CURSORICONDIR*)GlobalLock16( handle );
656        lpID->idReserved = lpiID->idReserved = id[0];
657        lpID->idType = lpiID->idType = id[1];
658        lpID->idCount = lpiID->idCount = id[2];
659        for( i=0; i < lpiID->idCount; i++ )
660       { memcpy((void*)(lpID->idEntries + i), 
661                    (void*)(lpiID->idEntries + i), sizeof(CURSORICONDIRENTRY) - 2);
662             lpID->idEntries[i].wResId = i;
663          }
664       *lplpiID = lpiID;
665        return handle;
666      }
667   }
668   /* fail */
669
670   HeapFree( GetProcessHeap(), 0, lpiID);
671   return 0;
672 }
673
674 /*************************************************************************
675  *                      InternalExtractIcon             [SHELL.39]
676  *
677  * This abortion is called directly by Progman
678  */
679 HGLOBAL16 WINAPI InternalExtractIcon16(HINSTANCE16 hInstance,
680                                      LPCSTR lpszExeFileName, UINT16 nIconIndex, WORD n )
681 {       HGLOBAL16       hRet = 0;
682         HGLOBAL16*      RetPtr = NULL;
683         LPBYTE          pData;
684         OFSTRUCT        ofs;
685         DWORD           sig;
686         HFILE           hFile = OpenFile( lpszExeFileName, &ofs, OF_READ );
687         UINT16          iconDirCount = 0,iconCount = 0;
688         LPBYTE          peimage;
689         HANDLE  fmapping;
690         
691         TRACE_(shell)("(%04x,file %s,start %d,extract %d\n", 
692                        hInstance, lpszExeFileName, nIconIndex, n);
693
694         if( hFile == HFILE_ERROR || !n )
695           return 0;
696
697         hRet = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, sizeof(HICON16)*n);
698         RetPtr = (HICON16*)GlobalLock16(hRet);
699
700         *RetPtr = (n == 0xFFFF)? 0: 1;  /* error return values */
701
702         sig = SHELL_GetResourceTable(hFile,&pData);
703
704         if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */
705         { HICON16        hIcon = 0;
706           NE_TYPEINFO* pTInfo = (NE_TYPEINFO*)(pData + 2);
707           NE_NAMEINFO* pIconStorage = NULL;
708           NE_NAMEINFO* pIconDir = NULL;
709           LPicoICONDIR lpiID = NULL;
710  
711           if( pData == (BYTE*)-1 )
712           { hIcon = ICO_GetIconDirectory(hInstance, hFile, &lpiID);     /* check for .ICO file */
713             if( hIcon ) 
714             { iconDirCount = 1; iconCount = lpiID->idCount; 
715             }
716           }
717           else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
718           { if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON )      /* find icon directory and icon repository */
719             { iconDirCount = pTInfo->count;
720               pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
721               TRACE_(shell)("\tfound directory - %i icon families\n", iconDirCount);
722             }
723             if( pTInfo->type_id == NE_RSCTYPE_ICON ) 
724             { iconCount = pTInfo->count;
725               pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
726               TRACE_(shell)("\ttotal icons - %i\n", iconCount);
727             }
728             pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
729           }
730
731           /* load resources and create icons */
732
733           if( (pIconStorage && pIconDir) || lpiID )
734           { if( nIconIndex == (UINT16)-1 )
735             { RetPtr[0] = iconDirCount;
736             }
737             else if( nIconIndex < iconDirCount )
738             { UINT16   i, icon;
739               if( n > iconDirCount - nIconIndex ) 
740                 n = iconDirCount - nIconIndex;
741
742               for( i = nIconIndex; i < nIconIndex + n; i++ ) 
743               { /* .ICO files have only one icon directory */
744
745                 if( lpiID == NULL )
746                   hIcon = SHELL_LoadResource( hInstance, hFile, pIconDir + i, *(WORD*)pData );
747                 RetPtr[i-nIconIndex] = GetIconID16( hIcon, 3 );
748                 GlobalFree16(hIcon); 
749               }
750
751               for( icon = nIconIndex; icon < nIconIndex + n; icon++ )
752               { hIcon = 0;
753                 if( lpiID )
754                 { hIcon = ICO_LoadIcon( hInstance, hFile, lpiID->idEntries + RetPtr[icon-nIconIndex]);
755                 }
756                 else
757                 { for( i = 0; i < iconCount; i++ )
758                   { if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
759                     { hIcon = SHELL_LoadResource( hInstance, hFile, pIconStorage + i,*(WORD*)pData );
760                     }
761                   }
762                 }
763                 if( hIcon )
764                 { RetPtr[icon-nIconIndex] = LoadIconHandler16( hIcon, TRUE ); 
765                   FarSetOwner16( RetPtr[icon-nIconIndex], GetExePtr(hInstance) );
766                 }
767                 else
768                 { RetPtr[icon-nIconIndex] = 0;
769                 }
770               }
771             }
772           }
773           if( lpiID ) 
774             HeapFree( GetProcessHeap(), 0, lpiID);
775           else 
776             HeapFree( GetProcessHeap(), 0, pData);
777         } 
778
779         if( sig == IMAGE_NT_SIGNATURE)
780         { LPBYTE                idata,igdata;
781           PIMAGE_DOS_HEADER     dheader;
782           PIMAGE_NT_HEADERS     pe_header;
783           PIMAGE_SECTION_HEADER pe_sections;
784           PIMAGE_RESOURCE_DIRECTORY     rootresdir,iconresdir,icongroupresdir;
785           PIMAGE_RESOURCE_DATA_ENTRY    idataent,igdataent;
786           int                   i,j;
787           PIMAGE_RESOURCE_DIRECTORY_ENTRY       xresent;
788           CURSORICONDIR         **cids;
789         
790           fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL);
791           if (fmapping == 0) 
792           { /* FIXME, INVALID_HANDLE_VALUE? */
793             WARN_(shell)("failed to create filemap.\n");
794             hRet = 0;
795             goto end_2; /* failure */
796           }
797           peimage = MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0);
798           if (!peimage) 
799           { WARN_(shell)("failed to mmap filemap.\n");
800             hRet = 0;
801             goto end_2; /* failure */
802           }
803           dheader = (PIMAGE_DOS_HEADER)peimage;
804
805           /* it is a pe header, SHELL_GetResourceTable checked that */
806           pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew);
807
808           /* probably makes problems with short PE headers... but I haven't seen 
809           * one yet... 
810           */
811           pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header));
812           rootresdir = NULL;
813
814           for (i=0;i<pe_header->FileHeader.NumberOfSections;i++) 
815           { if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA)
816               continue;
817             /* FIXME: doesn't work when the resources are not in a seperate section */
818             if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress) 
819             { rootresdir = (PIMAGE_RESOURCE_DIRECTORY)((char*)peimage+pe_sections[i].PointerToRawData);
820               break;
821             }
822           }
823
824           if (!rootresdir) 
825           { WARN_(shell)("haven't found section for resource directory.\n");
826             goto end_4; /* failure */
827           }
828
829           icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE);
830
831           if (!icongroupresdir) 
832           { WARN_(shell)("No Icongroupresourcedirectory!\n");
833             goto end_4; /* failure */
834           }
835
836           iconDirCount = icongroupresdir->NumberOfNamedEntries+icongroupresdir->NumberOfIdEntries;
837
838           if( nIconIndex == (UINT16)-1 ) 
839           { RetPtr[0] = iconDirCount;
840             goto end_3; /* success */
841           }
842
843           if (nIconIndex >= iconDirCount) 
844           { WARN_(shell)("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount);
845             GlobalFree16(hRet);
846             goto end_4; /* failure */
847           }
848
849           cids = (CURSORICONDIR**)HeapAlloc(GetProcessHeap(),0,n*sizeof(CURSORICONDIR*));
850                 
851           /* caller just wanted the number of entries */
852           xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1);
853
854           /* assure we don't get too much ... */
855           if( n > iconDirCount - nIconIndex ) 
856           { n = iconDirCount - nIconIndex;
857           }
858
859           /* starting from specified index ... */
860           xresent = xresent+nIconIndex;
861
862           for (i=0;i<n;i++,xresent++) 
863           { CURSORICONDIR       *cid;
864             PIMAGE_RESOURCE_DIRECTORY   resdir;
865
866             /* go down this resource entry, name */
867             resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory));
868
869             /* default language (0) */
870             resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
871             igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir;
872
873             /* lookup address in mapped image for virtual address */
874             igdata = NULL;
875
876             for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) 
877             { if (igdataent->OffsetToData < pe_sections[j].VirtualAddress)
878                 continue;
879               if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
880                 continue;
881               igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
882             }
883
884             if (!igdata) 
885             { WARN_(shell)("no matching real address for icongroup!\n");
886               goto end_4;       /* failure */
887             }
888             /* found */
889             cid = (CURSORICONDIR*)igdata;
890             cids[i] = cid;
891             RetPtr[i] = LookupIconIdFromDirectoryEx(igdata,TRUE,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0);
892           }
893
894           iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE);
895
896           if (!iconresdir) 
897           { WARN_(shell)("No Iconresourcedirectory!\n");
898             goto end_4; /* failure */
899           }
900
901           for (i=0;i<n;i++) 
902           { PIMAGE_RESOURCE_DIRECTORY   xresdir;
903             xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE);
904             xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE);
905             idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir;
906             idata = NULL;
907
908             /* map virtual to address in image */
909             for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) 
910             { if (idataent->OffsetToData < pe_sections[j].VirtualAddress)
911                 continue;
912               if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData)
913                 continue;
914               idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData);
915             }
916             if (!idata) 
917             { WARN_(shell)("no matching real address found for icondata!\n");
918               RetPtr[i]=0;
919               continue;
920             }
921             RetPtr[i] = CreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0);
922           }
923           goto end_3;   /* sucess */
924         }
925         goto end_1;     /* return array with icon handles */
926
927 /* cleaning up (try & catch would be nicer) */
928 end_4:  hRet = 0;       /* failure */
929 end_3:  UnmapViewOfFile(peimage);       /* success */
930 end_2:  CloseHandle(fmapping);
931 end_1:  _lclose( hFile);
932         return hRet;
933 }
934
935 /*************************************************************************
936  *             ExtractIcon16   (SHELL.34)
937  */
938 HICON16 WINAPI ExtractIcon16( HINSTANCE16 hInstance, LPCSTR lpszExeFileName,
939         UINT16 nIconIndex )
940 {   TRACE_(shell)("\n");
941     return ExtractIconA( hInstance, lpszExeFileName, nIconIndex );
942 }
943
944 /*************************************************************************
945  *             ExtractIconEx16   (SHELL.40)
946  */
947 HICON16 WINAPI ExtractIconEx16(
948         LPCSTR lpszFile, INT16 nIconIndex, HICON16 *phiconLarge,
949         HICON16 *phiconSmall, UINT16 nIcons
950 ) {
951     HICON       *ilarge,*ismall;
952     UINT16      ret;
953     int         i;
954
955     if (phiconLarge)
956         ilarge = (HICON*)HeapAlloc(GetProcessHeap(),0,nIcons*sizeof(HICON));
957     else
958         ilarge = NULL;
959     if (phiconSmall)
960         ismall = (HICON*)HeapAlloc(GetProcessHeap(),0,nIcons*sizeof(HICON));
961     else
962         ismall = NULL;
963     ret = ExtractIconExA(lpszFile,nIconIndex,ilarge,ismall,nIcons);
964     if (ilarge) {
965         for (i=0;i<nIcons;i++)
966             phiconLarge[i]=ilarge[i];
967         HeapFree(GetProcessHeap(),0,ilarge);
968     }
969     if (ismall) {
970         for (i=0;i<nIcons;i++)
971             phiconSmall[i]=ismall[i];
972         HeapFree(GetProcessHeap(),0,ismall);
973     }
974     return ret;
975 }
976
977 /*************************************************************************
978  *                              ExtractAssociatedIcon   [SHELL.36]
979  * 
980  * Return icon for given file (either from file itself or from associated
981  * executable) and patch parameters if needed.
982  */
983 HICON WINAPI ExtractAssociatedIconA(HINSTANCE hInst, LPSTR lpIconPath, LPWORD lpiIcon)
984 {       TRACE_(shell)("\n");
985         return ExtractAssociatedIcon16(hInst,lpIconPath,lpiIcon);
986 }
987
988 HICON16 WINAPI ExtractAssociatedIcon16(HINSTANCE16 hInst, LPSTR lpIconPath, LPWORD lpiIcon)
989 {       HICON16 hIcon;
990
991         TRACE_(shell)("\n");
992
993         hIcon = ExtractIcon16(hInst, lpIconPath, *lpiIcon);
994
995         if( hIcon < 2 )
996         { if( hIcon == 1 ) /* no icons found in given file */
997           { char  tempPath[0x80];
998             UINT16  uRet = FindExecutable16(lpIconPath,NULL,tempPath);
999
1000             if( uRet > 32 && tempPath[0] )
1001             { strcpy(lpIconPath,tempPath);
1002               hIcon = ExtractIcon16(hInst, lpIconPath, *lpiIcon);
1003               if( hIcon > 2 ) 
1004                 return hIcon;
1005             }
1006             else hIcon = 0;
1007           }
1008
1009           if( hIcon == 1 ) 
1010             *lpiIcon = 2;   /* MSDOS icon - we found .exe but no icons in it */
1011           else
1012             *lpiIcon = 6;   /* generic icon - found nothing */
1013
1014           GetModuleFileName16(hInst, lpIconPath, 0x80);
1015           hIcon = LoadIcon16( hInst, MAKEINTRESOURCE16(*lpiIcon));
1016         }
1017         return hIcon;
1018 }
1019
1020 /*************************************************************************
1021  *                              FindEnvironmentString   [SHELL.38]
1022  *
1023  * Returns a pointer into the DOS environment... Ugh.
1024  */
1025 LPSTR SHELL_FindString(LPSTR lpEnv, LPCSTR entry)
1026 { UINT16 l;
1027
1028   TRACE_(shell)("\n");
1029
1030   l = strlen(entry); 
1031   for( ; *lpEnv ; lpEnv+=strlen(lpEnv)+1 )
1032   { if( lstrncmpiA(lpEnv, entry, l) ) 
1033       continue;
1034         if( !*(lpEnv+l) )
1035             return (lpEnv + l);                 /* empty entry */
1036         else if ( *(lpEnv+l)== '=' )
1037             return (lpEnv + l + 1);
1038     }
1039     return NULL;
1040 }
1041
1042 SEGPTR WINAPI FindEnvironmentString16(LPSTR str)
1043 { SEGPTR  spEnv;
1044   LPSTR lpEnv,lpString;
1045   TRACE_(shell)("\n");
1046     
1047   spEnv = GetDOSEnvironment16();
1048
1049   lpEnv = (LPSTR)PTR_SEG_TO_LIN(spEnv);
1050   lpString = (spEnv)?SHELL_FindString(lpEnv, str):NULL; 
1051
1052     if( lpString )              /*  offset should be small enough */
1053         return spEnv + (lpString - lpEnv);
1054     return (SEGPTR)NULL;
1055 }
1056
1057 /*************************************************************************
1058  *                              DoEnvironmentSubst      [SHELL.37]
1059  *
1060  * Replace %KEYWORD% in the str with the value of variable KEYWORD
1061  * from "DOS" environment.
1062  */
1063 DWORD WINAPI DoEnvironmentSubst16(LPSTR str,WORD length)
1064 {
1065   LPSTR   lpEnv = (LPSTR)PTR_SEG_TO_LIN(GetDOSEnvironment16());
1066   LPSTR   lpBuffer = (LPSTR)HeapAlloc( GetProcessHeap(), 0, length);
1067   LPSTR   lpstr = str;
1068   LPSTR   lpbstr = lpBuffer;
1069
1070   CharToOemA(str,str);
1071
1072   TRACE_(shell)("accept %s\n", str);
1073
1074   while( *lpstr && lpbstr - lpBuffer < length )
1075    {
1076      LPSTR lpend = lpstr;
1077
1078      if( *lpstr == '%' )
1079        {
1080           do { lpend++; } while( *lpend && *lpend != '%' );
1081           if( *lpend == '%' && lpend - lpstr > 1 )      /* found key */
1082             {
1083                LPSTR lpKey;
1084               *lpend = '\0';  
1085                lpKey = SHELL_FindString(lpEnv, lpstr+1);
1086                if( lpKey )                              /* found key value */
1087                  {
1088                    int l = strlen(lpKey);
1089
1090                    if( l > length - (lpbstr - lpBuffer) - 1 )
1091                      {
1092            WARN_(shell)("-- Env subst aborted - string too short\n");
1093                       *lpend = '%';
1094                        break;
1095                      }
1096                    strcpy(lpbstr, lpKey);
1097                    lpbstr += l;
1098                  }
1099                else break;
1100               *lpend = '%';
1101                lpstr = lpend + 1;
1102             }
1103           else break;                                   /* back off and whine */
1104
1105           continue;
1106        } 
1107
1108      *lpbstr++ = *lpstr++;
1109    }
1110
1111  *lpbstr = '\0';
1112   if( lpstr - str == strlen(str) )
1113     {
1114       strncpy(str, lpBuffer, length);
1115       length = 1;
1116     }
1117   else
1118       length = 0;
1119
1120   TRACE_(shell)("-- return %s\n", str);
1121
1122   OemToCharA(str,str);
1123   HeapFree( GetProcessHeap(), 0, lpBuffer);
1124
1125   /*  Return str length in the LOWORD
1126    *  and 1 in HIWORD if subst was successful.
1127    */
1128  return (DWORD)MAKELONG(strlen(str), length);
1129 }
1130
1131 /*************************************************************************
1132  *                              ShellHookProc           [SHELL.103]
1133  * System-wide WH_SHELL hook.
1134  */
1135 LRESULT WINAPI ShellHookProc16(INT16 code, WPARAM16 wParam, LPARAM lParam)
1136 {
1137     TRACE_(shell)("%i, %04x, %08x\n", code, wParam, 
1138                                                       (unsigned)lParam );
1139     if( SHELL_hHook && SHELL_hWnd )
1140     {
1141         UINT16  uMsg = 0;
1142         switch( code )
1143         {
1144             case HSHELL_WINDOWCREATED:          uMsg = uMsgWndCreated;   break;
1145             case HSHELL_WINDOWDESTROYED:        uMsg = uMsgWndDestroyed; break;
1146             case HSHELL_ACTIVATESHELLWINDOW:    uMsg = uMsgShellActivate;
1147         }
1148         PostMessage16( SHELL_hWnd, uMsg, wParam, 0 );
1149     }
1150     return CallNextHookEx16( WH_SHELL, code, wParam, lParam );
1151 }
1152
1153 /*************************************************************************
1154  *                              RegisterShellHook       [SHELL.102]
1155  */
1156 BOOL WINAPI RegisterShellHook16(HWND16 hWnd, UINT16 uAction)
1157
1158     TRACE_(shell)("%04x [%u]\n", hWnd, uAction );
1159
1160     switch( uAction )
1161     { 
1162     case 2:  /* register hWnd as a shell window */
1163         if( !SHELL_hHook )
1164         { 
1165             HMODULE16 hShell = GetModuleHandle16( "SHELL" );
1166             HOOKPROC16 hookProc = (HOOKPROC16)NE_GetEntryPoint( hShell, 103 );
1167             SHELL_hHook = SetWindowsHookEx16( WH_SHELL, hookProc, hShell, 0 );
1168             if ( SHELL_hHook )
1169             { 
1170                 uMsgWndCreated = RegisterWindowMessageA( lpstrMsgWndCreated );
1171                 uMsgWndDestroyed = RegisterWindowMessageA( lpstrMsgWndDestroyed );
1172                 uMsgShellActivate = RegisterWindowMessageA( lpstrMsgShellActivate );
1173             } 
1174             else 
1175                 WARN_(shell)("-- unable to install ShellHookProc()!\n");
1176         }
1177
1178         if ( SHELL_hHook )
1179             return ((SHELL_hWnd = hWnd) != 0);
1180         break;
1181
1182     default:
1183         WARN_(shell)("-- unknown code %i\n", uAction );
1184         SHELL_hWnd = 0; /* just in case */
1185     }
1186     return FALSE;
1187 }