WetCode

Untitled

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