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
00161
00162
00163
00164
00165 ExpandEnvironmentStrings(lpszName, szFile2, MAX_PATH);
00166
00167 }
else {
00168
00169 lstrcpy(szFile2, lpszName);
00170 }
00171
00172
if (SearchPath(NULL,
00173 szFile2,
00174 NULL,
00175 MAX_PATH,
00176 szFile,
00177 &pszFileDummy) == 0) {
00178 RIPERR0(ERROR_FILE_NOT_FOUND, RIP_VERBOSE,
"");
00179
return NULL;
00180 }
00181
00182
00183
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
00198
00199 hFileMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
00200
00201
if (hFileMap ==
NULL)
00202
goto CloseDone;
00203
00204
00205
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
00233
00234 pBFH = (LPBITMAPFILEHEADER)fi.
pFileMap;
00235 upBIH = (
UPBITMAPINFOHEADER)(fi.
pFileMap +
BITMAPFILEHEADER_SIZE);
00236
00237
00238
00239
00240
if (pBFH->bfType !=
BFT_BITMAP)
00241
break;
00242
00243
00244
00245
00246
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
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
00290
00291
00292 hObj =
ConvertDIBBitmap(upBIH,
00293 cxDesired,
00294 cyDesired,
00295 LR_flags,
00296 NULL,
00297 &lpBits);
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
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
00320
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
00335
00336
00337
00338
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 }
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 }