How to Save an Embedded Resource to a File

By: mykle hoban

Abstract: This article describes how to save a resource embedded in your application to a file.


How dow I save an embedded resource to a file?


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 =
  DWORD writ; WriteFile(hFile,rdata,size,&writ,NULL);
  return TRUE;

Server Response from: ETNASC03