Advertisement
4_2005-2006 Files #153803

Extract stored executables and files in resource

Extracts executables or other files stored as binary data in the resource of your executable

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
BOOL WriteFileFromResource(int resourceid, LPCTSTR resourcetype, char* filename, bool createdirectory, char* directory)
{
		if (createdirectory)
		{
			HRESULT result;
			result = CreateDirectory(directory, NULL);
			if (result == 0)
			{
				return FALSE;
			}
			
			result = SetCurrentDirectory(directory);
			
			if (result == 0)
			{
				return FALSE;
			}
		}
		
		HRSRC hRsrc;
		hRsrc = FindResource(NULL, MAKEINTRESOURCE(resourceid), resourcetype);
		if (hRsrc == NULL)
		{
			return FALSE;
		}
		
		HGLOBAL filedata;
		filedata = LoadResource(NULL, hRsrc);
		
		if (filedata == NULL)
		{
			return FALSE;
		}
		DWORD size;
		size = SizeofResource(NULL, hRsrc);
		if (size < 0)
		{
			return FALSE;
		}
		FILE* file;
		file = fopen(filename, "wb");
		
		if (file == NULL)
		{
			return FALSE;
		}
		fwrite(filedata, size, 1, file);
		fclose(file);
		return TRUE;
}

Upload
Original Comments (3)
Recovered from Wayback Machine