Hi all, hopefully someone will be able to help :)
I've managed to get the following code to "work".
My problem, however, is the icon file which is created from the resource, is missing the first 22 bytes.
Apart from the missing bytes, the rest of the file is OK (but obviously not a valid nor working icon).
(I checked by viewing original icon and new icon in a HEX editor.)
The size of the original Icon is 1,150 bytes. So, I double checked what dwSizeRes is actually finding.
The size dwSizeRes is returning, is only 1,128 bytes.
The resource is being correctly shown as the compiled applications Icon, so has been included into the project correctly.
I'm still somewhat new to C++, so it
may be something silly that I'm overlooking.
If anyone would be able to hint at or tell me where I'm going wrong, I'd be very grateful.
Thanks in advance,
Gremz.
#include <windows.h>
#include <fstream>
int main ()
{
HGLOBAL hResourceLoaded;
HRSRC hRes;
char *lpResLock;
DWORD dwSizeRes;
hRes = FindResource( GetModuleHandle(NULL), MAKEINTRESOURCE(1), RT_ICON );
hResourceLoaded = LoadResource( NULL, hRes );
lpResLock = (char*)LockResource( hResourceLoaded );
dwSizeRes = SizeofResource( NULL, hRes );
if(hRes==NULL){
printf("hRes not being populated.");
}
else{
std::cout << dwSizeRes;
std::ofstream outputFile("c:\\test.ico", std::ios::binary);
outputFile.write((const char*)lpResLock, dwSizeRes);
outputFile.close();
}
}