try this one:
ICONINFO ii;
if(GetIconInfo(hicon,&ii))
{
__IcoSave24(store,ii.hbmMask,ii.hbmColor);
if(ii.hbmColor) DeleteObject(ii.hbmColor);
if(ii.hbmMask ) DeleteObject(ii.hbmMask );
}
static void __IcoSave24(vStore& store,HBITMAP hbmMask,HBITMAP hbmColor)
{
BITMAP bmiMask;
BITMAP bmiColor;
if(
GetObject(hbmColor,sizeof(bmiColor),&bmiColor) &&
GetObject(hbmMask,sizeof(bmiMask),&bmiMask) &&
(bmiColor.bmWidth==bmiMask.bmWidth) &&
(bmiColor.bmHeight==bmiMask.bmHeight)
)
{
ICONDIR icodir;
ICONDIRENTRY icoent;
BITMAPINFOHEADER icobmi = {0};
tArr<char> bits;
unsigned int size;
icodir.idReserved = 0;
icodir.idType = 1;
icodir.idCount = 1;
icoent.bWidth = (unsigned char)bmiColor.bmWidth;
icoent.bHeight = (unsigned char)bmiColor.bmHeight;
icoent.bColorCount = 8<=bmiColor.bmBitsPixel?0:1<<bmiColor.bmBitsPixel;
icoent.bReserved = 0;
icoent.wPlanes = bmiColor.bmPlanes;
icoent.wBitCount = bmiColor.bmBitsPixel;
icoent.dwBytesInRes = sizeof(BITMAPINFOHEADER) + (__bmp_bpl(bmiColor.bmBitsPixel,bmiColor.bmWidth)*bmiColor.bmHeight) + (__bmp_bpl(bmiMask.bmBitsPixel,bmiMask.bmWidth)*bmiMask.bmHeight);
icoent.dwImageOffset = sizeof(icodir) + sizeof(icoent);
store.Write(&icodir,sizeof(icodir));
store.Write(&icoent,sizeof(icoent));
if(0>bmiMask.bmHeight) Beep(3000,1000);
icobmi.biSize = sizeof(icobmi);
icobmi.biWidth = bmiColor.bmWidth;
icobmi.biHeight = bmiColor.bmHeight + bmiMask.bmHeight;
icobmi.biPlanes = 1;
icobmi.biBitCount = bmiColor.bmBitsPixel;
icobmi.biSizeImage = __bmp_bpl(bmiColor.bmBitsPixel,bmiColor.bmWidth)*bmiColor.bmHeight;
store.Write(&icobmi,sizeof(icobmi));
bits.resize(icobmi.biSizeImage);
size = GetBitmapBits(hbmColor,bits.count,bits.array);
store.Write(bits.array,size);
size = GetBitmapBits(hbmMask,bits.count,bits.array);
store.Write(bits.array,size);
}
}
Good luck.