#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 )
#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 )
// Load the DLL/EXE without executing its codehLib = LoadLibraryEx( szFileName, NULL, LOAD_LIBRARY_AS_DATAFILE );// Find the group resource which lists its imageshRsrc = FindResource( hLib, MAKEINTRESOURCE( nId ), RT_GROUP_ICON );// Load and Lock to get a pointer to a GRPICONDIRhGlobal = LoadResource( hLib, hRsrc );lpGrpIconDir = LockResource( hGlobal );// Using an ID from the group, Find, Load and Lock the RT_ICONhRsrc = FindResource( hLib, MAKEINTRESOURCE( lpGrpIconDir->idEntries[0].nID ), RT_ICON );hGlobal = LoadResource( hLib, hRsrc );lpIconImage = LockResource( hGlobal );// Here, lpIconImage points to an ICONIMAGE structure