2 * Shell Library Functions
12 #include "wine/winuser16.h"
13 #include "wine/winbase16.h"
14 #include "wine/shell16.h"
21 #include "cursoricon.h"
24 #include "debugtools.h"
29 DEFAULT_DEBUG_CHANNEL(shell
);
30 DECLARE_DEBUG_CHANNEL(exec
);
32 /* .ICO file ICONDIR definitions */
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
;
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
;
58 typedef struct { /* structure for dropped files */
61 BOOL16 fInNonClientArea
;
62 /* memory block with filenames follows */
63 } DROPFILESTRUCT16
, *LPDROPFILESTRUCT16
;
65 static const char* lpstrMsgWndCreated
= "OTHERWINDOWCREATED";
66 static const char* lpstrMsgWndDestroyed
= "OTHERWINDOWDESTROYED";
67 static const char* lpstrMsgShellActivate
= "ACTIVATESHELLWINDOW";
69 static HWND16 SHELL_hWnd
= 0;
70 static HHOOK SHELL_hHook
= 0;
71 static UINT16 uMsgWndCreated
= 0;
72 static UINT16 uMsgWndDestroyed
= 0;
73 static UINT16 uMsgShellActivate
= 0;
74 HINSTANCE16 SHELL_hInstance
= 0;
75 HINSTANCE SHELL_hInstance32
;
76 static int SHELL_Attach
= 0;
78 /***********************************************************************
79 * SHELL_DllEntryPoint [SHELL.entry]
81 * Initialization code for shell.dll. Automatically loads the
82 * 32-bit shell32.dll to allow thunking up to 32-bit code.
86 BOOL WINAPI
SHELL_DllEntryPoint(DWORD Reason
, HINSTANCE16 hInst
,
87 WORD ds
, WORD HeapSize
, DWORD res1
, WORD res2
)
89 TRACE("(%08lx, %04x, %04x, %04x, %08lx, %04x)\n",
90 Reason
, hInst
, ds
, HeapSize
, res1
, res2
);
94 case DLL_PROCESS_ATTACH
:
98 ERR("shell.dll instantiated twice!\n");
100 * We should return FALSE here, but that will break
101 * most apps that use CreateProcess because we do
102 * not yet support seperate address-spaces.
107 SHELL_hInstance
= hInst
;
108 if(!SHELL_hInstance32
)
110 if(!(SHELL_hInstance32
= LoadLibraryA("shell32.dll")))
112 ERR("Could not load sibling shell32.dll\n");
118 case DLL_PROCESS_DETACH
:
122 if(SHELL_hInstance32
)
123 FreeLibrary(SHELL_hInstance32
);
130 /*************************************************************************
131 * DragAcceptFiles16 [SHELL.9]
133 void WINAPI
DragAcceptFiles16(HWND16 hWnd
, BOOL16 b
)
135 DragAcceptFiles(hWnd
, b
);
138 /*************************************************************************
139 * DragQueryFile16 [SHELL.11]
141 UINT16 WINAPI
DragQueryFile16(
149 LPDROPFILESTRUCT16 lpDropFileStruct
= (LPDROPFILESTRUCT16
) GlobalLock16(hDrop
);
151 TRACE("(%04x, %x, %p, %u)\n", hDrop
,wFile
,lpszFile
,wLength
);
153 if(!lpDropFileStruct
) goto end
;
155 lpDrop
= (LPSTR
) lpDropFileStruct
+ lpDropFileStruct
->wSize
;
156 wFile
= (wFile
==0xffff) ? 0xffffffff : wFile
;
160 while (*lpDrop
++); /* skip filename */
163 i
= (wFile
== 0xFFFFFFFF) ? i
: 0;
170 if (!lpszFile
) goto end
; /* needed buffer size */
171 i
= (wLength
> i
) ? i
: wLength
;
172 lstrcpynA (lpszFile
, lpDrop
, i
);
174 GlobalUnlock16(hDrop
);
178 /*************************************************************************
179 * DragFinish16 [SHELL.12]
181 void WINAPI
DragFinish16(HDROP16 h
)
184 GlobalFree16((HGLOBAL16
)h
);
188 /*************************************************************************
189 * DragQueryPoint16 [SHELL.13]
191 BOOL16 WINAPI
DragQueryPoint16(HDROP16 hDrop
, POINT16
*p
)
193 LPDROPFILESTRUCT16 lpDropFileStruct
;
196 lpDropFileStruct
= (LPDROPFILESTRUCT16
) GlobalLock16(hDrop
);
198 memcpy(p
,&lpDropFileStruct
->ptMousePos
,sizeof(POINT16
));
199 bRet
= lpDropFileStruct
->fInNonClientArea
;
201 GlobalUnlock16(hDrop
);
205 /*************************************************************************
206 * SHELL_FindExecutable [Internal]
208 * Utility for code sharing between FindExecutable and ShellExecute
210 HINSTANCE
SHELL_FindExecutable( LPCSTR lpFile
,
213 { char *extension
= NULL
; /* pointer to file extension */
214 char tmpext
[5]; /* local copy to mung as we please */
215 char filetype
[256]; /* registry name for this filetype */
216 LONG filetypelen
=256; /* length of above */
217 char command
[256]; /* command from registry */
218 LONG commandlen
=256; /* This is the most DOS can handle :) */
219 char buffer
[256]; /* Used to GetProfileString */
220 HINSTANCE retval
=31; /* default - 'No association was found' */
221 char *tok
; /* token pointer */
222 int i
; /* random counter */
223 char xlpFile
[256] = ""; /* result of SearchPath */
225 TRACE("%s\n", (lpFile
!= NULL
?lpFile
:"-") );
227 lpResult
[0]='\0'; /* Start off with an empty return string */
229 /* trap NULL parameters on entry */
230 if (( lpFile
== NULL
) || ( lpResult
== NULL
) || ( lpOperation
== NULL
))
231 { WARN_(exec
)("(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n",
232 lpFile
, lpOperation
, lpResult
);
233 return 2; /* File not found. Close enough, I guess. */
236 if (SearchPathA( NULL
, lpFile
,".exe",sizeof(xlpFile
),xlpFile
,NULL
))
237 { TRACE("SearchPathA returned non-zero\n");
241 /* First thing we need is the file's extension */
242 extension
= strrchr( xlpFile
, '.' ); /* Assume last "." is the one; */
243 /* File->Run in progman uses */
245 TRACE("xlpFile=%s,extension=%s\n", xlpFile
, extension
);
247 if ((extension
== NULL
) || (extension
== &xlpFile
[strlen(xlpFile
)]))
248 { WARN("Returning 31 - No association\n");
249 return 31; /* no association */
252 /* Make local copy & lowercase it for reg & 'programs=' lookup */
253 lstrcpynA( tmpext
, extension
, 5 );
254 CharLowerA( tmpext
);
255 TRACE("%s file\n", tmpext
);
257 /* Three places to check: */
258 /* 1. win.ini, [windows], programs (NB no leading '.') */
259 /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
260 /* 3. win.ini, [extensions], extension (NB no leading '.' */
261 /* All I know of the order is that registry is checked before */
262 /* extensions; however, it'd make sense to check the programs */
263 /* section first, so that's what happens here. */
265 /* See if it's a program - if GetProfileString fails, we skip this
266 * section. Actually, if GetProfileString fails, we've probably
267 * got a lot more to worry about than running a program... */
268 if ( GetProfileStringA("windows", "programs", "exe pif bat com",
269 buffer
, sizeof(buffer
)) > 0 )
270 { for (i
=0;i
<strlen(buffer
); i
++) buffer
[i
]=tolower(buffer
[i
]);
272 tok
= strtok(buffer
, " \t"); /* ? */
275 if (strcmp(tok
, &tmpext
[1])==0) /* have to skip the leading "." */
277 strcpy(lpResult
, xlpFile
);
278 /* Need to perhaps check that the file has a path
280 TRACE("found %s\n", lpResult
);
283 /* Greater than 32 to indicate success FIXME According to the
284 * docs, I should be returning a handle for the
285 * executable. Does this mean I'm supposed to open the
286 * executable file or something? More RTFM, I guess... */
288 tok
=strtok(NULL
, " \t");
293 if (RegQueryValue16( HKEY_CLASSES_ROOT
, tmpext
, filetype
,
294 &filetypelen
) == ERROR_SUCCESS
)
296 filetype
[filetypelen
]='\0';
297 TRACE("File type: %s\n", filetype
);
299 /* Looking for ...buffer\shell\lpOperation\command */
300 strcat( filetype
, "\\shell\\" );
301 strcat( filetype
, lpOperation
);
302 strcat( filetype
, "\\command" );
304 if (RegQueryValue16( HKEY_CLASSES_ROOT
, filetype
, command
,
305 &commandlen
) == ERROR_SUCCESS
)
312 /* Get the parameters needed by the application
313 from the associated ddeexec key */
314 tmp
= strstr(filetype
,"command");
316 strcat(filetype
,"ddeexec");
318 if(RegQueryValue16( HKEY_CLASSES_ROOT
, filetype
, param
,¶mlen
) == ERROR_SUCCESS
)
321 strcat(command
,param
);
322 commandlen
+= paramlen
;
325 /* Is there a replace() function anywhere? */
326 command
[commandlen
]='\0';
327 strcpy( lpResult
, command
);
328 tok
=strstr( lpResult
, "%1" );
331 tok
[0]='\0'; /* truncate string at the percent */
332 strcat( lpResult
, xlpFile
); /* what if no dir in xlpFile? */
333 tok
=strstr( command
, "%1" );
334 if ((tok
!=NULL
) && (strlen(tok
)>2))
336 strcat( lpResult
, &tok
[2] );
339 retval
=33; /* FIXME see above */
342 else /* Check win.ini */
344 /* Toss the leading dot */
346 if ( GetProfileStringA( "extensions", extension
, "", command
,
347 sizeof(command
)) > 0)
349 if (strlen(command
)!=0)
351 strcpy( lpResult
, command
);
352 tok
=strstr( lpResult
, "^" ); /* should be ^.extension? */
356 strcat( lpResult
, xlpFile
); /* what if no dir in xlpFile? */
357 tok
=strstr( command
, "^" ); /* see above */
358 if ((tok
!= NULL
) && (strlen(tok
)>5))
360 strcat( lpResult
, &tok
[5]);
363 retval
=33; /* FIXME - see above */
368 TRACE("returning %s\n", lpResult
);
372 /*************************************************************************
373 * ShellExecute16 [SHELL.20]
375 HINSTANCE16 WINAPI
ShellExecute16( HWND16 hWnd
, LPCSTR lpOperation
,
376 LPCSTR lpFile
, LPCSTR lpParameters
,
377 LPCSTR lpDirectory
, INT16 iShowCmd
)
378 { HINSTANCE16 retval
=31;
382 TRACE("(%04x,'%s','%s','%s','%s',%x)\n",
383 hWnd
, lpOperation
? lpOperation
:"<null>", lpFile
? lpFile
:"<null>",
384 lpParameters
? lpParameters
: "<null>",
385 lpDirectory
? lpDirectory
: "<null>", iShowCmd
);
387 if (lpFile
==NULL
) return 0; /* should not happen */
388 if (lpOperation
==NULL
) /* default is open */
392 { GetCurrentDirectoryA( sizeof(old_dir
), old_dir
);
393 SetCurrentDirectoryA( lpDirectory
);
396 /* First try to execute lpFile with lpParameters directly */
398 strcat(cmd
,lpParameters
? lpParameters
: "");
400 retval
= WinExec16( cmd
, iShowCmd
);
402 /* Unable to execute lpFile directly
403 Check if we can match an application to lpFile */
407 retval
= SHELL_FindExecutable( lpFile
, lpOperation
, cmd
);
409 if (retval
> 32) /* Found */
414 strcat(cmd
,lpParameters
);
416 retval
= WinExec16( cmd
, iShowCmd
);
418 else if(PathIsURLA((LPSTR
)lpFile
)) /* File not found, check for URL */
420 char lpstrProtocol
[256];
425 lpstrRes
= strchr(lpFile
,':');
426 iSize
= lpstrRes
- lpFile
;
428 /* Looking for ...protocol\shell\lpOperation\command */
429 strncpy(lpstrProtocol
,lpFile
,iSize
);
430 lpstrProtocol
[iSize
]='\0';
431 strcat( lpstrProtocol
, "\\shell\\" );
432 strcat( lpstrProtocol
, lpOperation
);
433 strcat( lpstrProtocol
, "\\command" );
435 /* Remove File Protocol from lpFile */
436 /* In the case file://path/file */
437 if(!strncasecmp(lpFile
,"file",iSize
))
440 while(*lpFile
== ':') lpFile
++;
444 /* Get the application for the protocol and execute it */
445 if (RegQueryValue16( HKEY_CLASSES_ROOT
, lpstrProtocol
, cmd
,
446 &cmdlen
) == ERROR_SUCCESS
)
450 char param
[256] = "";
453 /* Get the parameters needed by the application
454 from the associated ddeexec key */
455 tmp
= strstr(lpstrProtocol
,"command");
457 strcat(lpstrProtocol
,"ddeexec");
459 if(RegQueryValue16( HKEY_CLASSES_ROOT
, lpstrProtocol
, param
,¶mlen
) == ERROR_SUCCESS
)
466 /* Is there a replace() function anywhere? */
469 tok
=strstr( cmd
, "%1" );
472 tok
[0]='\0'; /* truncate string at the percent */
473 strcat( cmd
, lpFile
); /* what if no dir in xlpFile? */
474 tok
=strstr( cmd
, "%1" );
475 if ((tok
!=NULL
) && (strlen(tok
)>2))
477 strcat( cmd
, &tok
[2] );
481 retval
= WinExec16( cmd
, iShowCmd
);
484 /* Check if file specified is in the form www.??????.*** */
485 else if(!strncasecmp(lpFile
,"www",3))
487 /* if so, append lpFile http:// and call ShellExecute */
488 char lpstrTmpFile
[256] = "http://" ;
489 strcat(lpstrTmpFile
,lpFile
);
490 retval
= ShellExecuteA(hWnd
,lpOperation
,lpstrTmpFile
,NULL
,NULL
,0);
494 SetCurrentDirectoryA( old_dir
);
498 /*************************************************************************
499 * FindExecutable16 (SHELL.21)
501 HINSTANCE16 WINAPI
FindExecutable16( LPCSTR lpFile
, LPCSTR lpDirectory
,
503 { return (HINSTANCE16
)FindExecutableA( lpFile
, lpDirectory
, lpResult
);
507 /*************************************************************************
508 * AboutDlgProc16 (SHELL.33)
510 BOOL16 WINAPI
AboutDlgProc16( HWND16 hWnd
, UINT16 msg
, WPARAM16 wParam
,
512 { return AboutDlgProc( hWnd
, msg
, wParam
, lParam
);
516 /*************************************************************************
517 * ShellAbout16 (SHELL.22)
519 BOOL16 WINAPI
ShellAbout16( HWND16 hWnd
, LPCSTR szApp
, LPCSTR szOtherStuff
,
521 { return ShellAboutA( hWnd
, szApp
, szOtherStuff
, hIcon
);
524 /*************************************************************************
525 * SHELL_GetResourceTable
527 static DWORD
SHELL_GetResourceTable(HFILE hFile
,LPBYTE
*retptr
)
528 { IMAGE_DOS_HEADER mz_header
;
535 _llseek( hFile
, 0, SEEK_SET
);
536 if ((_lread(hFile
,&mz_header
,sizeof(mz_header
)) != sizeof(mz_header
)) || (mz_header
.e_magic
!= IMAGE_DOS_SIGNATURE
))
538 if (mz_header
.e_cblp
== 1)
539 { /* ICONHEADER.idType, must be 1 */
540 *retptr
= (LPBYTE
)-1;
544 return 0; /* failed */
546 _llseek( hFile
, mz_header
.e_lfanew
, SEEK_SET
);
548 if (_lread( hFile
, magic
, sizeof(magic
) ) != sizeof(magic
))
551 _llseek( hFile
, mz_header
.e_lfanew
, SEEK_SET
);
553 if (*(DWORD
*)magic
== IMAGE_NT_SIGNATURE
)
554 return IMAGE_NT_SIGNATURE
;
556 if (*(WORD
*)magic
== IMAGE_OS2_SIGNATURE
)
557 { IMAGE_OS2_HEADER ne_header
;
558 LPBYTE pTypeInfo
= (LPBYTE
)-1;
560 if (_lread(hFile
,&ne_header
,sizeof(ne_header
))!=sizeof(ne_header
))
563 if (ne_header
.ne_magic
!= IMAGE_OS2_SIGNATURE
)
566 size
= ne_header
.ne_restab
- ne_header
.ne_rsrctab
;
568 if( size
> sizeof(NE_TYPEINFO
) )
569 { pTypeInfo
= (BYTE
*)HeapAlloc( GetProcessHeap(), 0, size
);
571 { _llseek(hFile
, mz_header
.e_lfanew
+ne_header
.ne_rsrctab
, SEEK_SET
);
572 if( _lread( hFile
, (char*)pTypeInfo
, size
) != size
)
573 { HeapFree( GetProcessHeap(), 0, pTypeInfo
);
579 return IMAGE_OS2_SIGNATURE
;
581 return 0; /* failed */
584 /*************************************************************************
587 static HGLOBAL16
SHELL_LoadResource(HINSTANCE16 hInst
, HFILE hFile
, NE_NAMEINFO
* pNInfo
, WORD sizeShift
)
589 HGLOBAL16 handle
= DirectResAlloc16( hInst
, 0x10, (DWORD
)pNInfo
->length
<< sizeShift
);
593 if( (ptr
= (BYTE
*)GlobalLock16( handle
)) )
594 { _llseek( hFile
, (DWORD
)pNInfo
->offset
<< sizeShift
, SEEK_SET
);
595 _lread( hFile
, (char*)ptr
, pNInfo
->length
<< sizeShift
);
601 /*************************************************************************
604 static HGLOBAL16
ICO_LoadIcon(HINSTANCE16 hInst
, HFILE hFile
, LPicoICONDIRENTRY lpiIDE
)
606 HGLOBAL16 handle
= DirectResAlloc16( hInst
, 0x10, lpiIDE
->dwBytesInRes
);
608 if( (ptr
= (BYTE
*)GlobalLock16( handle
)) )
609 { _llseek( hFile
, lpiIDE
->dwImageOffset
, SEEK_SET
);
610 _lread( hFile
, (char*)ptr
, lpiIDE
->dwBytesInRes
);
616 /*************************************************************************
617 * ICO_GetIconDirectory
619 * Read .ico file and build phony ICONDIR struct for GetIconID
621 static HGLOBAL16
ICO_GetIconDirectory(HINSTANCE16 hInst
, HFILE hFile
, LPicoICONDIR
* lplpiID
)
622 { WORD id
[3]; /* idReserved, idType, idCount */
627 _llseek( hFile
, 0, SEEK_SET
);
628 if( _lread(hFile
,(char*)id
,sizeof(id
)) != sizeof(id
) ) return 0;
632 * - see http://www.microsoft.com/win32dev/ui/icons.htm
635 if( id
[0] || id
[1] != 1 || !id
[2] ) return 0;
637 i
= id
[2]*sizeof(icoICONDIRENTRY
) ;
639 lpiID
= (LPicoICONDIR
)HeapAlloc( GetProcessHeap(), 0, i
+ sizeof(id
));
641 if( _lread(hFile
,(char*)lpiID
->idEntries
,i
) == i
)
642 { HGLOBAL16 handle
= DirectResAlloc16( hInst
, 0x10,
643 id
[2]*sizeof(CURSORICONDIRENTRY
) + sizeof(id
) );
645 { CURSORICONDIR
* lpID
= (CURSORICONDIR
*)GlobalLock16( handle
);
646 lpID
->idReserved
= lpiID
->idReserved
= id
[0];
647 lpID
->idType
= lpiID
->idType
= id
[1];
648 lpID
->idCount
= lpiID
->idCount
= id
[2];
649 for( i
=0; i
< lpiID
->idCount
; i
++ )
650 { memcpy((void*)(lpID
->idEntries
+ i
),
651 (void*)(lpiID
->idEntries
+ i
), sizeof(CURSORICONDIRENTRY
) - 2);
652 lpID
->idEntries
[i
].wResId
= i
;
660 HeapFree( GetProcessHeap(), 0, lpiID
);
664 /*************************************************************************
665 * InternalExtractIcon [SHELL.39]
667 * This abortion is called directly by Progman
669 HGLOBAL16 WINAPI
InternalExtractIcon16(HINSTANCE16 hInstance
,
670 LPCSTR lpszExeFileName
, UINT16 nIconIndex
, WORD n
)
671 { HGLOBAL16 hRet
= 0;
672 HGLOBAL16
* RetPtr
= NULL
;
677 UINT16 iconDirCount
= 0,iconCount
= 0;
681 TRACE("(%04x,file %s,start %d,extract %d\n",
682 hInstance
, lpszExeFileName
, nIconIndex
, n
);
687 hFile
= OpenFile( lpszExeFileName
, &ofs
, OF_READ
);
689 hRet
= GlobalAlloc16( GMEM_FIXED
| GMEM_ZEROINIT
, sizeof(HICON16
)*n
);
690 RetPtr
= (HICON16
*)GlobalLock16(hRet
);
692 if (hFile
== HFILE_ERROR
)
693 { /* not found - load from builtin module if available */
694 HINSTANCE hInst
= (HINSTANCE
)LoadLibrary16(lpszExeFileName
);
696 if (hInst
< 32) /* hmm, no Win16 module - try Win32 :-) */
697 hInst
= LoadLibraryA(lpszExeFileName
);
701 for (i
=nIconIndex
; i
< nIconIndex
+ n
; i
++)
702 RetPtr
[i
-nIconIndex
] =
703 (HICON16
)LoadIconA(hInst
, (LPCSTR
)(DWORD
)i
);
710 *RetPtr
= (n
== 0xFFFF)? 0 : 1; /* error return values */
712 sig
= SHELL_GetResourceTable(hFile
,&pData
);
714 if( sig
==IMAGE_OS2_SIGNATURE
|| sig
==1 ) /* .ICO file */
716 NE_TYPEINFO
* pTInfo
= (NE_TYPEINFO
*)(pData
+ 2);
717 NE_NAMEINFO
* pIconStorage
= NULL
;
718 NE_NAMEINFO
* pIconDir
= NULL
;
719 LPicoICONDIR lpiID
= NULL
;
721 if( pData
== (BYTE
*)-1 )
722 { hIcon
= ICO_GetIconDirectory(hInstance
, hFile
, &lpiID
); /* check for .ICO file */
724 { iconDirCount
= 1; iconCount
= lpiID
->idCount
;
727 else while( pTInfo
->type_id
&& !(pIconStorage
&& pIconDir
) )
728 { if( pTInfo
->type_id
== NE_RSCTYPE_GROUP_ICON
) /* find icon directory and icon repository */
729 { iconDirCount
= pTInfo
->count
;
730 pIconDir
= ((NE_NAMEINFO
*)(pTInfo
+ 1));
731 TRACE("\tfound directory - %i icon families\n", iconDirCount
);
733 if( pTInfo
->type_id
== NE_RSCTYPE_ICON
)
734 { iconCount
= pTInfo
->count
;
735 pIconStorage
= ((NE_NAMEINFO
*)(pTInfo
+ 1));
736 TRACE("\ttotal icons - %i\n", iconCount
);
738 pTInfo
= (NE_TYPEINFO
*)((char*)(pTInfo
+1)+pTInfo
->count
*sizeof(NE_NAMEINFO
));
741 /* load resources and create icons */
743 if( (pIconStorage
&& pIconDir
) || lpiID
)
744 { if( nIconIndex
== (UINT16
)-1 )
745 { RetPtr
[0] = iconDirCount
;
747 else if( nIconIndex
< iconDirCount
)
749 if( n
> iconDirCount
- nIconIndex
)
750 n
= iconDirCount
- nIconIndex
;
752 for( i
= nIconIndex
; i
< nIconIndex
+ n
; i
++ )
753 { /* .ICO files have only one icon directory */
756 hIcon
= SHELL_LoadResource( hInstance
, hFile
, pIconDir
+ i
, *(WORD
*)pData
);
757 RetPtr
[i
-nIconIndex
] = GetIconID16( hIcon
, 3 );
761 for( icon
= nIconIndex
; icon
< nIconIndex
+ n
; icon
++ )
764 { hIcon
= ICO_LoadIcon( hInstance
, hFile
, lpiID
->idEntries
+ RetPtr
[icon
-nIconIndex
]);
767 { for( i
= 0; i
< iconCount
; i
++ )
768 { if( pIconStorage
[i
].id
== (RetPtr
[icon
-nIconIndex
] | 0x8000) )
769 { hIcon
= SHELL_LoadResource( hInstance
, hFile
, pIconStorage
+ i
,*(WORD
*)pData
);
774 { RetPtr
[icon
-nIconIndex
] = LoadIconHandler16( hIcon
, TRUE
);
775 FarSetOwner16( RetPtr
[icon
-nIconIndex
], GetExePtr(hInstance
) );
778 { RetPtr
[icon
-nIconIndex
] = 0;
784 HeapFree( GetProcessHeap(), 0, lpiID
);
786 HeapFree( GetProcessHeap(), 0, pData
);
789 if( sig
== IMAGE_NT_SIGNATURE
)
790 { LPBYTE idata
,igdata
;
791 PIMAGE_DOS_HEADER dheader
;
792 PIMAGE_NT_HEADERS pe_header
;
793 PIMAGE_SECTION_HEADER pe_sections
;
794 const IMAGE_RESOURCE_DIRECTORY
*rootresdir
,*iconresdir
,*icongroupresdir
;
795 const IMAGE_RESOURCE_DATA_ENTRY
*idataent
,*igdataent
;
797 const IMAGE_RESOURCE_DIRECTORY_ENTRY
*xresent
;
798 CURSORICONDIR
**cids
;
800 fmapping
= CreateFileMappingA(hFile
,NULL
,PAGE_READONLY
|SEC_COMMIT
,0,0,NULL
);
802 { /* FIXME, INVALID_HANDLE_VALUE? */
803 WARN("failed to create filemap.\n");
805 goto end_2
; /* failure */
807 peimage
= MapViewOfFile(fmapping
,FILE_MAP_READ
,0,0,0);
809 { WARN("failed to mmap filemap.\n");
811 goto end_2
; /* failure */
813 dheader
= (PIMAGE_DOS_HEADER
)peimage
;
815 /* it is a pe header, SHELL_GetResourceTable checked that */
816 pe_header
= (PIMAGE_NT_HEADERS
)(peimage
+dheader
->e_lfanew
);
818 /* probably makes problems with short PE headers... but I haven't seen
821 pe_sections
= (PIMAGE_SECTION_HEADER
)(((char*)pe_header
)+sizeof(*pe_header
));
824 for (i
=0;i
<pe_header
->FileHeader
.NumberOfSections
;i
++)
825 { if (pe_sections
[i
].Characteristics
& IMAGE_SCN_CNT_UNINITIALIZED_DATA
)
827 /* FIXME: doesn't work when the resources are not in a seperate section */
828 if (pe_sections
[i
].VirtualAddress
== pe_header
->OptionalHeader
.DataDirectory
[IMAGE_DIRECTORY_ENTRY_RESOURCE
].VirtualAddress
)
829 { rootresdir
= (PIMAGE_RESOURCE_DIRECTORY
)((char*)peimage
+pe_sections
[i
].PointerToRawData
);
835 { WARN("haven't found section for resource directory.\n");
836 goto end_4
; /* failure */
839 icongroupresdir
= GetResDirEntryW(rootresdir
,RT_GROUP_ICONW
, rootresdir
,FALSE
);
841 if (!icongroupresdir
)
842 { WARN("No Icongroupresourcedirectory!\n");
843 goto end_4
; /* failure */
846 iconDirCount
= icongroupresdir
->NumberOfNamedEntries
+icongroupresdir
->NumberOfIdEntries
;
848 if( nIconIndex
== (UINT16
)-1 )
849 { RetPtr
[0] = iconDirCount
;
850 goto end_3
; /* success */
853 if (nIconIndex
>= iconDirCount
)
854 { WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex
,iconDirCount
);
856 goto end_4
; /* failure */
859 cids
= (CURSORICONDIR
**)HeapAlloc(GetProcessHeap(),0,n
*sizeof(CURSORICONDIR
*));
861 /* caller just wanted the number of entries */
862 xresent
= (PIMAGE_RESOURCE_DIRECTORY_ENTRY
)(icongroupresdir
+1);
864 /* assure we don't get too much ... */
865 if( n
> iconDirCount
- nIconIndex
)
866 { n
= iconDirCount
- nIconIndex
;
869 /* starting from specified index ... */
870 xresent
= xresent
+nIconIndex
;
872 for (i
=0;i
<n
;i
++,xresent
++)
875 const IMAGE_RESOURCE_DIRECTORY
*resdir
;
877 /* go down this resource entry, name */
878 resdir
= (PIMAGE_RESOURCE_DIRECTORY
)((DWORD
)rootresdir
+(xresent
->u2
.s
.OffsetToDirectory
));
880 /* default language (0) */
881 resdir
= GetResDirEntryW(resdir
,(LPWSTR
)0,rootresdir
,TRUE
);
882 igdataent
= (PIMAGE_RESOURCE_DATA_ENTRY
)resdir
;
884 /* lookup address in mapped image for virtual address */
887 for (j
=0;j
<pe_header
->FileHeader
.NumberOfSections
;j
++)
888 { if (igdataent
->OffsetToData
< pe_sections
[j
].VirtualAddress
)
890 if (igdataent
->OffsetToData
+igdataent
->Size
> pe_sections
[j
].VirtualAddress
+pe_sections
[j
].SizeOfRawData
)
892 igdata
= peimage
+(igdataent
->OffsetToData
-pe_sections
[j
].VirtualAddress
+pe_sections
[j
].PointerToRawData
);
896 { WARN("no matching real address for icongroup!\n");
897 goto end_4
; /* failure */
900 cid
= (CURSORICONDIR
*)igdata
;
902 RetPtr
[i
] = LookupIconIdFromDirectoryEx(igdata
,TRUE
,GetSystemMetrics(SM_CXICON
),GetSystemMetrics(SM_CYICON
),0);
905 iconresdir
=GetResDirEntryW(rootresdir
,RT_ICONW
,rootresdir
,FALSE
);
908 { WARN("No Iconresourcedirectory!\n");
909 goto end_4
; /* failure */
914 const IMAGE_RESOURCE_DIRECTORY
*xresdir
;
915 xresdir
= GetResDirEntryW(iconresdir
,(LPWSTR
)(DWORD
)RetPtr
[i
],rootresdir
,FALSE
);
916 xresdir
= GetResDirEntryW(xresdir
,(LPWSTR
)0,rootresdir
,TRUE
);
917 idataent
= (PIMAGE_RESOURCE_DATA_ENTRY
)xresdir
;
920 /* map virtual to address in image */
921 for (j
=0;j
<pe_header
->FileHeader
.NumberOfSections
;j
++)
922 { if (idataent
->OffsetToData
< pe_sections
[j
].VirtualAddress
)
924 if (idataent
->OffsetToData
+idataent
->Size
> pe_sections
[j
].VirtualAddress
+pe_sections
[j
].SizeOfRawData
)
926 idata
= peimage
+(idataent
->OffsetToData
-pe_sections
[j
].VirtualAddress
+pe_sections
[j
].PointerToRawData
);
929 { WARN("no matching real address found for icondata!\n");
933 RetPtr
[i
] = CreateIconFromResourceEx(idata
,idataent
->Size
,TRUE
,0x00030000,GetSystemMetrics(SM_CXICON
),GetSystemMetrics(SM_CYICON
),0);
935 goto end_3
; /* success */
937 goto end_1
; /* return array with icon handles */
939 /* cleaning up (try & catch would be nicer) */
940 end_4
: hRet
= 0; /* failure */
941 end_3
: UnmapViewOfFile(peimage
); /* success */
942 end_2
: CloseHandle(fmapping
);
943 end_1
: _lclose( hFile
);
947 /*************************************************************************
948 * ExtractIcon16 (SHELL.34)
950 HICON16 WINAPI
ExtractIcon16( HINSTANCE16 hInstance
, LPCSTR lpszExeFileName
,
953 return ExtractIconA( hInstance
, lpszExeFileName
, nIconIndex
);
956 /*************************************************************************
957 * ExtractIconEx16 (SHELL.40)
959 HICON16 WINAPI
ExtractIconEx16(
960 LPCSTR lpszFile
, INT16 nIconIndex
, HICON16
*phiconLarge
,
961 HICON16
*phiconSmall
, UINT16 nIcons
963 HICON
*ilarge
,*ismall
;
968 ilarge
= (HICON
*)HeapAlloc(GetProcessHeap(),0,nIcons
*sizeof(HICON
));
972 ismall
= (HICON
*)HeapAlloc(GetProcessHeap(),0,nIcons
*sizeof(HICON
));
975 ret
= ExtractIconExA(lpszFile
,nIconIndex
,ilarge
,ismall
,nIcons
);
977 for (i
=0;i
<nIcons
;i
++)
978 phiconLarge
[i
]=ilarge
[i
];
979 HeapFree(GetProcessHeap(),0,ilarge
);
982 for (i
=0;i
<nIcons
;i
++)
983 phiconSmall
[i
]=ismall
[i
];
984 HeapFree(GetProcessHeap(),0,ismall
);
989 /*************************************************************************
990 * ExtractAssociatedIcon [SHELL.36]
992 * Return icon for given file (either from file itself or from associated
993 * executable) and patch parameters if needed.
995 HICON16 WINAPI
ExtractAssociatedIcon16(HINSTANCE16 hInst
, LPSTR lpIconPath
, LPWORD lpiIcon
)
1002 lpiIcon
= &wDummyIcon
;
1004 hIcon
= ExtractIcon16(hInst
, lpIconPath
, *lpiIcon
);
1007 { if( hIcon
== 1 ) /* no icons found in given file */
1008 { char tempPath
[0x80];
1009 UINT16 uRet
= FindExecutable16(lpIconPath
,NULL
,tempPath
);
1011 if( uRet
> 32 && tempPath
[0] )
1012 { strcpy(lpIconPath
,tempPath
);
1013 hIcon
= ExtractIcon16(hInst
, lpIconPath
, *lpiIcon
);
1021 *lpiIcon
= 2; /* MSDOS icon - we found .exe but no icons in it */
1023 *lpiIcon
= 6; /* generic icon - found nothing */
1025 GetModuleFileName16(hInst
, lpIconPath
, 0x80);
1026 hIcon
= LoadIcon16( hInst
, MAKEINTRESOURCE16(*lpiIcon
));
1031 /*************************************************************************
1032 * ExtractAssociatedIconA
1034 * Return icon for given file (either from file itself or from associated
1035 * executable) and patch parameters if needed.
1037 HICON WINAPI
ExtractAssociatedIconA(HINSTANCE hInst
, LPSTR lpIconPath
, LPWORD lpiIcon
)
1039 return ExtractAssociatedIcon16(hInst
,lpIconPath
,lpiIcon
);
1042 /*************************************************************************
1043 * FindEnvironmentString [SHELL.38]
1045 * Returns a pointer into the DOS environment... Ugh.
1047 LPSTR
SHELL_FindString(LPSTR lpEnv
, LPCSTR entry
)
1053 for( ; *lpEnv
; lpEnv
+=strlen(lpEnv
)+1 )
1054 { if( strncasecmp(lpEnv
, entry
, l
) )
1057 return (lpEnv
+ l
); /* empty entry */
1058 else if ( *(lpEnv
+l
)== '=' )
1059 return (lpEnv
+ l
+ 1);
1064 SEGPTR WINAPI
FindEnvironmentString16(LPSTR str
)
1066 LPSTR lpEnv
,lpString
;
1069 spEnv
= GetDOSEnvironment16();
1071 lpEnv
= (LPSTR
)PTR_SEG_TO_LIN(spEnv
);
1072 lpString
= (spEnv
)?SHELL_FindString(lpEnv
, str
):NULL
;
1074 if( lpString
) /* offset should be small enough */
1075 return spEnv
+ (lpString
- lpEnv
);
1076 return (SEGPTR
)NULL
;
1079 /*************************************************************************
1080 * DoEnvironmentSubst [SHELL.37]
1082 * Replace %KEYWORD% in the str with the value of variable KEYWORD
1083 * from "DOS" environment.
1085 DWORD WINAPI
DoEnvironmentSubst16(LPSTR str
,WORD length
)
1087 LPSTR lpEnv
= (LPSTR
)PTR_SEG_TO_LIN(GetDOSEnvironment16());
1088 LPSTR lpBuffer
= (LPSTR
)HeapAlloc( GetProcessHeap(), 0, length
);
1090 LPSTR lpbstr
= lpBuffer
;
1092 CharToOemA(str
,str
);
1094 TRACE("accept %s\n", str
);
1096 while( *lpstr
&& lpbstr
- lpBuffer
< length
)
1098 LPSTR lpend
= lpstr
;
1102 do { lpend
++; } while( *lpend
&& *lpend
!= '%' );
1103 if( *lpend
== '%' && lpend
- lpstr
> 1 ) /* found key */
1107 lpKey
= SHELL_FindString(lpEnv
, lpstr
+1);
1108 if( lpKey
) /* found key value */
1110 int l
= strlen(lpKey
);
1112 if( l
> length
- (lpbstr
- lpBuffer
) - 1 )
1114 WARN("-- Env subst aborted - string too short\n");
1118 strcpy(lpbstr
, lpKey
);
1125 else break; /* back off and whine */
1130 *lpbstr
++ = *lpstr
++;
1134 if( lpstr
- str
== strlen(str
) )
1136 strncpy(str
, lpBuffer
, length
);
1142 TRACE("-- return %s\n", str
);
1144 OemToCharA(str
,str
);
1145 HeapFree( GetProcessHeap(), 0, lpBuffer
);
1147 /* Return str length in the LOWORD
1148 * and 1 in HIWORD if subst was successful.
1150 return (DWORD
)MAKELONG(strlen(str
), length
);
1153 /*************************************************************************
1154 * ShellHookProc [SHELL.103]
1155 * System-wide WH_SHELL hook.
1157 LRESULT WINAPI
ShellHookProc16(INT16 code
, WPARAM16 wParam
, LPARAM lParam
)
1159 TRACE("%i, %04x, %08x\n", code
, wParam
,
1161 if( SHELL_hHook
&& SHELL_hWnd
)
1166 case HSHELL_WINDOWCREATED
: uMsg
= uMsgWndCreated
; break;
1167 case HSHELL_WINDOWDESTROYED
: uMsg
= uMsgWndDestroyed
; break;
1168 case HSHELL_ACTIVATESHELLWINDOW
: uMsg
= uMsgShellActivate
;
1170 PostMessage16( SHELL_hWnd
, uMsg
, wParam
, 0 );
1172 return CallNextHookEx16( WH_SHELL
, code
, wParam
, lParam
);
1175 /*************************************************************************
1176 * RegisterShellHook [SHELL.102]
1178 BOOL WINAPI
RegisterShellHook16(HWND16 hWnd
, UINT16 uAction
)
1180 TRACE("%04x [%u]\n", hWnd
, uAction
);
1184 case 2: /* register hWnd as a shell window */
1187 HMODULE16 hShell
= GetModuleHandle16( "SHELL" );
1188 HOOKPROC16 hookProc
= (HOOKPROC16
)NE_GetEntryPoint( hShell
, 103 );
1189 SHELL_hHook
= SetWindowsHookEx16( WH_SHELL
, hookProc
, hShell
, 0 );
1192 uMsgWndCreated
= RegisterWindowMessageA( lpstrMsgWndCreated
);
1193 uMsgWndDestroyed
= RegisterWindowMessageA( lpstrMsgWndDestroyed
);
1194 uMsgShellActivate
= RegisterWindowMessageA( lpstrMsgShellActivate
);
1197 WARN("-- unable to install ShellHookProc()!\n");
1201 return ((SHELL_hWnd
= hWnd
) != 0);
1205 WARN("-- unknown code %i\n", uAction
);
1206 SHELL_hWnd
= 0; /* just in case */