Hi guys I have a function that extracts resources from application, it goes fine with custom resources, but when it comes to standard resources it extracts files of same size but garbage content in them.
In my applciation I have embedded two resources of type 'BITMAP', in resource file I defined them as:
117 and 118 are resource Ids, and BITMAP is type of resource.Code:117 BITMAP DISCARDABLE "p2/ide_icons/splash.bmp" 118 BITMAP DISCARDABLE "p2/ide_icons/splash.gif"
Now if the resource type is something else e.g. 'MYRES' defined in resource file as
it is extracted fine.Code:117 MYRES DISCARDABLE "p2/ide_icons/splash.bmp"
But as you can see it is is of type BITMAP, so I pass RT_BITMAP to function FindResource.
Problem is all of folowing functions pass fine
FindResource
LoadResource
LockResource
but resulting extracted data is not actual file that was in the resources, although the size is same but contents are wrong.
Please review following function and let me know what can be possible problem.
Will be waiting for kind reply.Code:bool ExtractResource(DWORD resID, LPCSTR resType,String file) { HRSRC hResInfo = FindResource(GetModuleHandle(NULL), MAKEINTRESOURCE(resID), resType); if (hResInfo == NULL) return false; HGLOBAL hResource = LoadResource(GetModuleHandle(NULL), hResInfo); if (hResource == NULL) return false; char *pResData = (char*)LockResource(hResource); DWORD resSize = SizeofResource(NULL, hResInfo); if(resSize==0) return false; FILE *f = fopen(file.c_str(),"w"); fwrite(pResData,1,resSize,f); fclose(f); UnlockResource(hResource); }
regards




Reply With Quote