Release 961208
[wine.git] / misc / shell.c
blob2f9cc8b218f235de64cfa806d7ed19fe0c78dbb3
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 "file.h"
11 #include "shell.h"
12 #include "module.h"
13 #include "neexe.h"
14 #include "resource.h"
15 #include "dlgs.h"
16 #include "win.h"
17 #include "cursoricon.h"
18 #include "stddebug.h"
19 #include "debug.h"
20 #include "xmalloc.h"
21 #include "winreg.h"
23 /* .ICO file ICONDIR definitions */
25 #pragma pack(1)
27 typedef struct
29 BYTE bWidth; /* Width, in pixels, of the image */
30 BYTE bHeight; /* Height, in pixels, of the image */
31 BYTE bColorCount; /* Number of colors in image (0 if >=8bpp) */
32 BYTE bReserved; /* Reserved ( must be 0) */
33 WORD wPlanes; /* Color Planes */
34 WORD wBitCount; /* Bits per pixel */
35 DWORD dwBytesInRes; /* How many bytes in this resource? */
36 DWORD dwImageOffset; /* Where in the file is this image? */
37 } icoICONDIRENTRY, *LPicoICONDIRENTRY;
39 typedef struct
41 WORD idReserved; /* Reserved (must be 0) */
42 WORD idType; /* Resource Type (1 for icons) */
43 WORD idCount; /* How many images? */
44 icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */
45 } icoICONDIR, *LPicoICONDIR;
47 #pragma pack(4)
49 extern HGLOBAL16 CURSORICON_LoadHandler( HGLOBAL16, HINSTANCE16, BOOL);
50 extern WORD GetIconID( HGLOBAL16 hResource, DWORD resType );
52 /*************************************************************************
53 * DragAcceptFiles [SHELL.9]
55 void DragAcceptFiles(HWND hWnd, BOOL b)
57 WND* wnd = WIN_FindWndPtr(hWnd);
59 if( wnd )
60 wnd->dwExStyle = b? wnd->dwExStyle | WS_EX_ACCEPTFILES
61 : wnd->dwExStyle & ~WS_EX_ACCEPTFILES;
65 /*************************************************************************
66 * DragQueryFile [SHELL.11]
68 UINT DragQueryFile(HDROP16 hDrop, WORD wFile, LPSTR lpszFile, WORD wLength)
70 /* hDrop is a global memory block allocated with GMEM_SHARE
71 * with DROPFILESTRUCT as a header and filenames following
72 * it, zero length filename is in the end */
74 LPDROPFILESTRUCT lpDropFileStruct;
75 LPSTR lpCurrent;
76 WORD i;
78 dprintf_reg(stddeb,"DragQueryFile(%04x, %i, %p, %u)\n",
79 hDrop,wFile,lpszFile,wLength);
81 lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock16(hDrop);
82 if(!lpDropFileStruct) return 0;
84 lpCurrent = (LPSTR) lpDropFileStruct + lpDropFileStruct->wSize;
86 i = 0;
87 while (i++ < wFile)
89 while (*lpCurrent++); /* skip filename */
90 if (!*lpCurrent)
91 return (wFile == 0xFFFF) ? i : 0;
94 i = strlen(lpCurrent);
95 if (!lpszFile) return i+1; /* needed buffer size */
97 i = (wLength > i) ? i : wLength-1;
98 strncpy(lpszFile, lpCurrent, i);
99 lpszFile[i] = '\0';
101 GlobalUnlock16(hDrop);
102 return i;
106 /*************************************************************************
107 * DragFinish [SHELL.12]
109 void DragFinish(HDROP16 h)
111 GlobalFree16((HGLOBAL16)h);
115 /*************************************************************************
116 * DragQueryPoint [SHELL.13]
118 BOOL DragQueryPoint(HDROP16 hDrop, POINT16 *p)
120 LPDROPFILESTRUCT lpDropFileStruct;
121 BOOL16 bRet;
123 lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock16(hDrop);
125 memcpy(p,&lpDropFileStruct->ptMousePos,sizeof(POINT16));
126 bRet = lpDropFileStruct->fInNonClientArea;
128 GlobalUnlock16(hDrop);
129 return bRet;
132 /*************************************************************************
133 * SHELL_FindExecutable
134 * Utility for code sharing between FindExecutable and ShellExecute
136 static HINSTANCE16 SHELL_FindExecutable( LPCSTR lpFile,
137 LPCSTR lpDirectory,
138 LPCSTR lpOperation,
139 LPSTR lpResult)
141 char *extension = NULL; /* pointer to file extension */
142 char tmpext[5]; /* local copy to mung as we please */
143 char filetype[256]; /* registry name for this filetype */
144 LONG filetypelen=256; /* length of above */
145 char command[256]; /* command from registry */
146 LONG commandlen=256; /* This is the most DOS can handle :) */
147 char buffer[256]; /* Used to GetProfileString */
148 HINSTANCE16 retval=31; /* default - 'No association was found' */
149 char *tok; /* token pointer */
150 int i; /* random counter */
151 char xlpFile[256]; /* result of SearchPath */
153 dprintf_exec(stddeb, "SHELL_FindExecutable: File %s, Dir %s\n",
154 (lpFile != NULL?lpFile:"-"),
155 (lpDirectory != NULL?lpDirectory:"-"));
157 lpResult[0]='\0'; /* Start off with an empty return string */
159 /* trap NULL parameters on entry */
160 if (( lpFile == NULL ) || ( lpResult == NULL ) || ( lpOperation == NULL ))
162 /* FIXME - should throw a warning, perhaps! */
163 return 2; /* File not found. Close enough, I guess. */
165 if (SearchPath32A(lpDirectory,lpFile,NULL,sizeof(xlpFile),xlpFile,NULL))
166 lpFile = xlpFile;
167 else {
168 if (SearchPath32A(lpDirectory,lpFile,".exe",sizeof(xlpFile),xlpFile,NULL))
169 lpFile = xlpFile;
172 /* First thing we need is the file's extension */
173 extension = strrchr( xlpFile, '.' ); /* Assume last "." is the one; */
174 /* File->Run in progman uses */
175 /* .\FILE.EXE :( */
176 if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)]))
178 return 31; /* no association */
181 /* Make local copy & lowercase it for reg & 'programs=' lookup */
182 strncpy( tmpext, extension, 5 );
183 if (strlen(extension)<=4)
184 tmpext[strlen(extension)]='\0';
185 else
186 tmpext[4]='\0';
187 for (i=0;i<strlen(tmpext);i++) tmpext[i]=tolower(tmpext[i]);
188 dprintf_exec(stddeb, "SHELL_FindExecutable: %s file\n", tmpext);
190 /* Three places to check: */
191 /* 1. win.ini, [windows], programs (NB no leading '.') */
192 /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */
193 /* 3. win.ini, [extensions], extension (NB no leading '.' */
194 /* All I know of the order is that registry is checked before */
195 /* extensions; however, it'd make sense to check the programs */
196 /* section first, so that's what happens here. */
198 /* See if it's a program - if GetProfileString fails, we skip this
199 * section. Actually, if GetProfileString fails, we've probably
200 * got a lot more to worry about than running a program... */
201 if ( GetProfileString32A("windows", "programs", "exe pif bat com",
202 buffer, sizeof(buffer)) > 0 )
204 for (i=0;i<strlen(buffer); i++) buffer[i]=tolower(buffer[i]);
206 tok = strtok(buffer, " \t"); /* ? */
207 while( tok!= NULL)
209 if (strcmp(tok, &tmpext[1])==0) /* have to skip the leading "." */
211 strcpy(lpResult, xlpFile);
212 /* Need to perhaps check that the file has a path
213 * attached */
214 dprintf_exec(stddeb, "SHELL_FindExecutable: found %s\n",
215 lpResult);
216 return 33;
218 /* Greater than 32 to indicate success FIXME According to the
219 * docs, I should be returning a handle for the
220 * executable. Does this mean I'm supposed to open the
221 * executable file or something? More RTFM, I guess... */
223 tok=strtok(NULL, " \t");
227 /* Check registry */
228 if (RegQueryValue16( (HKEY)HKEY_CLASSES_ROOT, tmpext, filetype,
229 &filetypelen ) == SHELL_ERROR_SUCCESS )
231 filetype[filetypelen]='\0';
232 dprintf_exec(stddeb, "SHELL_FindExecutable: File type: %s\n",
233 filetype);
235 /* Looking for ...buffer\shell\lpOperation\command */
236 strcat( filetype, "\\shell\\" );
237 strcat( filetype, lpOperation );
238 strcat( filetype, "\\command" );
240 if (RegQueryValue16( (HKEY)HKEY_CLASSES_ROOT, filetype, command,
241 &commandlen ) == SHELL_ERROR_SUCCESS )
243 /* Is there a replace() function anywhere? */
244 command[commandlen]='\0';
245 strcpy( lpResult, command );
246 tok=strstr( lpResult, "%1" );
247 if (tok != NULL)
249 tok[0]='\0'; /* truncate string at the percent */
250 strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */
251 tok=strstr( command, "%1" );
252 if ((tok!=NULL) && (strlen(tok)>2))
254 strcat( lpResult, &tok[2] );
257 retval=33; /* FIXME see above */
260 else /* Check win.ini */
262 /* Toss the leading dot */
263 extension++;
264 if ( GetProfileString32A( "extensions", extension, "", command,
265 sizeof(command)) > 0)
267 if (strlen(command)!=0)
269 strcpy( lpResult, command );
270 tok=strstr( lpResult, "^" ); /* should be ^.extension? */
271 if (tok != NULL)
273 tok[0]='\0';
274 strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */
275 tok=strstr( command, "^" ); /* see above */
276 if ((tok != NULL) && (strlen(tok)>5))
278 strcat( lpResult, &tok[5]);
281 retval=33; /* FIXME - see above */
286 dprintf_exec(stddeb, "SHELL_FindExecutable: returning %s\n", lpResult);
287 return retval;
290 /*************************************************************************
291 * ShellExecute [SHELL.20]
293 HINSTANCE16 ShellExecute(HWND hWnd, LPCSTR lpOperation, LPCSTR lpFile,
294 LPSTR lpParameters, LPCSTR lpDirectory,
295 INT iShowCmd)
297 HINSTANCE16 retval=31;
298 char cmd[256];
300 dprintf_exec(stddeb, "ShellExecute(%04x,'%s','%s','%s','%s',%x)\n",
301 hWnd, lpOperation ? lpOperation:"<null>", lpFile ? lpFile:"<null>",
302 lpParameters ? lpParameters : "<null>",
303 lpDirectory ? lpDirectory : "<null>", iShowCmd);
305 if (lpFile==NULL) return 0; /* should not happen */
306 if (lpOperation==NULL) /* default is open */
307 lpOperation="open";
309 retval = SHELL_FindExecutable( lpFile, lpDirectory, lpOperation, cmd );
311 if ( retval <= 32 )
313 return retval;
316 if (lpParameters)
318 strcat(cmd," ");
319 strcat(cmd,lpParameters);
322 dprintf_exec(stddeb,"ShellExecute:starting %s\n",cmd);
323 return WinExec(cmd,iShowCmd);
326 /*************************************************************************
327 * FindExecutable [SHELL.21]
329 HINSTANCE16 FindExecutable(LPCSTR lpFile, LPCSTR lpDirectory, LPSTR lpResult)
331 HINSTANCE16 retval=31; /* default - 'No association was found' */
333 dprintf_exec(stddeb, "FindExecutable: File %s, Dir %s\n",
334 (lpFile != NULL?lpFile:"-"),
335 (lpDirectory != NULL?lpDirectory:"-"));
337 lpResult[0]='\0'; /* Start off with an empty return string */
339 /* trap NULL parameters on entry */
340 if (( lpFile == NULL ) || ( lpResult == NULL ))
342 /* FIXME - should throw a warning, perhaps! */
343 return 2; /* File not found. Close enough, I guess. */
346 retval = SHELL_FindExecutable( lpFile, lpDirectory, "open",
347 lpResult );
349 dprintf_exec(stddeb, "FindExecutable: returning %s\n", lpResult);
350 return retval;
353 static char AppName[128], AppMisc[1536];
355 /*************************************************************************
356 * AboutDlgProc [SHELL.33]
358 LRESULT AboutDlgProc(HWND hWnd, UINT msg, WPARAM16 wParam, LPARAM lParam)
360 char Template[512], AppTitle[512];
362 switch(msg) {
363 case WM_INITDIALOG:
364 SendDlgItemMessage32A(hWnd,stc1,STM_SETICON,lParam,0);
365 GetWindowText32A(hWnd, Template, sizeof(Template));
366 sprintf(AppTitle, Template, AppName);
367 SetWindowText32A(hWnd, AppTitle);
368 SetWindowText32A(GetDlgItem(hWnd,100), AppMisc);
369 return 1;
371 case WM_COMMAND:
372 switch (wParam) {
373 case IDOK:
374 EndDialog(hWnd, TRUE);
375 return TRUE;
377 break;
379 return FALSE;
382 /*************************************************************************
383 * ShellAbout [SHELL.22]
385 INT ShellAbout(HWND hWnd, LPCSTR szApp, LPCSTR szOtherStuff, HICON16 hIcon)
387 HGLOBAL16 handle;
388 BOOL bRet;
390 if (szApp) strncpy(AppName, szApp, sizeof(AppName));
391 else *AppName = 0;
392 AppName[sizeof(AppName)-1]=0;
394 if (szOtherStuff) strncpy(AppMisc, szOtherStuff, sizeof(AppMisc));
395 else *AppMisc = 0;
396 AppMisc[sizeof(AppMisc)-1]=0;
398 if (!hIcon) hIcon = LoadIcon16(0,MAKEINTRESOURCE(OIC_WINEICON));
399 handle = SYSRES_LoadResource( SYSRES_DIALOG_SHELL_ABOUT_MSGBOX );
400 if (!handle) return FALSE;
401 bRet = DialogBoxIndirectParam16( WIN_GetWindowInstance( hWnd ),
402 handle, hWnd,
403 (DLGPROC16)MODULE_GetWndProcEntry16("AboutDlgProc"),
404 (LPARAM)hIcon );
405 SYSRES_FreeResource( handle );
406 return bRet;
409 /*************************************************************************
410 * SHELL_GetResourceTable
412 * FIXME: Implement GetPEResourceTable in w32sys.c and call it here.
414 static BYTE* SHELL_GetResourceTable(HFILE hFile)
416 struct mz_header_s mz_header;
417 struct ne_header_s ne_header;
418 int size;
420 _llseek( hFile, 0, SEEK_SET );
421 if ((_lread32(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) ||
422 (mz_header.mz_magic != MZ_SIGNATURE)) return (BYTE*)-1;
424 _llseek( hFile, mz_header.ne_offset, SEEK_SET );
425 if (_lread32( hFile, &ne_header, sizeof(ne_header) ) != sizeof(ne_header))
426 return NULL;
428 if (ne_header.ne_magic == PE_SIGNATURE)
429 { fprintf(stdnimp,"Win32s FIXME: file %s line %i\n", __FILE__, __LINE__ );
430 return NULL; }
432 if (ne_header.ne_magic != NE_SIGNATURE) return NULL;
434 size = ne_header.rname_tab_offset - ne_header.resource_tab_offset;
436 if( size > sizeof(NE_TYPEINFO) )
438 BYTE* pTypeInfo = (BYTE*)xmalloc(size);
440 if( !pTypeInfo ) return NULL;
442 _llseek(hFile, mz_header.ne_offset+ne_header.resource_tab_offset, SEEK_SET);
443 if( _lread32( hFile, (char*)pTypeInfo, size) != size )
444 { free(pTypeInfo); return NULL; }
445 return pTypeInfo;
447 /* no resources */
449 return NULL;
452 /*************************************************************************
453 * SHELL_LoadResource
455 static HGLOBAL16 SHELL_LoadResource(HINSTANCE16 hInst, HFILE hFile, NE_NAMEINFO* pNInfo, WORD sizeShift)
457 BYTE* ptr;
458 HGLOBAL16 handle = DirectResAlloc( hInst, 0x10, (DWORD)pNInfo->length << sizeShift);
460 if( (ptr = (BYTE*)GlobalLock16( handle )) )
462 _llseek( hFile, (DWORD)pNInfo->offset << sizeShift, SEEK_SET);
463 _lread32( hFile, (char*)ptr, pNInfo->length << sizeShift);
464 return handle;
466 return 0;
469 /*************************************************************************
470 * ICO_LoadIcon
472 static HGLOBAL16 ICO_LoadIcon(HINSTANCE16 hInst, HFILE hFile, LPicoICONDIRENTRY lpiIDE)
474 BYTE* ptr;
475 HGLOBAL16 handle = DirectResAlloc( hInst, 0x10, lpiIDE->dwBytesInRes);
477 if( (ptr = (BYTE*)GlobalLock16( handle )) )
479 _llseek( hFile, lpiIDE->dwImageOffset, SEEK_SET);
480 _lread32( hFile, (char*)ptr, lpiIDE->dwBytesInRes);
481 return handle;
483 return 0;
486 /*************************************************************************
487 * ICO_GetIconDirectory
489 * Read .ico file and build phony ICONDIR struct for GetIconID
491 static HGLOBAL16 ICO_GetIconDirectory(HINSTANCE16 hInst, HFILE hFile, LPicoICONDIR* lplpiID )
493 WORD id[3]; /* idReserved, idType, idCount */
494 LPicoICONDIR lpiID;
495 int i;
497 _llseek( hFile, 0, SEEK_SET );
498 if( _lread32(hFile,(char*)id,sizeof(id)) != sizeof(id) ) return 0;
500 /* check .ICO header
502 * - see http://www.microsoft.com/win32dev/ui/icons.htm
505 if( id[0] || id[1] != 1 || !id[2] ) return 0;
507 i = id[2]*sizeof(icoICONDIRENTRY) + sizeof(id);
509 lpiID = (LPicoICONDIR)xmalloc(i);
511 if( _lread32(hFile,(char*)lpiID->idEntries,i) == i )
513 HGLOBAL16 handle = DirectResAlloc( hInst, 0x10,
514 id[2]*sizeof(ICONDIRENTRY) + sizeof(id) );
515 if( handle )
517 CURSORICONDIR* lpID = (CURSORICONDIR*)GlobalLock16( handle );
518 lpID->idReserved = lpiID->idReserved = id[0];
519 lpID->idType = lpiID->idType = id[1];
520 lpID->idCount = lpiID->idCount = id[2];
521 for( i=0; i < lpiID->idCount; i++ )
523 memcpy((void*)(lpID->idEntries + i),
524 (void*)(lpiID->idEntries + i), sizeof(ICONDIRENTRY) - 2);
525 lpID->idEntries[i].icon.wResId = i;
527 *lplpiID = lpiID;
528 return handle;
531 /* fail */
533 free(lpiID);
534 return 0;
537 /*************************************************************************
538 * InternalExtractIcon [SHELL.39]
540 * This abortion is called directly by Progman
542 HGLOBAL16 InternalExtractIcon(HINSTANCE16 hInstance, LPCSTR lpszExeFileName, UINT nIconIndex, WORD n )
544 HGLOBAL16 hRet = 0;
545 HGLOBAL16* RetPtr = NULL;
546 BYTE* pData;
547 OFSTRUCT ofs;
548 HFILE hFile = OpenFile( lpszExeFileName, &ofs, OF_READ );
550 dprintf_reg(stddeb, "InternalExtractIcon(%04x, file '%s', start from %d, extract %d\n",
551 hInstance, lpszExeFileName, nIconIndex, n);
553 if( hFile == HFILE_ERROR || !n ) return 0;
555 hRet = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, sizeof(HICON16)*n);
556 RetPtr = (HICON16*)GlobalLock16(hRet);
558 *RetPtr = (n == 0xFFFF)? 0: 1; /* error return values */
560 pData = SHELL_GetResourceTable(hFile);
561 if( pData )
563 HICON16 hIcon = 0;
564 BOOL icoFile = FALSE;
565 UINT iconDirCount = 0;
566 UINT iconCount = 0;
567 NE_TYPEINFO* pTInfo = (NE_TYPEINFO*)(pData + 2);
568 NE_NAMEINFO* pIconStorage = NULL;
569 NE_NAMEINFO* pIconDir = NULL;
570 LPicoICONDIR lpiID = NULL;
572 if( pData == (BYTE*)-1 )
574 /* check for .ICO file */
576 hIcon = ICO_GetIconDirectory(hInstance, hFile, &lpiID);
577 if( hIcon )
578 { icoFile = TRUE; iconDirCount = 1; iconCount = lpiID->idCount; }
580 else while( pTInfo->type_id && !(pIconStorage && pIconDir) )
582 /* find icon directory and icon repository */
584 if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON )
586 iconDirCount = pTInfo->count;
587 pIconDir = ((NE_NAMEINFO*)(pTInfo + 1));
588 dprintf_reg(stddeb,"\tfound directory - %i icon families\n", iconDirCount);
590 if( pTInfo->type_id == NE_RSCTYPE_ICON )
592 iconCount = pTInfo->count;
593 pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1));
594 dprintf_reg(stddeb,"\ttotal icons - %i\n", iconCount);
596 pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO));
599 /* load resources and create icons */
601 if( (pIconStorage && pIconDir) || icoFile )
602 if( nIconIndex == (UINT)-1 ) RetPtr[0] = iconDirCount;
603 else if( nIconIndex < iconDirCount )
605 UINT i, icon;
607 if( n > iconDirCount - nIconIndex ) n = iconDirCount - nIconIndex;
609 for( i = nIconIndex; i < nIconIndex + n; i++ )
611 /* .ICO files have only one icon directory */
613 if( !icoFile )
614 hIcon = SHELL_LoadResource( hInstance, hFile, pIconDir + i,
615 *(WORD*)pData );
616 RetPtr[i-nIconIndex] = GetIconID( hIcon, 3 );
617 GlobalFree16(hIcon);
620 for( icon = nIconIndex; icon < nIconIndex + n; icon++ )
622 hIcon = 0;
623 if( icoFile )
624 hIcon = ICO_LoadIcon( hInstance, hFile, lpiID->idEntries + RetPtr[icon-nIconIndex]);
625 else
626 for( i = 0; i < iconCount; i++ )
627 if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) )
628 hIcon = SHELL_LoadResource( hInstance, hFile, pIconStorage + i,
629 *(WORD*)pData );
630 RetPtr[icon-nIconIndex] = (hIcon)?CURSORICON_LoadHandler( hIcon, hInstance, FALSE ):0;
633 if( icoFile ) free(lpiID);
634 else free(pData);
636 _lclose( hFile );
638 /* return array with icon handles */
640 return hRet;
643 /*************************************************************************
644 * ExtractIcon [SHELL.34]
646 HICON16 ExtractIcon(HINSTANCE16 hInstance, LPCSTR lpszExeFileName, WORD nIconIndex)
648 HGLOBAL16 handle = InternalExtractIcon(hInstance,lpszExeFileName,nIconIndex, 1);
650 if( handle )
652 HICON16* ptr = (HICON16*)GlobalLock16(handle);
653 HICON16 hIcon = *ptr;
655 GlobalFree16(handle);
656 return hIcon;
658 return 0;
661 /*************************************************************************
662 * ExtractAssociatedIcon [SHELL.36]
664 * Return icon for given file (either from file itself or from associated
665 * executable) and patch parameters if needed.
667 HICON16 ExtractAssociatedIcon(HINSTANCE16 hInst,LPSTR lpIconPath,LPWORD lpiIcon)
669 HICON16 hIcon = ExtractIcon(hInst, lpIconPath, *lpiIcon);
671 if( hIcon < 2 )
674 if( hIcon == 1 ) /* no icons found in given file */
676 char tempPath[0x80];
677 UINT uRet = FindExecutable(lpIconPath,NULL,tempPath);
679 if( uRet > 32 && tempPath[0] )
681 strcpy(lpIconPath,tempPath);
682 hIcon = ExtractIcon(hInst, lpIconPath, *lpiIcon);
684 if( hIcon > 2 ) return hIcon;
686 else hIcon = 0;
689 if( hIcon == 1 )
690 *lpiIcon = 2; /* MSDOS icon - we found .exe but no icons in it */
691 else
692 *lpiIcon = 6; /* generic icon - found nothing */
694 GetModuleFileName(hInst, lpIconPath, 0x80);
695 hIcon = LoadIcon16( hInst, MAKEINTRESOURCE(*lpiIcon));
698 return hIcon;
701 /*************************************************************************
702 * FindEnvironmentString [SHELL.38]
704 * Returns a pointer into the DOS environment... Ugh.
706 LPSTR SHELL_FindString(LPSTR lpEnv, LPCSTR entry)
708 UINT l = strlen(entry);
709 for( ; *lpEnv ; lpEnv+=strlen(lpEnv)+1 )
711 if( lstrncmpi32A(lpEnv, entry, l) ) continue;
713 if( !*(lpEnv+l) )
714 return (lpEnv + l); /* empty entry */
715 else if ( *(lpEnv+l)== '=' )
716 return (lpEnv + l + 1);
718 return NULL;
721 SEGPTR FindEnvironmentString(LPSTR str)
723 SEGPTR spEnv = GetDOSEnvironment();
724 LPSTR lpEnv = (LPSTR)PTR_SEG_TO_LIN(spEnv);
726 LPSTR lpString = (spEnv)?SHELL_FindString(lpEnv, str):NULL;
728 if( lpString ) /* offset should be small enough */
729 return spEnv + (lpString - lpEnv);
731 return (SEGPTR)NULL;
734 /*************************************************************************
735 * DoEnvironmentSubst [SHELL.37]
737 * Replace %KEYWORD% in the str with the value of variable KEYWORD
738 * from "DOS" environment.
740 DWORD DoEnvironmentSubst(LPSTR str,WORD length)
742 LPSTR lpEnv = (LPSTR)PTR_SEG_TO_LIN(GetDOSEnvironment());
743 LPSTR lpBuffer = (LPSTR)xmalloc(length);
744 LPSTR lpstr = str;
745 LPSTR lpbstr = lpBuffer;
747 AnsiToOem(str,str);
749 dprintf_reg(stddeb,"DoEnvSubst: accept %s", str);
751 while( *lpstr && lpbstr - lpBuffer < length )
753 LPSTR lpend = lpstr;
755 if( *lpstr == '%' )
757 do { lpend++; } while( *lpend && *lpend != '%' );
758 if( *lpend == '%' && lpend - lpstr > 1 ) /* found key */
760 LPSTR lpKey;
761 *lpend = '\0';
762 lpKey = SHELL_FindString(lpEnv, lpstr+1);
763 if( lpKey ) /* found key value */
765 int l = strlen(lpKey);
767 if( l > length - (lpbstr - lpBuffer) - 1 )
769 fprintf(stdnimp,"File %s, line %i: Env subst aborted - string too short\n",
770 __FILE__, __LINE__);
771 *lpend = '%';
772 break;
774 strcpy(lpbstr, lpKey);
775 lpbstr += l;
777 else break;
778 *lpend = '%';
779 lpstr = lpend + 1;
781 else break; /* back off and whine */
783 continue;
786 *lpbstr++ = *lpstr++;
789 *lpbstr = '\0';
790 if( lpstr - str == strlen(str) )
792 strncpy(str, lpBuffer, length);
793 length = 1;
795 else
796 length = 0;
798 dprintf_reg(stddeb," return %s\n", str);
800 OemToAnsi(str,str);
801 free(lpBuffer);
803 /* Return str length in the LOWORD
804 * and 1 in HIWORD if subst was successful.
806 return (DWORD)MAKELONG(strlen(str), length);
809 /*************************************************************************
810 * RegisterShellHook [SHELL.102]
812 int RegisterShellHook(void *ptr)
814 fprintf(stdnimp, "RegisterShellHook( %p ) : Empty Stub !!!\n", ptr);
815 return 0;
819 /*************************************************************************
820 * ShellHookProc [SHELL.103]
822 int ShellHookProc(void)
824 fprintf(stdnimp, "ShellHookProc : Empty Stub !!!\n");
825 return 0;
828 /*************************************************************************
829 * SHGetFileInfoA [SHELL32.54]
831 DWORD
832 SHGetFileInfo32A(LPCSTR path,DWORD dwFileAttributes,SHFILEINFO32A *psfi,
833 UINT32 sizeofpsfi,UINT32 flags
835 fprintf(stdnimp,"SHGetFileInfo32A(%s,0x%08lx,%p,%d,0x%08x)\n",
836 path,dwFileAttributes,psfi,sizeofpsfi,flags
838 return TRUE;