Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Resources.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <vector>
- #include <Windows.h>
- using namespace std;
- BOOL ResTypes(HMODULE hModule, LPTSTR lpType, LONG lParam);
- BOOL ResNames(HMODULE hModule, LPCTSTR lpType, LPTSTR lpName, LONG lParam);
- #pragma pack( push )
- #pragma pack( 2 )
- typedef struct
- {
- BYTE bWidth; // Width, in pixels, of the image
- BYTE bHeight; // Height, in pixels, of the image
- BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
- BYTE bReserved; // Reserved
- WORD wPlanes; // Color Planes
- WORD wBitCount; // Bits per pixel
- DWORD dwBytesInRes; // how many bytes in this resource?
- WORD nID; // the ID
- } GRPICONDIRENTRY, *LPGRPICONDIRENTRY;
- #pragma pack( pop )
- typedef struct
- {
- BYTE bWidth; // Width, in pixels, of the image
- BYTE bHeight; // Height, in pixels, of the image
- BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
- BYTE bReserved; // Reserved ( must be 0)
- WORD wPlanes; // Color Planes
- WORD wBitCount; // Bits per pixel
- DWORD dwBytesInRes; // How many bytes in this resource?
- DWORD dwImageOffset; // Where in the file is this image?
- } ICONDIRENTRY, *LPICONDIRENTRY;
- // #pragmas are used here to insure that the structure's
- // packing in memory matches the packing of the EXE or DLL.
- #pragma pack( push )
- #pragma pack( 2 )
- typedef struct
- {
- WORD idReserved; // Reserved (must be 0)
- WORD idType; // Resource type (1 for icons)
- WORD idCount; // How many images?
- GRPICONDIRENTRY idEntries[1]; // The entries for each image
- } GRPICONDIR, *LPGRPICONDIR;
- #pragma pack( pop )
- typedef struct {
- WORD idReserved; // Reserved (must be 0)
- WORD idType; // Resource Type (1 for icons)
- WORD idCount; // How many images?
- ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em)
- } ICONDIR, *LPICONDIR;
- typedef struct
- {
- BITMAPINFOHEADER icHeader; // DIB header
- RGBQUAD icColors[1]; // Color table
- BYTE icXOR[1]; // DIB bits for XOR mask
- BYTE icAND[1]; // DIB bits for AND mask
- } ICONIMAGE, *LPICONIMAGE;
- typedef BOOL (CALLBACK *EnumResNameProc)( HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam);
- int main(int argc, char* argv[])
- {
- LPCSTR IconGrpName = NULL;
- // Credit to my friend *** thanks for you help and explination :)
- HMODULE hExe = LoadLibrary(TEXT("TestRes.exe"));
- EnumResourceTypes(hExe, (ENUMRESTYPEPROC)ResTypes, 0);
- // Find the group resource which lists its images
- HRSRC hRsrc = FindResource( hExe, MAKEINTRESOURCE(1), RT_GROUP_ICON );
- // Load and Lock to get a pointer to a GRPICONDIR
- HGLOBAL hGlobal = LoadResource( hExe, hRsrc );
- GRPICONDIR *lpGrpIconDir = (GRPICONDIR*)LockResource( hGlobal );
- vector<ICONIMAGE*> vec_lpIconImage;
- for ( int i = 0; i < lpGrpIconDir->idCount; i++ )
- {
- // Using an ID from the group, Find, Load and Lock the RT_ICON
- hRsrc = FindResource( hExe, MAKEINTRESOURCE( lpGrpIconDir->idEntries[i].nID ), RT_ICON );
- hGlobal = LoadResource( hExe, hRsrc );
- ICONIMAGE *lpIconImage = (ICONIMAGE*)LockResource( hGlobal );
- vec_lpIconImage.push_back( lpIconImage );
- // Here, lpIconImage points to an ICONIMAGE structure
- }
- for ( unsigned i = 0; i < vec_lpIconImage.size(); i++ )
- {
- cout << "Width x Height: " << vec_lpIconImage[i]->icHeader.biWidth << "x" << vec_lpIconImage[i]->icHeader.biHeight << endl;
- cout << "Size: " << vec_lpIconImage[i]->icHeader.biSizeImage << endl;
- }
- system("PAUSE");
- return 0;
- }
- // Credit to my friend *** thanks for you help and explination :)
- BOOL ResTypes(HMODULE hModule, LPTSTR lpType, LONG lParam)
- {
- if (!IS_INTRESOURCE(lpType))
- {
- if( lpType == (RT_ICON + 11))
- {
- std::cout<<"Icon Group"<< lpType << "\n";
- }
- } else {
- if( lpType == (RT_ICON + 11))
- {
- std::cout<<"Icon Group (short): "<< (short)lpType << "\n";
- }
- }
- if( lpType == RT_ICON) // Icon Resource Type
- {
- EnumResourceNames(hModule, lpType, (ENUMRESNAMEPROC)ResNames, 0);
- }
- return true;
- }
- // Credit to my friend *** thanks for you elp and explination :)
- BOOL ResNames(HMODULE hModule, LPCTSTR lpType, LPTSTR lpName, LONG lParam)
- {
- if (!IS_INTRESOURCE(lpName))
- {
- if( lpType == RT_ICON)
- std::cout<<"Icon: "<< lpType << "\n";
- } else {
- if( lpType == RT_ICON)
- std::cout<<"Icon (short): "<< (short)lpType << "\n";
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment