WetCode

Untitled

Dec 4th, 2013
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1.  
  2. // #pragmas are used here to insure that the structure's
  3. // packing in memory matches the packing of the EXE or DLL.
  4. #pragma pack( push )
  5. #pragma pack( 2 )
  6. typedef struct
  7. {
  8.    WORD            idReserved;   // Reserved (must be 0)
  9.    WORD            idType;       // Resource type (1 for icons)
  10.    WORD            idCount;      // How many images?
  11.    GRPICONDIRENTRY   idEntries[1]; // The entries for each image
  12. } GRPICONDIR, *LPGRPICONDIR;
  13. #pragma pack( pop )
  14.  
  15.  
  16. #pragma pack( push )
  17. #pragma pack( 2 )
  18. typedef struct
  19. {
  20.    BYTE   bWidth;               // Width, in pixels, of the image
  21.    BYTE   bHeight;              // Height, in pixels, of the image
  22.    BYTE   bColorCount;          // Number of colors in image (0 if >=8bpp)
  23.    BYTE   bReserved;            // Reserved
  24.    WORD   wPlanes;              // Color Planes
  25.    WORD   wBitCount;            // Bits per pixel
  26.    DWORD   dwBytesInRes;         // how many bytes in this resource?
  27.    WORD   nID;                  // the ID
  28. } GRPICONDIRENTRY, *LPGRPICONDIRENTRY;
  29. #pragma pack( pop )
  30.  
  31. HMODULE hExe = LoadLibrary("TestRes.exe");
  32. EnumResourceTypes(hExe, (ENUMRESTYPEPROC)ResTypes, 0);
  33.  
  34. // Find the group resource which lists its images
  35.                             /* Need to set "IconGrpName" this from ResTypee */
  36. HRSRC hRsrc = FindResource( hExe, MAKEINTRESOURCE(1), RT_GROUP_ICON );
  37. // Load and Lock to get a pointer to a GRPICONDIR
  38. HGLOBAL hGlobal = LoadResource( hExe, hRsrc );
  39. GRPICONDIR *lpIconGroup = new GRPICONDIR[ SizeofResource( hExe, hRsrc ) ];
  40. RtlZeroMemory( lpIconGroup, SizeofResource( hExe, hRsrc ) );
  41. lpIconGroup = (GRPICONDIR*)LockResource( hGlobal );
  42. // We now have the header of the icon file now we need all the icons.
  43.    
  44. cout << "Icon Count: " << lpIconGroup->idCount << endl;
  45. cout << "Type: " << lpIconGroup->idType  << endl;
  46. cout << "idReserved: " << lpIconGroup->idReserved << endl;
  47. for ( unsigned i = 0; i < lpIconGroup->idCount; i++ )
  48. {
  49.     cout << "\tEntry ID: " << lpIconGroup->idEntries[i].nID << endl;
  50.     cout << "\tEntry Height: " << (int)lpIconGroup->idEntries[i].bHeight << endl;
  51.     cout << "\tEntry Height: " << (int)lpIconGroup->idEntries[i].bWidth << endl;
  52.     cout << "\tEntry Size: " << lpIconGroup->idEntries[i].dwBytesInRes << endl << endl;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment