| 1 | /* $Id: shell.cpp,v 1.6 2000-03-27 15:09:20 cbratschi Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Win32 SHELL32 for OS/2 | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1999 Patrick Haller (haller@zebra.fh-weingarten.de) | 
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 8 | * | 
|---|
| 9 | *             Shell Library Functions | 
|---|
| 10 | * | 
|---|
| 11 | *  1998 Marcus Meissner | 
|---|
| 12 | * | 
|---|
| 13 | * Corel WINE 20000324 level | 
|---|
| 14 | */ | 
|---|
| 15 |  | 
|---|
| 16 |  | 
|---|
| 17 | /***************************************************************************** | 
|---|
| 18 | * Includes                                                                  * | 
|---|
| 19 | *****************************************************************************/ | 
|---|
| 20 |  | 
|---|
| 21 | #include <odin.h> | 
|---|
| 22 | #include <odinwrap.h> | 
|---|
| 23 | #include <os2sel.h> | 
|---|
| 24 |  | 
|---|
| 25 | #include <assert.h> | 
|---|
| 26 | #include <stdlib.h> | 
|---|
| 27 | #include <string.h> | 
|---|
| 28 | //#include <unistd.h> | 
|---|
| 29 | #include <ctype.h> | 
|---|
| 30 |  | 
|---|
| 31 | #define ICOM_CINTERFACE 1 | 
|---|
| 32 | #define CINTERFACE 1 | 
|---|
| 33 |  | 
|---|
| 34 | #include <winbase.h> | 
|---|
| 35 | #include <winuser.h> | 
|---|
| 36 | //#include "wine/shell16.h" | 
|---|
| 37 | #include "winerror.h" | 
|---|
| 38 | //#include "file.h" | 
|---|
| 39 | #include "heap.h" | 
|---|
| 40 | #include "ldt.h" | 
|---|
| 41 | #include "module.h" | 
|---|
| 42 | #include "neexe.h" | 
|---|
| 43 | #include "dlgs.h" | 
|---|
| 44 | #include "cursoricon.h" | 
|---|
| 45 | #include "shellapi.h" | 
|---|
| 46 | #include "shlobj.h" | 
|---|
| 47 | #include "debugtools.h" | 
|---|
| 48 | #include "winreg.h" | 
|---|
| 49 | //#include "syslevel.h" | 
|---|
| 50 | #include "imagelist.h" | 
|---|
| 51 | #include "shell32_main.h" | 
|---|
| 52 | #include "winversion.h" | 
|---|
| 53 |  | 
|---|
| 54 | #include <heapstring.h> | 
|---|
| 55 | #include <misc.h> | 
|---|
| 56 |  | 
|---|
| 57 |  | 
|---|
| 58 | /***************************************************************************** | 
|---|
| 59 | * Implementation                                                            * | 
|---|
| 60 | *****************************************************************************/ | 
|---|
| 61 |  | 
|---|
| 62 | ODINDEBUGCHANNEL(SHELL32-SHELL) | 
|---|
| 63 |  | 
|---|
| 64 |  | 
|---|
| 65 | /* .ICO file ICONDIR definitions */ | 
|---|
| 66 |  | 
|---|
| 67 | #include "pshpack1.h" | 
|---|
| 68 |  | 
|---|
| 69 | typedef struct | 
|---|
| 70 | { | 
|---|
| 71 | BYTE        bWidth;          /* Width, in pixels, of the image  */ | 
|---|
| 72 | BYTE        bHeight;         /* Height, in pixels, of the image */ | 
|---|
| 73 | BYTE        bColorCount;     /* Number of colors in image (0 if >=8bpp) */ | 
|---|
| 74 | BYTE        bReserved;       /* Reserved ( must be 0)     */ | 
|---|
| 75 | WORD        wPlanes;         /* Color Planes        */ | 
|---|
| 76 | WORD        wBitCount;       /* Bits per pixel         */ | 
|---|
| 77 | DWORD       dwBytesInRes;    /* How many bytes in this resource?   */ | 
|---|
| 78 | DWORD       dwImageOffset;   /* Where in the file is this image?   */ | 
|---|
| 79 | } icoICONDIRENTRY, *LPicoICONDIRENTRY; | 
|---|
| 80 |  | 
|---|
| 81 | typedef struct | 
|---|
| 82 | { | 
|---|
| 83 | WORD            idReserved;   /* Reserved (must be 0)     */ | 
|---|
| 84 | WORD            idType;       /* Resource Type (1 for icons) */ | 
|---|
| 85 | WORD            idCount;      /* How many images?         */ | 
|---|
| 86 | icoICONDIRENTRY idEntries[1]; /* An entry for each image (idCount of 'em) */ | 
|---|
| 87 | } icoICONDIR, *LPicoICONDIR; | 
|---|
| 88 |  | 
|---|
| 89 | #include "poppack.h" | 
|---|
| 90 |  | 
|---|
| 91 | static const char* lpstrMsgWndCreated    = "OTHERWINDOWCREATED"; | 
|---|
| 92 | static const char* lpstrMsgWndDestroyed  = "OTHERWINDOWDESTROYED"; | 
|---|
| 93 | static const char* lpstrMsgShellActivate = "ACTIVATESHELLWINDOW"; | 
|---|
| 94 |  | 
|---|
| 95 | static HWND  SHELL_hWnd = 0; | 
|---|
| 96 | static HHOOK SHELL_hHook = 0; | 
|---|
| 97 | static UINT  uMsgWndCreated = 0; | 
|---|
| 98 | static UINT  uMsgWndDestroyed = 0; | 
|---|
| 99 | static UINT  uMsgShellActivate = 0; | 
|---|
| 100 | HINSTANCE SHELL_hInstance32; | 
|---|
| 101 | static int SHELL_Attach = 0; | 
|---|
| 102 |  | 
|---|
| 103 |  | 
|---|
| 104 | /************************************************************************* | 
|---|
| 105 | *          DragAcceptFiles32               [SHELL32.54] | 
|---|
| 106 | */ | 
|---|
| 107 |  | 
|---|
| 108 | //SvL: DON'T USE ODINFUNCTION MACRO'S HERE; SetWindowLong (style) sends messages | 
|---|
| 109 | //     to the win32 app!!!! (FS messed up) | 
|---|
| 110 | void WINAPI DragAcceptFiles(HWND hWnd, BOOL b) | 
|---|
| 111 | { | 
|---|
| 112 | LONG exstyle; | 
|---|
| 113 |  | 
|---|
| 114 | dprintf(("DragAcceptFiles %x %d", hWnd, b)); | 
|---|
| 115 | if( !IsWindow(hWnd) ) | 
|---|
| 116 | return; | 
|---|
| 117 | exstyle = GetWindowLongA(hWnd,GWL_EXSTYLE); | 
|---|
| 118 | if (b)exstyle |= WS_EX_ACCEPTFILES; | 
|---|
| 119 | else   exstyle &= ~WS_EX_ACCEPTFILES; | 
|---|
| 120 | SetWindowLongA(hWnd,GWL_EXSTYLE,exstyle); | 
|---|
| 121 | } | 
|---|
| 122 |  | 
|---|
| 123 | /************************************************************************* | 
|---|
| 124 | *          SHELL_DragQueryFile          [internal] | 
|---|
| 125 | * | 
|---|
| 126 | */ | 
|---|
| 127 | static UINT SHELL_DragQueryFile(LPSTR lpDrop, LPWSTR lpwDrop, UINT lFile, | 
|---|
| 128 | LPSTR lpszFile, LPWSTR lpszwFile, UINT lLength) | 
|---|
| 129 | { | 
|---|
| 130 | UINT i; | 
|---|
| 131 |  | 
|---|
| 132 | i = 0; | 
|---|
| 133 | if (lpDrop) { | 
|---|
| 134 | while (i++ < lFile) { | 
|---|
| 135 | while (*lpDrop++); /* skip filename */ | 
|---|
| 136 | if (!*lpDrop) | 
|---|
| 137 | return (lFile == 0xFFFFFFFF) ? i : 0; | 
|---|
| 138 | } | 
|---|
| 139 | } | 
|---|
| 140 | if (lpwDrop) { | 
|---|
| 141 | while (i++ < lFile) { | 
|---|
| 142 | while (*lpwDrop++); /* skip filename */ | 
|---|
| 143 | if (!*lpwDrop) | 
|---|
| 144 | return (lFile == 0xFFFFFFFF) ? i : 0; | 
|---|
| 145 | } | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | if (lpDrop)  i = lstrlenA(lpDrop); | 
|---|
| 149 | if (lpwDrop) i = lstrlenW(lpwDrop); | 
|---|
| 150 | i++; | 
|---|
| 151 | if (!lpszFile && !lpszwFile) { | 
|---|
| 152 | return i;   /* needed buffer size */ | 
|---|
| 153 | } | 
|---|
| 154 | i = (lLength > i) ? i : lLength; | 
|---|
| 155 | if (lpszFile) { | 
|---|
| 156 | if (lpDrop) lstrcpynA (lpszFile,  lpDrop,  i); | 
|---|
| 157 | else        lstrcpynWtoA(lpszFile,  lpwDrop, i); | 
|---|
| 158 | } else { | 
|---|
| 159 | if (lpDrop) lstrcpynAtoW(lpszwFile, lpDrop,  i); | 
|---|
| 160 | else        lstrcpynW (lpszwFile, lpwDrop, i); | 
|---|
| 161 | } | 
|---|
| 162 | return i; | 
|---|
| 163 | } | 
|---|
| 164 |  | 
|---|
| 165 | /************************************************************************* | 
|---|
| 166 | *          DragQueryFile32A             [SHELL32.81] [shell32.82] | 
|---|
| 167 | */ | 
|---|
| 168 |  | 
|---|
| 169 | ODINFUNCTION4(UINT, DragQueryFileA, HDROP, hDrop, | 
|---|
| 170 | UINT,  lFile, | 
|---|
| 171 | LPSTR, lpszFile, | 
|---|
| 172 | UINT,  lLength) | 
|---|
| 173 | { /* hDrop is a global memory block allocated with GMEM_SHARE | 
|---|
| 174 | * with DROPFILESTRUCT as a header and filenames following | 
|---|
| 175 | * it, zero length filename is in the end */ | 
|---|
| 176 |  | 
|---|
| 177 | LPDROPFILESTRUCT lpDropFileStruct; | 
|---|
| 178 | LPSTR lpCurrent; | 
|---|
| 179 | UINT i; | 
|---|
| 180 |  | 
|---|
| 181 | lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); | 
|---|
| 182 | if(!lpDropFileStruct) | 
|---|
| 183 | return 0; | 
|---|
| 184 |  | 
|---|
| 185 | lpCurrent = (LPSTR) lpDropFileStruct + lpDropFileStruct->lSize; | 
|---|
| 186 | i = SHELL_DragQueryFile(lpCurrent, NULL, lFile, lpszFile, NULL, lLength); | 
|---|
| 187 | GlobalUnlock(hDrop); | 
|---|
| 188 | return i; | 
|---|
| 189 | } | 
|---|
| 190 |  | 
|---|
| 191 | /************************************************************************* | 
|---|
| 192 | *          DragQueryFile32W             [shell32.133] | 
|---|
| 193 | */ | 
|---|
| 194 | ODINFUNCTION4(UINT, DragQueryFileW, HDROP,  hDrop, | 
|---|
| 195 | UINT,   lFile, | 
|---|
| 196 | LPWSTR, lpszwFile, | 
|---|
| 197 | UINT,   lLength) | 
|---|
| 198 | { | 
|---|
| 199 | LPDROPFILESTRUCT lpDropFileStruct; | 
|---|
| 200 | LPWSTR lpwCurrent; | 
|---|
| 201 | UINT i; | 
|---|
| 202 |  | 
|---|
| 203 | lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); | 
|---|
| 204 | if(!lpDropFileStruct) | 
|---|
| 205 | return 0; | 
|---|
| 206 |  | 
|---|
| 207 | lpwCurrent = (LPWSTR) lpDropFileStruct + lpDropFileStruct->lSize; | 
|---|
| 208 | i = SHELL_DragQueryFile(NULL, lpwCurrent, lFile, NULL, lpszwFile,lLength); | 
|---|
| 209 | GlobalUnlock(hDrop); | 
|---|
| 210 | return i; | 
|---|
| 211 | } | 
|---|
| 212 |  | 
|---|
| 213 |  | 
|---|
| 214 | /***************************************************************************** | 
|---|
| 215 | * Name      : UINT DragQueryFileAorW | 
|---|
| 216 | * Purpose   : | 
|---|
| 217 | * Parameters: HDROP  hDrop    - drop structure handle | 
|---|
| 218 | *             UINT   iFile    - index of file to query | 
|---|
| 219 | *             LPTSTR lpszFile - target buffer | 
|---|
| 220 | *             UINT   cch      - target buffer size | 
|---|
| 221 | * Variables : | 
|---|
| 222 | * Result    : | 
|---|
| 223 | * Remark    : | 
|---|
| 224 | * Status    : UNTESTED STUB | 
|---|
| 225 | * | 
|---|
| 226 | * Author    : Patrick Haller [Tue, 1999/06/09 20:00] | 
|---|
| 227 | *****************************************************************************/ | 
|---|
| 228 |  | 
|---|
| 229 | ODINFUNCTION4(UINT,   DragQueryFileAorW, | 
|---|
| 230 | HDROP,  hDrop, | 
|---|
| 231 | UINT,   iFile, | 
|---|
| 232 | LPTSTR, lpszFile, | 
|---|
| 233 | UINT,   cch) | 
|---|
| 234 | { | 
|---|
| 235 | // @@@PH maybe they want automatic determination here | 
|---|
| 236 | if (VERSION_OsIsUnicode()) | 
|---|
| 237 | return DragQueryFileW(hDrop, iFile, (LPWSTR)lpszFile, cch); | 
|---|
| 238 | else | 
|---|
| 239 | return DragQueryFileA(hDrop, iFile, lpszFile, cch); | 
|---|
| 240 | } | 
|---|
| 241 |  | 
|---|
| 242 |  | 
|---|
| 243 | /************************************************************************* | 
|---|
| 244 | *          DragFinish32                    [SHELL32.80] | 
|---|
| 245 | */ | 
|---|
| 246 | ODINPROCEDURE1(DragFinish, HDROP, h) | 
|---|
| 247 | { | 
|---|
| 248 | GlobalFree((HGLOBAL)h); | 
|---|
| 249 | } | 
|---|
| 250 |  | 
|---|
| 251 |  | 
|---|
| 252 | /************************************************************************* | 
|---|
| 253 | *          DragQueryPoint32                [SHELL32.135] | 
|---|
| 254 | */ | 
|---|
| 255 | ODINFUNCTION2(BOOL,   DragQueryPoint, | 
|---|
| 256 | HDROP,  hDrop, | 
|---|
| 257 | POINT*, p) | 
|---|
| 258 | { | 
|---|
| 259 | LPDROPFILESTRUCT lpDropFileStruct; | 
|---|
| 260 | BOOL             bRet; | 
|---|
| 261 |  | 
|---|
| 262 | lpDropFileStruct = (LPDROPFILESTRUCT) GlobalLock(hDrop); | 
|---|
| 263 |  | 
|---|
| 264 | memcpy(p,&lpDropFileStruct->ptMousePos,sizeof(POINT)); | 
|---|
| 265 | bRet = lpDropFileStruct->fInNonClientArea; | 
|---|
| 266 |  | 
|---|
| 267 | GlobalUnlock(hDrop); | 
|---|
| 268 | return bRet; | 
|---|
| 269 | } | 
|---|
| 270 |  | 
|---|
| 271 | /************************************************************************* | 
|---|
| 272 | * SHELL_FindExecutable [Internal] | 
|---|
| 273 | * | 
|---|
| 274 | * Utility for code sharing between FindExecutable and ShellExecute | 
|---|
| 275 | */ | 
|---|
| 276 | HINSTANCE SHELL_FindExecutable( LPCSTR lpFile, | 
|---|
| 277 | LPCSTR lpOperation, | 
|---|
| 278 | LPSTR lpResult) | 
|---|
| 279 | { char *extension = NULL; /* pointer to file extension */ | 
|---|
| 280 | char tmpext[5];         /* local copy to mung as we please */ | 
|---|
| 281 | char filetype[256];     /* registry name for this filetype */ | 
|---|
| 282 | LONG filetypelen=256;   /* length of above */ | 
|---|
| 283 | char command[256];      /* command from registry */ | 
|---|
| 284 | LONG commandlen=256;    /* This is the most DOS can handle :) */ | 
|---|
| 285 | char buffer[256];       /* Used to GetProfileString */ | 
|---|
| 286 | HINSTANCE retval=31;  /* default - 'No association was found' */ | 
|---|
| 287 | char *tok;              /* token pointer */ | 
|---|
| 288 | int i;                  /* random counter */ | 
|---|
| 289 | char xlpFile[256];      /* result of SearchPath */ | 
|---|
| 290 |  | 
|---|
| 291 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable(%s,%s,%08xh)\n", | 
|---|
| 292 | lpFile, | 
|---|
| 293 | lpOperation, | 
|---|
| 294 | lpResult)); | 
|---|
| 295 |  | 
|---|
| 296 | lpResult[0]='\0'; /* Start off with an empty return string */ | 
|---|
| 297 |  | 
|---|
| 298 | /* trap NULL parameters on entry */ | 
|---|
| 299 | if (( lpFile == NULL ) || ( lpResult == NULL ) || ( lpOperation == NULL )) | 
|---|
| 300 | { dprintf(("SHELL32:SHELL:SHELL_FindExecutable(lpFile=%s,lpResult=%s,lpOperation=%s): NULL parameter\n", | 
|---|
| 301 | lpFile, lpOperation, lpResult)); | 
|---|
| 302 | return 2; /* File not found. Close enough, I guess. */ | 
|---|
| 303 | } | 
|---|
| 304 |  | 
|---|
| 305 | if (SearchPathA( NULL, lpFile,".exe",sizeof(xlpFile),xlpFile,NULL)) | 
|---|
| 306 | {  dprintf(("SHELL32:SHELL:SHELL_FindExecutable(SearchPath32A returned non-zero\n")); | 
|---|
| 307 | lpFile = xlpFile; | 
|---|
| 308 | } | 
|---|
| 309 |  | 
|---|
| 310 | /* First thing we need is the file's extension */ | 
|---|
| 311 | extension = strrchr( xlpFile, '.' ); /* Assume last "." is the one; */ | 
|---|
| 312 | /* File->Run in progman uses */ | 
|---|
| 313 | /* .\FILE.EXE :( */ | 
|---|
| 314 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable(xlpFile=%s,extension=%s)\n", | 
|---|
| 315 | xlpFile, extension)); | 
|---|
| 316 |  | 
|---|
| 317 | if ((extension == NULL) || (extension == &xlpFile[strlen(xlpFile)])) | 
|---|
| 318 | { dprintf(("SHELL32:SHELL:SHELL_FindExecutable Returning 31 - No association\n")); | 
|---|
| 319 | return 31; /* no association */ | 
|---|
| 320 | } | 
|---|
| 321 |  | 
|---|
| 322 | /* Make local copy & lowercase it for reg & 'programs=' lookup */ | 
|---|
| 323 | lstrcpynA( tmpext, extension, 5 ); | 
|---|
| 324 | CharLowerA( tmpext ); | 
|---|
| 325 |  | 
|---|
| 326 |  | 
|---|
| 327 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable(%s file)\n", tmpext)); | 
|---|
| 328 |  | 
|---|
| 329 | /* Three places to check: */ | 
|---|
| 330 | /* 1. win.ini, [windows], programs (NB no leading '.') */ | 
|---|
| 331 | /* 2. Registry, HKEY_CLASS_ROOT\<filetype>\shell\open\command */ | 
|---|
| 332 | /* 3. win.ini, [extensions], extension (NB no leading '.' */ | 
|---|
| 333 | /* All I know of the order is that registry is checked before */ | 
|---|
| 334 | /* extensions; however, it'd make sense to check the programs */ | 
|---|
| 335 | /* section first, so that's what happens here. */ | 
|---|
| 336 |  | 
|---|
| 337 | /* See if it's a program - if GetProfileString fails, we skip this | 
|---|
| 338 | * section. Actually, if GetProfileString fails, we've probably | 
|---|
| 339 | * got a lot more to worry about than running a program... */ | 
|---|
| 340 | if ( GetProfileStringA("windows", "programs", "exe pif bat com", | 
|---|
| 341 | buffer, sizeof(buffer)) > 0 ) | 
|---|
| 342 | { for (i=0;i<strlen(buffer); i++) buffer[i]=tolower(buffer[i]); | 
|---|
| 343 |  | 
|---|
| 344 | tok = strtok(buffer, " \t"); /* ? */ | 
|---|
| 345 | while( tok!= NULL) | 
|---|
| 346 | { | 
|---|
| 347 | if (strcmp(tok, &tmpext[1])==0) /* have to skip the leading "." */ | 
|---|
| 348 | { | 
|---|
| 349 | strcpy(lpResult, xlpFile); | 
|---|
| 350 | /* Need to perhaps check that the file has a path | 
|---|
| 351 | * attached */ | 
|---|
| 352 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable found %s\n", | 
|---|
| 353 | lpResult)); | 
|---|
| 354 | return 33; | 
|---|
| 355 |  | 
|---|
| 356 | /* Greater than 32 to indicate success FIXME According to the | 
|---|
| 357 | * docs, I should be returning a handle for the | 
|---|
| 358 | * executable. Does this mean I'm supposed to open the | 
|---|
| 359 | * executable file or something? More RTFM, I guess... */ | 
|---|
| 360 | } | 
|---|
| 361 | tok=strtok(NULL, " \t"); | 
|---|
| 362 | } | 
|---|
| 363 | } | 
|---|
| 364 |  | 
|---|
| 365 | /* Check registry */ | 
|---|
| 366 | if (RegQueryValueA( HKEY_CLASSES_ROOT, tmpext, filetype, | 
|---|
| 367 | &filetypelen ) == ERROR_SUCCESS ) | 
|---|
| 368 | { | 
|---|
| 369 | filetype[filetypelen]='\0'; | 
|---|
| 370 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable(File type: %s)\n", | 
|---|
| 371 | filetype)); | 
|---|
| 372 |  | 
|---|
| 373 | /* Looking for ...buffer\shell\lpOperation\command */ | 
|---|
| 374 | strcat( filetype, "\\shell\\" ); | 
|---|
| 375 | strcat( filetype, lpOperation ); | 
|---|
| 376 | strcat( filetype, "\\command" ); | 
|---|
| 377 |  | 
|---|
| 378 | if (RegQueryValueA( HKEY_CLASSES_ROOT, filetype, command, | 
|---|
| 379 | &commandlen ) == ERROR_SUCCESS ) | 
|---|
| 380 | { | 
|---|
| 381 | LPSTR tmp; | 
|---|
| 382 | char param[256]; | 
|---|
| 383 | LONG paramlen = 256; | 
|---|
| 384 |  | 
|---|
| 385 | /* Get the parameters needed by the application | 
|---|
| 386 | from the associated ddeexec key */ | 
|---|
| 387 | tmp = strstr(filetype,"command"); | 
|---|
| 388 | tmp[0] = '\0'; | 
|---|
| 389 | strcat(filetype,"ddeexec"); | 
|---|
| 390 |  | 
|---|
| 391 | if(RegQueryValueA( HKEY_CLASSES_ROOT, filetype, param,¶mlen ) == ERROR_SUCCESS) | 
|---|
| 392 | { | 
|---|
| 393 | strcat(command," "); | 
|---|
| 394 | strcat(command,param); | 
|---|
| 395 | commandlen += paramlen; | 
|---|
| 396 | } | 
|---|
| 397 |  | 
|---|
| 398 | /* Is there a replace() function anywhere? */ | 
|---|
| 399 | command[commandlen]='\0'; | 
|---|
| 400 | strcpy( lpResult, command ); | 
|---|
| 401 | tok=strstr( lpResult, "%1" ); | 
|---|
| 402 | if (tok != NULL) | 
|---|
| 403 | { | 
|---|
| 404 | tok[0]='\0'; /* truncate string at the percent */ | 
|---|
| 405 | strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */ | 
|---|
| 406 | tok=strstr( command, "%1" ); | 
|---|
| 407 | if ((tok!=NULL) && (strlen(tok)>2)) | 
|---|
| 408 | { | 
|---|
| 409 | strcat( lpResult, &tok[2] ); | 
|---|
| 410 | } | 
|---|
| 411 | } | 
|---|
| 412 | retval=33; /* FIXME see above */ | 
|---|
| 413 | } | 
|---|
| 414 | } | 
|---|
| 415 | else /* Check win.ini */ | 
|---|
| 416 | { | 
|---|
| 417 | /* Toss the leading dot */ | 
|---|
| 418 | extension++; | 
|---|
| 419 | if ( GetProfileStringA( "extensions", extension, "", command, | 
|---|
| 420 | sizeof(command)) > 0) | 
|---|
| 421 | { | 
|---|
| 422 | if (strlen(command)!=0) | 
|---|
| 423 | { | 
|---|
| 424 | strcpy( lpResult, command ); | 
|---|
| 425 | tok=strstr( lpResult, "^" ); /* should be ^.extension? */ | 
|---|
| 426 | if (tok != NULL) | 
|---|
| 427 | { | 
|---|
| 428 | tok[0]='\0'; | 
|---|
| 429 | strcat( lpResult, xlpFile ); /* what if no dir in xlpFile? */ | 
|---|
| 430 | tok=strstr( command, "^" ); /* see above */ | 
|---|
| 431 | if ((tok != NULL) && (strlen(tok)>5)) | 
|---|
| 432 | { | 
|---|
| 433 | strcat( lpResult, &tok[5]); | 
|---|
| 434 | } | 
|---|
| 435 | } | 
|---|
| 436 | retval=33; /* FIXME - see above */ | 
|---|
| 437 | } | 
|---|
| 438 | } | 
|---|
| 439 | } | 
|---|
| 440 |  | 
|---|
| 441 | dprintf(("SHELL32:SHELL:SHELL_FindExecutable (returning %s)\n", lpResult)); | 
|---|
| 442 | return retval; | 
|---|
| 443 | } | 
|---|
| 444 |  | 
|---|
| 445 |  | 
|---|
| 446 | /************************************************************************* | 
|---|
| 447 | *          SHELL_GetResourceTable | 
|---|
| 448 | */ | 
|---|
| 449 | static DWORD SHELL_GetResourceTable(HFILE hFile,LPBYTE *retptr) | 
|---|
| 450 | {  IMAGE_DOS_HEADER                      mz_header; | 
|---|
| 451 | char        magic[4]; | 
|---|
| 452 | int         size; | 
|---|
| 453 |  | 
|---|
| 454 | dprintf(("SHELL32:Shell:SHELL_GetResourceTable(%08xh,%08xh)\n", | 
|---|
| 455 | hFile, | 
|---|
| 456 | retptr)); | 
|---|
| 457 |  | 
|---|
| 458 | *retptr = NULL; | 
|---|
| 459 | _llseek( hFile, 0, SEEK_SET ); | 
|---|
| 460 | if ((_lread(hFile,&mz_header,sizeof(mz_header)) != sizeof(mz_header)) || (mz_header.e_magic != IMAGE_DOS_SIGNATURE)) | 
|---|
| 461 | { /* .ICO file ? */ | 
|---|
| 462 | if (mz_header.e_cblp == 1) | 
|---|
| 463 | { /* ICONHEADER.idType, must be 1 */ | 
|---|
| 464 | *retptr = (LPBYTE)-1; | 
|---|
| 465 | return 1; | 
|---|
| 466 | } | 
|---|
| 467 | else | 
|---|
| 468 | return 0; /* failed */ | 
|---|
| 469 | } | 
|---|
| 470 | _llseek( hFile, mz_header.e_lfanew, SEEK_SET ); | 
|---|
| 471 |  | 
|---|
| 472 | if (_lread( hFile, magic, sizeof(magic) ) != sizeof(magic)) | 
|---|
| 473 | return 0; | 
|---|
| 474 |  | 
|---|
| 475 | _llseek( hFile, mz_header.e_lfanew, SEEK_SET); | 
|---|
| 476 |  | 
|---|
| 477 | if (*(DWORD*)magic  == IMAGE_NT_SIGNATURE) | 
|---|
| 478 | return IMAGE_NT_SIGNATURE; | 
|---|
| 479 |  | 
|---|
| 480 | if (*(WORD*)magic == IMAGE_OS2_SIGNATURE) | 
|---|
| 481 | { | 
|---|
| 482 | IMAGE_OS2_HEADER                    ne_header; | 
|---|
| 483 | LPBYTE    pTypeInfo = (LPBYTE)-1; | 
|---|
| 484 |  | 
|---|
| 485 | if (_lread(hFile,&ne_header,sizeof(ne_header))!=sizeof(ne_header)) | 
|---|
| 486 | return 0; | 
|---|
| 487 |  | 
|---|
| 488 | if (ne_header.ne_magic != IMAGE_OS2_SIGNATURE) | 
|---|
| 489 | return 0; | 
|---|
| 490 |  | 
|---|
| 491 | size = ne_header.rname_tab_offset - ne_header.resource_tab_offset; | 
|---|
| 492 |  | 
|---|
| 493 | if( size > sizeof(NE_TYPEINFO) ) | 
|---|
| 494 | { | 
|---|
| 495 | pTypeInfo = (BYTE*)HeapAlloc( GetProcessHeap(), 0, size); | 
|---|
| 496 | if( pTypeInfo ) | 
|---|
| 497 | { | 
|---|
| 498 | _llseek(hFile, mz_header.e_lfanew+ne_header.resource_tab_offset, SEEK_SET); | 
|---|
| 499 | if( _lread( hFile, (char*)pTypeInfo, size) != size ) | 
|---|
| 500 | { | 
|---|
| 501 | HeapFree( GetProcessHeap(), 0, pTypeInfo); | 
|---|
| 502 | pTypeInfo = NULL; | 
|---|
| 503 | } | 
|---|
| 504 | } | 
|---|
| 505 | } | 
|---|
| 506 |  | 
|---|
| 507 | *retptr = pTypeInfo; | 
|---|
| 508 | return IMAGE_OS2_SIGNATURE; | 
|---|
| 509 | } | 
|---|
| 510 | return 0; /* failed */ | 
|---|
| 511 | } | 
|---|
| 512 | #if 0 //CB: DirectResAlloc16 not yet ported | 
|---|
| 513 | /************************************************************************* | 
|---|
| 514 | *                      SHELL_LoadResource | 
|---|
| 515 | */ | 
|---|
| 516 | static HGLOBAL SHELL_LoadResource(HINSTANCE hInst, HFILE hFile, NE_NAMEINFO* pNInfo, WORD sizeShift) | 
|---|
| 517 | {       BYTE*  ptr; | 
|---|
| 518 | HGLOBAL handle = DirectResAlloc( hInst, 0x10, (DWORD)pNInfo->length << sizeShift); | 
|---|
| 519 |  | 
|---|
| 520 | TRACE("\n"); | 
|---|
| 521 |  | 
|---|
| 522 | if( (ptr = (BYTE*)GlobalLock( handle )) ) | 
|---|
| 523 | { _llseek( hFile, (DWORD)pNInfo->offset << sizeShift, SEEK_SET); | 
|---|
| 524 | _lread( hFile, (char*)ptr, pNInfo->length << sizeShift); | 
|---|
| 525 | return handle; | 
|---|
| 526 | } | 
|---|
| 527 | return 0; | 
|---|
| 528 | } | 
|---|
| 529 |  | 
|---|
| 530 | /************************************************************************* | 
|---|
| 531 | *                      ICO_LoadIcon | 
|---|
| 532 | */ | 
|---|
| 533 | static HGLOBAL ICO_LoadIcon(HINSTANCE hInst, HFILE hFile, LPicoICONDIRENTRY lpiIDE) | 
|---|
| 534 | {       BYTE*  ptr; | 
|---|
| 535 | HGLOBAL handle = DirectResAlloc( hInst, 0x10, lpiIDE->dwBytesInRes); | 
|---|
| 536 | TRACE("\n"); | 
|---|
| 537 | if( (ptr = (BYTE*)GlobalLock( handle )) ) | 
|---|
| 538 | { _llseek( hFile, lpiIDE->dwImageOffset, SEEK_SET); | 
|---|
| 539 | _lread( hFile, (char*)ptr, lpiIDE->dwBytesInRes); | 
|---|
| 540 | return handle; | 
|---|
| 541 | } | 
|---|
| 542 | return 0; | 
|---|
| 543 | } | 
|---|
| 544 |  | 
|---|
| 545 | /************************************************************************* | 
|---|
| 546 | *                      ICO_GetIconDirectory | 
|---|
| 547 | * | 
|---|
| 548 | *  Read .ico file and build phony ICONDIR struct for GetIconID | 
|---|
| 549 | */ | 
|---|
| 550 | static HGLOBAL ICO_GetIconDirectory(HINSTANCE hInst, HFILE hFile, LPicoICONDIR* lplpiID ) | 
|---|
| 551 | { WORD    id[3];  /* idReserved, idType, idCount */ | 
|---|
| 552 | LPicoICONDIR  lpiID; | 
|---|
| 553 | int           i; | 
|---|
| 554 |  | 
|---|
| 555 | TRACE("\n"); | 
|---|
| 556 | _llseek( hFile, 0, SEEK_SET ); | 
|---|
| 557 | if( _lread(hFile,(char*)id,sizeof(id)) != sizeof(id) ) return 0; | 
|---|
| 558 |  | 
|---|
| 559 | /* check .ICO header | 
|---|
| 560 | * | 
|---|
| 561 | * - see http://www.microsoft.com/win32dev/ui/icons.htm | 
|---|
| 562 | */ | 
|---|
| 563 |  | 
|---|
| 564 | if( id[0] || id[1] != 1 || !id[2] ) return 0; | 
|---|
| 565 |  | 
|---|
| 566 | i = id[2]*sizeof(icoICONDIRENTRY) ; | 
|---|
| 567 |  | 
|---|
| 568 | lpiID = (LPicoICONDIR)HeapAlloc( GetProcessHeap(), 0, i + sizeof(id)); | 
|---|
| 569 |  | 
|---|
| 570 | if( _lread(hFile,(char*)lpiID->idEntries,i) == i ) | 
|---|
| 571 | { HGLOBAL handle = DirectResAlloc( hInst, 0x10, | 
|---|
| 572 | id[2]*sizeof(CURSORICONDIRENTRY) + sizeof(id) ); | 
|---|
| 573 | if( handle ) | 
|---|
| 574 | { CURSORICONDIR*     lpID = (CURSORICONDIR*)GlobalLock( handle ); | 
|---|
| 575 | lpID->idReserved = lpiID->idReserved = id[0]; | 
|---|
| 576 | lpID->idType = lpiID->idType = id[1]; | 
|---|
| 577 | lpID->idCount = lpiID->idCount = id[2]; | 
|---|
| 578 | for( i=0; i < lpiID->idCount; i++ ) | 
|---|
| 579 | { memcpy((void*)(lpID->idEntries + i), | 
|---|
| 580 | (void*)(lpiID->idEntries + i), sizeof(CURSORICONDIRENTRY) - 2); | 
|---|
| 581 | lpID->idEntries[i].wResId = i; | 
|---|
| 582 | } | 
|---|
| 583 | *lplpiID = lpiID; | 
|---|
| 584 | return handle; | 
|---|
| 585 | } | 
|---|
| 586 | } | 
|---|
| 587 | /* fail */ | 
|---|
| 588 |  | 
|---|
| 589 | HeapFree( GetProcessHeap(), 0, lpiID); | 
|---|
| 590 | return 0; | 
|---|
| 591 | } | 
|---|
| 592 | #endif | 
|---|
| 593 | /************************************************************************* | 
|---|
| 594 | *                      InternalExtractIcon             [SHELL.39] | 
|---|
| 595 | * | 
|---|
| 596 | * This abortion is called directly by Progman | 
|---|
| 597 | */ | 
|---|
| 598 | HGLOBAL WINAPI InternalExtractIcon(HINSTANCE hInstance, | 
|---|
| 599 | LPCSTR lpszExeFileName, UINT nIconIndex, WORD n ) | 
|---|
| 600 | {       HGLOBAL hRet = 0; | 
|---|
| 601 | HGLOBAL*        RetPtr = NULL; | 
|---|
| 602 | LPBYTE          pData; | 
|---|
| 603 | OFSTRUCT        ofs; | 
|---|
| 604 | DWORD           sig; | 
|---|
| 605 | HFILE           hFile = OpenFile( lpszExeFileName, &ofs, OF_READ ); | 
|---|
| 606 | UINT            iconDirCount = 0,iconCount = 0; | 
|---|
| 607 | LPBYTE          peimage; | 
|---|
| 608 | HANDLE  fmapping; | 
|---|
| 609 |  | 
|---|
| 610 | TRACE("(%04x,file %s,start %d,extract %d\n", | 
|---|
| 611 | hInstance, lpszExeFileName, nIconIndex, n); | 
|---|
| 612 |  | 
|---|
| 613 | if( hFile == HFILE_ERROR || !n ) | 
|---|
| 614 | return 0; | 
|---|
| 615 |  | 
|---|
| 616 | hRet = GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, sizeof(HICON16)*n); | 
|---|
| 617 | RetPtr = (HGLOBAL*)GlobalLock(hRet); | 
|---|
| 618 |  | 
|---|
| 619 | *RetPtr = (n == 0xFFFF)? 0: 1;  /* error return values */ | 
|---|
| 620 |  | 
|---|
| 621 | sig = SHELL_GetResourceTable(hFile,&pData); | 
|---|
| 622 | #if 0 //CB: some functions not (yet) supported | 
|---|
| 623 | if( sig==IMAGE_OS2_SIGNATURE || sig==1 ) /* .ICO file */ | 
|---|
| 624 | { HICON  hIcon = 0; | 
|---|
| 625 | NE_TYPEINFO* pTInfo = (NE_TYPEINFO*)(pData + 2); | 
|---|
| 626 | NE_NAMEINFO* pIconStorage = NULL; | 
|---|
| 627 | NE_NAMEINFO* pIconDir = NULL; | 
|---|
| 628 | LPicoICONDIR lpiID = NULL; | 
|---|
| 629 |  | 
|---|
| 630 | if( pData == (BYTE*)-1 ) | 
|---|
| 631 | { hIcon = ICO_GetIconDirectory(hInstance, hFile, &lpiID);     /* check for .ICO file */ | 
|---|
| 632 | if( hIcon ) | 
|---|
| 633 | { iconDirCount = 1; iconCount = lpiID->idCount; | 
|---|
| 634 | } | 
|---|
| 635 | } | 
|---|
| 636 | else while( pTInfo->type_id && !(pIconStorage && pIconDir) ) | 
|---|
| 637 | { if( pTInfo->type_id == NE_RSCTYPE_GROUP_ICON )      /* find icon directory and icon repository */ | 
|---|
| 638 | { iconDirCount = pTInfo->count; | 
|---|
| 639 | pIconDir = ((NE_NAMEINFO*)(pTInfo + 1)); | 
|---|
| 640 | TRACE("\tfound directory - %i icon families\n", iconDirCount); | 
|---|
| 641 | } | 
|---|
| 642 | if( pTInfo->type_id == NE_RSCTYPE_ICON ) | 
|---|
| 643 | { iconCount = pTInfo->count; | 
|---|
| 644 | pIconStorage = ((NE_NAMEINFO*)(pTInfo + 1)); | 
|---|
| 645 | TRACE("\ttotal icons - %i\n", iconCount); | 
|---|
| 646 | } | 
|---|
| 647 | pTInfo = (NE_TYPEINFO *)((char*)(pTInfo+1)+pTInfo->count*sizeof(NE_NAMEINFO)); | 
|---|
| 648 | } | 
|---|
| 649 |  | 
|---|
| 650 | /* load resources and create icons */ | 
|---|
| 651 |  | 
|---|
| 652 | if( (pIconStorage && pIconDir) || lpiID ) | 
|---|
| 653 | { if( nIconIndex == (UINT16)-1 ) | 
|---|
| 654 | { RetPtr[0] = iconDirCount; | 
|---|
| 655 | } | 
|---|
| 656 | else if( nIconIndex < iconDirCount ) | 
|---|
| 657 | { UINT   i, icon; | 
|---|
| 658 | if( n > iconDirCount - nIconIndex ) | 
|---|
| 659 | n = iconDirCount - nIconIndex; | 
|---|
| 660 |  | 
|---|
| 661 | for( i = nIconIndex; i < nIconIndex + n; i++ ) | 
|---|
| 662 | { /* .ICO files have only one icon directory */ | 
|---|
| 663 |  | 
|---|
| 664 | if( lpiID == NULL ) | 
|---|
| 665 | hIcon = SHELL_LoadResource( hInstance, hFile, pIconDir + i, *(WORD*)pData ); | 
|---|
| 666 | RetPtr[i-nIconIndex] = GetIconID( hIcon, 3 ); | 
|---|
| 667 | GlobalFree(hIcon); | 
|---|
| 668 | } | 
|---|
| 669 |  | 
|---|
| 670 | for( icon = nIconIndex; icon < nIconIndex + n; icon++ ) | 
|---|
| 671 | { hIcon = 0; | 
|---|
| 672 | if( lpiID ) | 
|---|
| 673 | { hIcon = ICO_LoadIcon( hInstance, hFile, lpiID->idEntries + RetPtr[icon-nIconIndex]); | 
|---|
| 674 | } | 
|---|
| 675 | else | 
|---|
| 676 | { for( i = 0; i < iconCount; i++ ) | 
|---|
| 677 | { if( pIconStorage[i].id == (RetPtr[icon-nIconIndex] | 0x8000) ) | 
|---|
| 678 | { hIcon = SHELL_LoadResource( hInstance, hFile, pIconStorage + i,*(WORD*)pData ); | 
|---|
| 679 | } | 
|---|
| 680 | } | 
|---|
| 681 | } | 
|---|
| 682 | if( hIcon ) | 
|---|
| 683 | { RetPtr[icon-nIconIndex] = LoadIconHandler16( hIcon, TRUE ); | 
|---|
| 684 | FarSetOwner16( RetPtr[icon-nIconIndex], GetExePtr(hInstance) ); | 
|---|
| 685 | } | 
|---|
| 686 | else | 
|---|
| 687 | { RetPtr[icon-nIconIndex] = 0; | 
|---|
| 688 | } | 
|---|
| 689 | } | 
|---|
| 690 | } | 
|---|
| 691 | } | 
|---|
| 692 | if( lpiID ) | 
|---|
| 693 | HeapFree( GetProcessHeap(), 0, lpiID); | 
|---|
| 694 | else | 
|---|
| 695 | HeapFree( GetProcessHeap(), 0, pData); | 
|---|
| 696 | } | 
|---|
| 697 | #endif | 
|---|
| 698 | if( sig == IMAGE_NT_SIGNATURE) | 
|---|
| 699 | { LPBYTE                idata,igdata; | 
|---|
| 700 | PIMAGE_DOS_HEADER     dheader; | 
|---|
| 701 | PIMAGE_NT_HEADERS     pe_header; | 
|---|
| 702 | PIMAGE_SECTION_HEADER pe_sections; | 
|---|
| 703 | PIMAGE_RESOURCE_DIRECTORY     rootresdir,iconresdir,icongroupresdir; | 
|---|
| 704 | PIMAGE_RESOURCE_DATA_ENTRY    idataent,igdataent; | 
|---|
| 705 | int                   i,j; | 
|---|
| 706 | PIMAGE_RESOURCE_DIRECTORY_ENTRY       xresent; | 
|---|
| 707 | CURSORICONDIR         **cids; | 
|---|
| 708 |  | 
|---|
| 709 | fmapping = CreateFileMappingA(hFile,NULL,PAGE_READONLY|SEC_COMMIT,0,0,NULL); | 
|---|
| 710 | if (fmapping == 0) | 
|---|
| 711 | { /* FIXME, INVALID_HANDLE_VALUE? */ | 
|---|
| 712 | WARN("failed to create filemap.\n"); | 
|---|
| 713 | hRet = 0; | 
|---|
| 714 | goto end_2; /* failure */ | 
|---|
| 715 | } | 
|---|
| 716 | peimage = (BYTE*)MapViewOfFile(fmapping,FILE_MAP_READ,0,0,0); | 
|---|
| 717 | if (!peimage) | 
|---|
| 718 | { WARN("failed to mmap filemap.\n"); | 
|---|
| 719 | hRet = 0; | 
|---|
| 720 | goto end_2; /* failure */ | 
|---|
| 721 | } | 
|---|
| 722 | dheader = (PIMAGE_DOS_HEADER)peimage; | 
|---|
| 723 |  | 
|---|
| 724 | /* it is a pe header, SHELL_GetResourceTable checked that */ | 
|---|
| 725 | pe_header = (PIMAGE_NT_HEADERS)(peimage+dheader->e_lfanew); | 
|---|
| 726 |  | 
|---|
| 727 | /* probably makes problems with short PE headers... but I haven't seen | 
|---|
| 728 | * one yet... | 
|---|
| 729 | */ | 
|---|
| 730 | pe_sections = (PIMAGE_SECTION_HEADER)(((char*)pe_header)+sizeof(*pe_header)); | 
|---|
| 731 | rootresdir = NULL; | 
|---|
| 732 |  | 
|---|
| 733 | for (i=0;i<pe_header->FileHeader.NumberOfSections;i++) | 
|---|
| 734 | { if (pe_sections[i].Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) | 
|---|
| 735 | continue; | 
|---|
| 736 | /* FIXME: doesn't work when the resources are not in a seperate section */ | 
|---|
| 737 | if (pe_sections[i].VirtualAddress == pe_header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress) | 
|---|
| 738 | { rootresdir = (PIMAGE_RESOURCE_DIRECTORY)((char*)peimage+pe_sections[i].PointerToRawData); | 
|---|
| 739 | break; | 
|---|
| 740 | } | 
|---|
| 741 | } | 
|---|
| 742 |  | 
|---|
| 743 | if (!rootresdir) | 
|---|
| 744 | { WARN("haven't found section for resource directory.\n"); | 
|---|
| 745 | goto end_4; /* failure */ | 
|---|
| 746 | } | 
|---|
| 747 |  | 
|---|
| 748 | icongroupresdir = GetResDirEntryW(rootresdir,RT_GROUP_ICONW, (DWORD)rootresdir,FALSE); | 
|---|
| 749 |  | 
|---|
| 750 | if (!icongroupresdir) | 
|---|
| 751 | { WARN("No Icongroupresourcedirectory!\n"); | 
|---|
| 752 | goto end_4; /* failure */ | 
|---|
| 753 | } | 
|---|
| 754 |  | 
|---|
| 755 | iconDirCount = icongroupresdir->NumberOfNamedEntries+icongroupresdir->NumberOfIdEntries; | 
|---|
| 756 |  | 
|---|
| 757 | if( nIconIndex == (UINT)-1 ) | 
|---|
| 758 | { RetPtr[0] = iconDirCount; | 
|---|
| 759 | goto end_3; /* success */ | 
|---|
| 760 | } | 
|---|
| 761 |  | 
|---|
| 762 | if (nIconIndex >= iconDirCount) | 
|---|
| 763 | { WARN("nIconIndex %d is larger than iconDirCount %d\n",nIconIndex,iconDirCount); | 
|---|
| 764 | GlobalFree(hRet); | 
|---|
| 765 | goto end_4; /* failure */ | 
|---|
| 766 | } | 
|---|
| 767 |  | 
|---|
| 768 | cids = (CURSORICONDIR**)HeapAlloc(GetProcessHeap(),0,n*sizeof(CURSORICONDIR*)); | 
|---|
| 769 |  | 
|---|
| 770 | /* caller just wanted the number of entries */ | 
|---|
| 771 | xresent = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(icongroupresdir+1); | 
|---|
| 772 |  | 
|---|
| 773 | /* assure we don't get too much ... */ | 
|---|
| 774 | if( n > iconDirCount - nIconIndex ) | 
|---|
| 775 | { n = iconDirCount - nIconIndex; | 
|---|
| 776 | } | 
|---|
| 777 |  | 
|---|
| 778 | /* starting from specified index ... */ | 
|---|
| 779 | xresent = xresent+nIconIndex; | 
|---|
| 780 |  | 
|---|
| 781 | for (i=0;i<n;i++,xresent++) | 
|---|
| 782 | { CURSORICONDIR       *cid; | 
|---|
| 783 | PIMAGE_RESOURCE_DIRECTORY   resdir; | 
|---|
| 784 |  | 
|---|
| 785 | /* go down this resource entry, name */ | 
|---|
| 786 | resdir = (PIMAGE_RESOURCE_DIRECTORY)((DWORD)rootresdir+(xresent->u2.s.OffsetToDirectory)); | 
|---|
| 787 |  | 
|---|
| 788 | /* default language (0) */ | 
|---|
| 789 | resdir = GetResDirEntryW(resdir,(LPWSTR)0,(DWORD)rootresdir,TRUE); | 
|---|
| 790 | igdataent = (PIMAGE_RESOURCE_DATA_ENTRY)resdir; | 
|---|
| 791 |  | 
|---|
| 792 | /* lookup address in mapped image for virtual address */ | 
|---|
| 793 | igdata = NULL; | 
|---|
| 794 |  | 
|---|
| 795 | for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) | 
|---|
| 796 | { if (igdataent->OffsetToData < pe_sections[j].VirtualAddress) | 
|---|
| 797 | continue; | 
|---|
| 798 | if (igdataent->OffsetToData+igdataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData) | 
|---|
| 799 | continue; | 
|---|
| 800 | igdata = peimage+(igdataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData); | 
|---|
| 801 | } | 
|---|
| 802 |  | 
|---|
| 803 | if (!igdata) | 
|---|
| 804 | { WARN("no matching real address for icongroup!\n"); | 
|---|
| 805 | goto end_4;       /* failure */ | 
|---|
| 806 | } | 
|---|
| 807 | /* found */ | 
|---|
| 808 | cid = (CURSORICONDIR*)igdata; | 
|---|
| 809 | cids[i] = cid; | 
|---|
| 810 | RetPtr[i] = LookupIconIdFromDirectoryEx(igdata,TRUE,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0); | 
|---|
| 811 | } | 
|---|
| 812 |  | 
|---|
| 813 | iconresdir=GetResDirEntryW(rootresdir,RT_ICONW,(DWORD)rootresdir,FALSE); | 
|---|
| 814 |  | 
|---|
| 815 | if (!iconresdir) | 
|---|
| 816 | { WARN("No Iconresourcedirectory!\n"); | 
|---|
| 817 | goto end_4; /* failure */ | 
|---|
| 818 | } | 
|---|
| 819 |  | 
|---|
| 820 | for (i=0;i<n;i++) | 
|---|
| 821 | { PIMAGE_RESOURCE_DIRECTORY   xresdir; | 
|---|
| 822 | xresdir = GetResDirEntryW(iconresdir,(LPWSTR)(DWORD)RetPtr[i],(DWORD)rootresdir,FALSE); | 
|---|
| 823 | xresdir = GetResDirEntryW(xresdir,(LPWSTR)0,(DWORD)rootresdir,TRUE); | 
|---|
| 824 | idataent = (PIMAGE_RESOURCE_DATA_ENTRY)xresdir; | 
|---|
| 825 | idata = NULL; | 
|---|
| 826 |  | 
|---|
| 827 | /* map virtual to address in image */ | 
|---|
| 828 | for (j=0;j<pe_header->FileHeader.NumberOfSections;j++) | 
|---|
| 829 | { if (idataent->OffsetToData < pe_sections[j].VirtualAddress) | 
|---|
| 830 | continue; | 
|---|
| 831 | if (idataent->OffsetToData+idataent->Size > pe_sections[j].VirtualAddress+pe_sections[j].SizeOfRawData) | 
|---|
| 832 | continue; | 
|---|
| 833 | idata = peimage+(idataent->OffsetToData-pe_sections[j].VirtualAddress+pe_sections[j].PointerToRawData); | 
|---|
| 834 | } | 
|---|
| 835 | if (!idata) | 
|---|
| 836 | { WARN("no matching real address found for icondata!\n"); | 
|---|
| 837 | RetPtr[i]=0; | 
|---|
| 838 | continue; | 
|---|
| 839 | } | 
|---|
| 840 | RetPtr[i] = CreateIconFromResourceEx(idata,idataent->Size,TRUE,0x00030000,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON),0); | 
|---|
| 841 | } | 
|---|
| 842 | goto end_3;   /* sucess */ | 
|---|
| 843 | } | 
|---|
| 844 | goto end_1;     /* return array with icon handles */ | 
|---|
| 845 |  | 
|---|
| 846 | /* cleaning up (try & catch would be nicer) */ | 
|---|
| 847 | end_4:  hRet = 0;       /* failure */ | 
|---|
| 848 | end_3:  UnmapViewOfFile(peimage);       /* success */ | 
|---|
| 849 | end_2:  CloseHandle(fmapping); | 
|---|
| 850 | end_1:  _lclose( hFile); | 
|---|
| 851 | return hRet; | 
|---|
| 852 | } | 
|---|
| 853 |  | 
|---|
| 854 | /************************************************************************* | 
|---|
| 855 | *          ExtractAssociatedIcon        [SHELL.36] | 
|---|
| 856 | * | 
|---|
| 857 | * Return icon for given file (either from file itself or from associated | 
|---|
| 858 | * executable) and patch parameters if needed. | 
|---|
| 859 | */ | 
|---|
| 860 | ODINFUNCTION3(HICON,     ExtractAssociatedIconA, | 
|---|
| 861 | HINSTANCE, hInst, | 
|---|
| 862 | LPSTR,     lpIconPath, | 
|---|
| 863 | LPWORD,    lpiIcon) | 
|---|
| 864 | { | 
|---|
| 865 | HICON hIcon; | 
|---|
| 866 |  | 
|---|
| 867 | hIcon = ExtractIconA(hInst, lpIconPath, *lpiIcon); | 
|---|
| 868 |  | 
|---|
| 869 | if( hIcon < 2 ) | 
|---|
| 870 | { if( hIcon == 1 ) /* no icons found in given file */ | 
|---|
| 871 | { char  tempPath[0x104]; | 
|---|
| 872 | UINT  uRet = FindExecutableA(lpIconPath,NULL,tempPath); | 
|---|
| 873 |  | 
|---|
| 874 | if( uRet > 32 && tempPath[0] ) | 
|---|
| 875 | { strcpy(lpIconPath,tempPath); | 
|---|
| 876 | hIcon = ExtractIconA(hInst, lpIconPath, *lpiIcon); | 
|---|
| 877 | if( hIcon > 2 ) | 
|---|
| 878 | return hIcon; | 
|---|
| 879 | } | 
|---|
| 880 | else hIcon = 0; | 
|---|
| 881 | } | 
|---|
| 882 |  | 
|---|
| 883 | if( hIcon == 1 ) | 
|---|
| 884 | *lpiIcon = 2;   /* MSDOS icon - we found .exe but no icons in it */ | 
|---|
| 885 | else | 
|---|
| 886 | *lpiIcon = 6;   /* generic icon - found nothing */ | 
|---|
| 887 |  | 
|---|
| 888 | GetModuleFileNameA(hInst, lpIconPath, 0x80); | 
|---|
| 889 | hIcon = LoadIconA( hInst, (LPCSTR)*lpiIcon); | 
|---|
| 890 | } | 
|---|
| 891 | return hIcon; | 
|---|
| 892 | } | 
|---|
| 893 |  | 
|---|