Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

rtlres.c File Reference

#include "precomp.h"

Go to the source code of this file.

Defines

#define BITMAPFILEHEADER_SIZE   14
#define MINHEADERS_SIZE   (BITMAPFILEHEADER_SIZE + sizeof(BITMAPCOREHEADER))

Functions

HICON IconFromBestImage (ICONFILEHEADER *pifh, LPNEWHEADER lpnhSrc, int cxDesired, int cyDesired, UINT LR_flags)
int LoadStringOrError (HANDLE hModule, UINT wID, LPWSTR lpBuffer, int cchBufferMax, WORD wLangId)
HANDLE RtlLoadObjectFromDIBFile (LPCWSTR lpszName, LPWSTR type, DWORD cxDesired, DWORD cyDesired, UINT LR_flags)


Define Documentation

#define BITMAPFILEHEADER_SIZE   14
 

Definition at line 139 of file rtlres.c.

Referenced by RtlLoadObjectFromDIBFile().

#define MINHEADERS_SIZE   (BITMAPFILEHEADER_SIZE + sizeof(BITMAPCOREHEADER))
 

Definition at line 140 of file rtlres.c.

Referenced by RtlLoadObjectFromDIBFile().


Function Documentation

HICON IconFromBestImage ICONFILEHEADER *  pifh,
LPNEWHEADER  lpnhSrc,
int  cxDesired,
int  cyDesired,
UINT  LR_flags
 

Definition at line 396 of file rtlres.c.

References CreateIconFromResourceEx(), DWORD, gpsi, LookupIconIdFromDirectoryEx(), NULL, PBYTE, UINT, UserLocalAlloc, and UserLocalFree.

Referenced by RtlLoadObjectFromDIBFile().

