WetCode

Untitled

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