Главная страница | назад





Article #26384: How to Save an Embedded Resource to a File

Question

How dow I save an embedded resource to a file?

Answer

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;
}

Last Modified: 04-DEC-00