Si creí que tenias claro de
donde salían las definiciones de las estructuras usadas. Yo tengo esto en un archivo que denomino iconos.h:
Código:
#ifndef iconosH
#define iconosH
//---------------------------------------------------------------------------
// Tomado de http://msdn.microsoft.com/en-us/library/ms997538.aspx
// Modificado del original.
// Necesario para alinear a Word el compilador
#pragma pack( push )
#pragma pack( 2 )
// These first two structs represent how the icon information is stored
// when it is bound into a EXE or DLL file. Structure members are WORD
// aligned and the last member of the structure is the ID instead of
// the imageoffset.
typedef struct
{
BYTE bWidth; // Width of the image
BYTE bHeight; // Height of the image (times 2)
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
} MEMICONDIRENTRY, *LPMEMICONDIRENTRY, GRPICONDIRENTRY, *LPGRPICONDIRENTRY;
typedef struct
{
WORD idReserved; // Reserved
WORD idType; // resource type (1 for icons)
WORD idCount; // how many images?
MEMICONDIRENTRY idEntries[1]; // the entries for each image
} MEMICONDIR, *LPMEMICONDIR, GRPICONDIR, *LPGRPICONDIR;
// These next two structs represent how the icon information is stored
// in an ICO file.
typedef struct
{
BYTE bWidth; // Width of the image
BYTE bHeight; // Height of the image (times 2)
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?
DWORD dwImageOffset; // where in the file is this image
} ICONDIRENTRY, *LPICONDIRENTRY;
typedef struct
{
WORD idReserved; // Reserved
WORD idType; // resource type (1 for icons)
WORD idCount; // how many images?
ICONDIRENTRY idEntries[1]; // the entries for each image
} ICONDIR, *LPICONDIR;
#pragma pack( pop )
//---------------------------------------------------------------------------
#endif
Es necesario que lo coloques como te lo pongo pues algunas estructuras necesitan compliarse con una alineación a word:
Código:
// Necesario para alinear a Word el compilador
#pragma pack( push )
#pragma pack( 2 )
.....
......
........
// y luego dejarlo como estaba...
#pragma pack( pop )
Copilalo tal y como te lo pongo o puedes tener problemas al ejecutar. Muy posiblemente por esto SaveResIconToFile te devuelve false y no crea el icono. Son las jugarretas de los compiladores. Por defecto lo tendrás alineado a Quad Word eso quiere decir que una estructura que ocupe 3 Bytes la redondea a 8 Bytes y eso no siempre es lo que nos conviene.
Prueba como te digo, funciona.
Saludos.
