The following code sample illustrates how to save an embedded resource to a file.
BOOL SaveResourceToFile(char *fn, char *res)
{ HRSRC hrsrc = FindResource(HInstance,res,RT_RCDATA);
if (hrsrc == NULL) return FALSE;
DWORD size = SizeofResource(HInstance,hrsrc);
HGLOBAL hglob = LoadResource(HInstance,hrsrc);
LPVOID rdata = LockResource(hglob);
HANDLE hFile =
CreateFile(fn,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
DWORD writ; WriteFile(hFile,rdata,size,&writ,NULL);
CloseHandle(hFile);
return TRUE;
}
|