Im trying to lock and write the icon resource, that is in module itself, to a file.
Its an icon.ico file 16x16 with size 1150 bytes and SizeofResource returns only 20 bytes.
GetLastError returns "The operation completed successfully". and the icon is displayed as expected.
resource.rc
Code:
#define IDI_MYICON 101
IDI_MYICON ICON "myicon.ico"
The function:
Code:
void Resource()
{
FILE *file;
HRSRC hRes = NULL;
HGLOBAL hResLoaded;
LPVOID lpResLock = NULL;
char* cbuf;
DWORD sizeOfRes;
int i;
hRes = FindResource(NULL,
MAKEINTRESOURCE(IDI_MYICON),
RT_GROUP_ICON);
if(hRes != NULL)
{
hResLoaded = LoadResource(NULL, hRes);
if(hResLoaded != NULL)
{
sizeOfRes = SizeofResource(NULL, hRes);
cout << "Size = "<< sizeOfRes << endl;
cbuf = (char*) calloc (sizeOfRes, sizeof(char));
strcpy(cbuf,(char*)LockResource(hResLoaded));
if(sizeOfRes != 0)
{
file = fopen("myfile.txt", "wb");
if(file != NULL)
{
for(i = 0; i < sizeOfRes; i++)
{
fwrite(&cbuf[i],sizeof(char),1,file);
}
fclose(file);
}
}
}
free(cbuf);
UnlockResource(hResLoaded);
FreeResource(hResLoaded);
}
}