00402 { 00403 UINT iImage; 00404 UINT iImageBest; 00405 LPNEWHEADER lpnhDst; 00406 LPRESDIR lprd; 00407 LPBYTE lpRes; 00408 DWORD cbDIB; 00409 HICON hIcon = NULL; 00410 IMAGEFILEHEADER *pimh; 00411 00412 if (lpnhSrc->ResCount > 1) { 00413 00414 /* 00415 * First, alloc dummy group resource. 00416 */ 00417 lpnhDst = (LPNEWHEADER)UserLocalAlloc(0, 00418 sizeof(NEWHEADER) + (lpnhSrc->ResCount * sizeof(RESDIR))); 00419 00420 if (lpnhDst == NULL) 00421 goto Done; 00422 00423 *lpnhDst = *lpnhSrc; 00424 lprd = (LPRESDIR)(lpnhDst + 1); 00425 00426 /* 00427 * Build up an image directory from the file's image header info. 00428 */ 00429 00430 for (pimh = pifh->imh, iImage=0; 00431 iImage < lpnhDst->ResCount; 00432 iImage++, lprd++, pimh++) { 00433 00434 /* 00435 * Fill in RESDIR 00436 */ 00437 lprd->Icon.Width = pimh->cx; 00438 lprd->Icon.Height = pimh->cy; 00439 00440 if (lpnhDst->ResType == IMAGE_ICON) 00441 lprd->Icon.ColorCount = pimh->nColors; 00442 00443 /* 00444 * NOTE: These aren't used in the "GetBestImage" process. So 00445 * stick in random stuff. 00446 */ 00447 lprd->Planes = gpsi->Planes; 00448 lprd->BitCount = gpsi->BitCount; 00449 lprd->BytesInRes = pimh->cbDIB; 00450 00451 /* 00452 * Make fake ID: the index of the image. 00453 */ 00454 lprd->idIcon = (WORD)iImage; 00455 } 00456 00457 /* 00458 * Find the best image in the group 00459 */ 00460 iImageBest = LookupIconIdFromDirectoryEx((PBYTE)lpnhDst, 00461 (lpnhDst->ResType == IMAGE_ICON), 00462 cxDesired, 00463 cyDesired, 00464 LR_flags); 00465 /* 00466 * Get rid of fake group resource 00467 */ 00468 UserLocalFree(lpnhDst); 00469 00470 } else { 00471 iImageBest = 0; 00472 } 00473 00474 /* 00475 * Point to selected image. 00476 */ 00477 pimh = &pifh->imh[iImageBest]; 00478 cbDIB = pimh->cbDIB; 00479 00480 /* 00481 * If we're creating a cursor, we have to whack in HOTSPOT in front 00482 * Regardless of which type we are making, we need to make sure 00483 * the resource is aligned. Thus we always copy. 00484 */ 00485 if (lpnhSrc->ResType == IMAGE_CURSOR) 00486 cbDIB += sizeof(POINTS); 00487 00488 lpRes = (LPBYTE)UserLocalAlloc(0, cbDIB); 00489 if (lpRes == NULL) 00490 goto Done; 00491 00492 if (lpnhSrc->ResType == IMAGE_CURSOR) 00493 lpRes += sizeof(POINTS); 00494 00495 RtlCopyMemory(lpRes, 00496 ((LPBYTE)pifh) + pimh->offsetDIB, 00497 pimh->cbDIB); 00498 00499 if (lpnhSrc->ResType == IMAGE_CURSOR) { 00500 00501 lpRes -= sizeof(POINTS); 00502 ((LPPOINTS)lpRes)->x = pimh->xHotSpot; 00503 ((LPPOINTS)lpRes)->y = pimh->yHotSpot; 00504 } 00505 00506 hIcon = CreateIconFromResourceEx(lpRes, 00507 cbDIB, 00508 (lpnhSrc->ResType == IMAGE_ICON), 00509 0x00030000, // was WIN32VER40 00510 cxDesired, 00511 cyDesired, 00512 LR_flags); 00513 00514 UserLocalFree(lpRes); 00515 00516 Done: 00517 00518 return hIcon; 00519 }

int LoadStringOrError HANDLE  hModule,
UINT  wID,
LPWSTR  lpBuffer,
int  cchBufferMax,
WORD  wLangId
 

Definition at line 37 of file rtlres.c.

References FINDRESOURCEEXW, LOADRESOURCE, LOCKRESOURCE, NULL, TRUE, UNLOCKRESOURCE, USHORT, and UTCHAR.

00043 { 00044 HANDLE hResInfo; 00045 HANDLE hStringSeg; 00046 LPTSTR lpsz; 00047 int cch; 00048 00049 /* 00050 * Make sure the parms are valid. 00051 */ 00052 if (lpBuffer == NULL) { 00053 RIPMSG0(RIP_WARNING, "LoadStringOrError: lpBuffer == NULL"); 00054 return 0; 00055 } 00056 00057 00058 cch = 0; 00059 00060 /* 00061 * String Tables are broken up into 16 string segments. Find the segment 00062 * containing the string we are interested in. 00063 */ 00064 if (hResInfo = FINDRESOURCEEXW(hModule, (LPTSTR)ULongToPtr( ((LONG)(((USHORT)wID >> 4) + 1)) ), RT_STRING, wLangId)) { 00065 00066 /* 00067 * Load that segment. 00068 */ 00069 hStringSeg = LOADRESOURCE(hModule, hResInfo); 00070 00071 /* 00072 * Lock the resource. 00073 */ 00074 if (lpsz = (LPTSTR)LOCKRESOURCE(hStringSeg, hModule)) { 00075 00076 /* 00077 * Move past the other strings in this segment. 00078 * (16 strings in a segment -> & 0x0F) 00079 */ 00080 wID &= 0x0F; 00081 while (TRUE) { 00082 cch = *((UTCHAR *)lpsz++); // PASCAL like string count 00083 // first UTCHAR is count if TCHARs 00084 if (wID-- == 0) break; 00085 lpsz += cch; // Step to start if next string 00086 } 00087 00088 /* 00089 * chhBufferMax == 0 means return a pointer to the read-only resource buffer. 00090 */ 00091 if (cchBufferMax == 0) { 00092 *(LPTSTR *)lpBuffer = lpsz; 00093 } else { 00094 00095 /* 00096 * Account for the NULL 00097 */ 00098 cchBufferMax--; 00099 00100 /* 00101 * Don't copy more than the max allowed. 00102 */ 00103 if (cch > cchBufferMax) 00104 cch = cchBufferMax; 00105 00106 /* 00107 * Copy the string into the buffer. 00108 */ 00109 RtlCopyMemory(lpBuffer, lpsz, cch*sizeof(WCHAR)); 00110 } 00111 00112 /* 00113 * Unlock resource, but don't free it - better performance this 00114 * way. 00115 */ 00116 UNLOCKRESOURCE(hStringSeg, hModule); 00117 } 00118 } 00119 00120 /* 00121 * Append a NULL. 00122 */ 00123 if (cchBufferMax != 0) { 00124 lpBuffer[cch] = 0; 00125 } 00126 00127 return cch; 00128 }

HANDLE RtlLoadObjectFromDIBFile LPCWSTR  lpszName,
LPWSTR  type,
DWORD  cxDesired,
DWORD  cyDesired,
UINT  LR_flags
 

Definition at line 142 of file rtlres.c.

References BFT_BITMAP, BITMAPFILEHEADER_SIZE, BitmapSize, BOOL, ConvertDIBBitmap(), cy, DWORD, FALSE, FILEINFO, IconFromBestImage(), INVALID_HANDLE_VALUE, LoadCursorIconFromFileMap(), MAX_PATH, MINHEADERS_SIZE, NULL, OPEN_EXISTING, _FILEINFO::pFileEnd, _FILEINFO::pFileMap, _FILEINFO::pFilePtr, _FILEINFO::pszName, PTR_TO_ID, szFile, type, UPBITMAPCOREHEADER, and UPBITMAPINFOHEADER.

Referenced by ObjectFromDIBResource().

00148 { 00149 FILEINFO fi = { NULL, NULL, NULL }; 00150 HANDLE hFile; 00151 HANDLE hFileMap = NULL; 00152 HANDLE hObj = NULL; 00153 TCHAR szFile[MAX_PATH]; 00154 TCHAR szFile2[MAX_PATH]; 00155 LPWSTR pszFileDummy; 00156 00157 if (LR_flags & LR_ENVSUBST) { 00158 00159 /* 00160 * Do any %% string substitutions. We need this feature to handle 00161 * loading custom cursors and icons from the registry which uses 00162 * %SystemRoot% in the paths. It also makes the shell's job 00163 * easier. 00164 */ 00165 ExpandEnvironmentStrings(lpszName, szFile2, MAX_PATH); 00166 00167 } else { 00168 00169 lstrcpy(szFile2, lpszName); 00170 } 00171 00172 if (SearchPath(NULL, // use default search locations 00173 szFile2, // file name to search for 00174 NULL, // already have file name extension 00175 MAX_PATH, // how big is that buffer, anyway? 00176 szFile, // stick fully qualified path name here 00177 &pszFileDummy) == 0) { 00178 RIPERR0(ERROR_FILE_NOT_FOUND, RIP_VERBOSE, ""); 00179 return NULL; 00180 } 00181 00182 /* 00183 * Open File for reading. 00184 */ 00185 hFile = CreateFileW(szFile, 00186 GENERIC_READ, 00187 FILE_SHARE_READ, 00188 NULL, 00189 OPEN_EXISTING, 00190 0, 00191 NULL); 00192 00193 if (hFile == INVALID_HANDLE_VALUE) 00194 goto Done; 00195 00196 /* 00197 * Create file-mapping for the file in question. 00198 */ 00199 hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); 00200 00201 if (hFileMap == NULL) 00202 goto CloseDone; 00203 00204 /* 00205 * Map the file into view. 00206 */ 00207 fi.pFileMap = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0); 00208 00209 if (fi.pFileMap == NULL) 00210 goto CloseDone; 00211 00212 fi.pFileEnd = fi.pFileMap + GetFileSize(hFile, NULL); 00213 fi.pFilePtr = fi.pFileMap; 00214 fi.pszName = szFile; 00215 00216 try { 00217 switch(PTR_TO_ID(type)) { 00218 case PTR_TO_ID(RT_BITMAP): { 00219 00220 LPBITMAPFILEHEADER pBFH; 00221 UPBITMAPINFOHEADER upBIH; 00222 LPBYTE lpBits; 00223 DWORD cx; 00224 DWORD cy; 00225 WORD planes; 00226 WORD bpp; 00227 DWORD cbSizeImage = 0; 00228 DWORD cbSizeFile; 00229 DWORD cbSizeBits; 00230 00231 /* 00232 * Set the BitmapFileHeader and BitmapInfoHeader pointers. 00233 */ 00234 pBFH = (LPBITMAPFILEHEADER)fi.pFileMap; 00235 upBIH = (UPBITMAPINFOHEADER)(fi.pFileMap + BITMAPFILEHEADER_SIZE); 00236 00237 /* 00238 * Are we dealing with a bitmap file. 00239 */ 00240 if (pBFH->bfType != BFT_BITMAP) 00241 break; 00242 00243 /* 00244 * We need to check the filesize against the potential size of 00245 * the image. Bad-Bitmaps would otherwise be able to slam us 00246 * if they lied about the size (and/or) the file is truncated. 00247 */ 00248 if (upBIH->biSize == sizeof(BITMAPCOREHEADER)) { 00249 00250 cx = ((UPBITMAPCOREHEADER)upBIH)->bcWidth; 00251 cy = ((UPBITMAPCOREHEADER)upBIH)->bcHeight; 00252 bpp = ((UPBITMAPCOREHEADER)upBIH)->bcBitCount; 00253 planes = ((UPBITMAPCOREHEADER)upBIH)->bcPlanes; 00254 00255 } else { 00256 00257 cx = upBIH->biWidth; 00258 cy = upBIH->biHeight; 00259 bpp = upBIH->biBitCount; 00260 planes = upBIH->biPlanes; 00261 00262 if(upBIH->biSizeImage >= sizeof(BITMAPINFOHEADER)) 00263 cbSizeImage = upBIH->biSizeImage; 00264 } 00265 00266 cbSizeFile = (DWORD)(fi.pFileEnd - fi.pFileMap); 00267 cbSizeBits = BitmapSize(cx, cy, planes, bpp); 00268 00269 if ((!cbSizeImage && ((cbSizeFile - MINHEADERS_SIZE) < cbSizeBits)) || 00270 (cbSizeImage && ((cbSizeFile - MINHEADERS_SIZE) < cbSizeImage))) { 00271 00272 break; 00273 } 00274 00275 /* 00276 * Get the bits-offset in the file. 00277 */ 00278 if ((pBFH->bfOffBits >= (sizeof(BITMAPFILEHEADER) + sizeof(BITMAPCOREHEADER))) && 00279 (pBFH->bfOffBits <= (cbSizeFile - cbSizeImage))) { 00280 00281 lpBits = ((LPBYTE)upBIH) + pBFH->bfOffBits - sizeof(BITMAPFILEHEADER); 00282 00283 } else { 00284 00285 lpBits = NULL; 00286 } 00287 00288 /* 00289 * Convert the dib-on-file to a bitmap-handle. This can 00290 * convert both CORE and INFO formats. 00291 */ 00292 hObj = ConvertDIBBitmap(upBIH, 00293 cxDesired, 00294 cyDesired, 00295 LR_flags, 00296 NULL, 00297 &lpBits); // use these bits! 00298 } 00299 break; 00300 00301 case PTR_TO_ID(RT_CURSOR): 00302 case PTR_TO_ID(RT_ICON): 00303 { 00304 RTAG *prtag; 00305 ICONFILEHEADER *pifh; 00306 00307 /* 00308 * Is this a RIFF file? 00309 */ 00310 prtag = (RTAG *)fi.pFileMap; 00311 00312 if (prtag->ckID != FOURCC_RIFF) { 00313 00314 NEWHEADER nh; 00315 00316 pifh = (ICONFILEHEADER *)fi.pFileMap; 00317 00318 /* 00319 * BUG?: looks like we can load icons as cursors and cursors 00320 * as icons. Does this work? Is this desired? (SAS) 00321 */ 00322 if ((pifh->iReserved != 0) || 00323 ((pifh->iResourceType != IMAGE_ICON) && 00324 (pifh->iResourceType != IMAGE_CURSOR)) || 00325 (pifh->cresIcons < 1)) 00326 00327 break; 00328 00329 nh.ResType = ((type == RT_ICON) ? IMAGE_ICON : IMAGE_CURSOR); 00330 nh.ResCount = pifh->cresIcons; 00331 nh.Reserved = 0; 00332 00333 /* 00334 * Get the size of the sucker and meanwhile seek the file pointer 00335 * to point at the DIB we want. Files that have more than one 00336 * icon/cursor are treated like a group. In other words, 00337 * each image is treated like an individual element in the res 00338 * dir. So we need to pick the best fit one... 00339 */ 00340 hObj = IconFromBestImage(pifh, 00341 &nh, 00342 cxDesired, 00343 cyDesired, 00344 LR_flags); 00345 } else { 00346 00347 BOOL fAni; 00348 00349 hObj = LoadCursorIconFromFileMap(&fi, 00350 &type, 00351 cxDesired, 00352 cyDesired, 00353 LR_flags, 00354 &fAni); 00355 } 00356 } 00357 break; 00358 00359 default: 00360 UserAssert(FALSE); 00361 break; 00362 } // switch 00363 } except (W32ExceptionHandler(FALSE, RIP_WARNING)) { 00364 hObj = NULL; 00365 } 00366 CloseDone: 00367 00368 if (fi.pFileMap != NULL) 00369 UnmapViewOfFile(fi.pFileMap); 00370 00371 if (hFileMap) 00372 CloseHandle(hFileMap); 00373 00374 if (hFile && (hFile != INVALID_HANDLE_VALUE)) 00375 CloseHandle(hFile); 00376 00377 Done: 00378 #if DBG 00379 if (hObj == NULL) { 00380 RIPMSG1(RIP_WARNING, 00381 "RtlLoadObjectFromDIBFile: Couldn't read resource from %ws", 00382 lpszName); 00383 } 00384 #endif 00385 00386 return hObj; 00387 }


Generated on Sat May 15 19:45:30 2004 for test by doxygen 1.3.7