Re: Why doesn't this work?
http://www.crispen.org/src/archive/0005.html
Not sure if this code works because I didn't try it myself, but it seems you have to make your own implementation that converts from HICON to raw data pointer used in a UpdateResource() call.
Also, it seems that LockResource() should be used instead of GlobalLock().
If you want a sample of how icon data must be provided for exe update, search the following link for "UpdateResource(RT_ICON":
http://cvs.sourceforge.net/viewcvs.p...l.cpp?rev=1.10
Best of luck,
Re: Why doesn't this work?
The link http://www.crispen.org/src/archive/0005.html doesn't work!
I've tried www.crispen.org too but the same result: Could not connect
1 Attachment(s)
Re: Why doesn't this work?
Hi nemok!
Please find the attachment containing the web page from the link:
http://www.crispen.org/src/archive/0005.html
Then again, I think the second link I've posted was better.
It seems that many before had the same problem you're facing.
Probably, many again will, so, it is a good thing for you to post a FAQ when will have a solution.
Thanks,
Re: Why doesn't this work?
The links you provided me with show only how to read an icon from an .ico file, which is not what I need.
I found the following code in MSDN (Q104570) on howw to save an HICON to disk and then read it and so gain an pointer to the icon.
Code:
int NEAR _pascal SaveMyIcon( HICON hIcon)
{
int fh, i, iResult;
UINT uiSize;
DWORD dwSize;
OFSTRUCT of; if (!hIcon)
return FALSE; dwSize = GlobalSize(hIcon);
lpGMem = GlobalLock(hIcon);
fh = OpenFile ("myicon.bin", &of, OF_WRITE | OF_CREATE); if (fh == -1) // If NOT opened successfully.
{
MessageBox(NULL, "Unable to create file", NULL, MB_OK );
return FALSE;
} uiSize = _lwrite(fh, (LPSTR)lpGMem, (UINT)dwSize);
_lclose(fh); if (uiSize == -1 || uiSize < (UINT)dwSize)
{
MessageBox(NULL, "Unable to read file", NULL, MB_OK );
return FALSE;
}
else // Everything worked, return hGMem.
{
return (HICON)hGMem;
}
}
The problem is that it doesn't work. The lpGMem pointer is always NULL.
Is it might be because I don't know what type lpGMem is (the article doesn't say). I made it LPTSTR, LPBYTE... and it doesnt work. What sould I do? Is it really not posible to gain a valid pointer from an HICON handle provided by ExtractIcon()?
Please help!
Re: Why doesn't this work?
Re: Why doesn't this work?
Re: Why doesn't this work?
I found a software doing what you want to do, so it is possible :D
http://www.softboy.net/exeico/
I've seen another sample code using a different function to extract an icon from a file, and maybe you want to try it out:
Code:
SHGetFileInfo("c:\\windows\\notepad.exe",0,&stFileInfo,sizeof(stFileInfo),SHGFI_ICON);
pDC->DrawIcon(10,10,stFileInfo.hIcon);
Since you've said before that drawing the icon obtained with ExtractIcon() works, but LockResource() or GlobalLock() are always returning NULL, makes me believe that ExtractIcon() doesn't fail, so there's no need to change it.
I have another question though:
Do you use LoadLibrary() to load the module from where you need to copy your icon?
http://msdn.microsoft.com/library/de...gResources.asp
Quote:
Originally Posted by MSDN
The pointer returned by LockResource is valid until the module containing the resource is unloaded. It is not necessary to unlock resources because the system automatically deletes them when the process that created them terminates.
Do not try to lock a resource by using the handle returned by the FindResource or FindResourceEx function. Such a handle points to random data.
These are the remarks on LockResource() function.
I'm so sorry I couldn't make the time to write a fully functional sample code, but I hope these links will lead you to it.
Best regards,
Re: Why doesn't this work?
Code:
int NEAR SaveMyIcon( HICON hIcon)
{
int fh, i, iResult;
UINT uiSize;
DWORD dwSize;
OFSTRUCT of; if (!hIcon)
return FALSE;
dwSize = GlobalSize(hIcon);
void* lpGMem;
lpGMem = GlobalLock(hIcon);
fh = OpenFile ("myicon.bin", &of, OF_WRITE | OF_CREATE); if (fh == -1) // If NOT opened successfully.
{
MessageBox(NULL, "Unable to create file", NULL, MB_OK );
return FALSE;
} uiSize = _lwrite(fh, (LPSTR)lpGMem, (UINT)dwSize);
_lclose(fh); if (uiSize == -1 || uiSize < (UINT)dwSize)
{
MessageBox(NULL, "Unable to read file", NULL, MB_OK );
return FALSE;
}
}
why error