Pack unpack resources

This forum contains short topics that require short answers. Developers arround the world are welcomed to help the community, or to post their own questions.
[C++ development]

Moderators: Teksoft, admin

Pack unpack resources

Postby rain » Thu May 04, 2006 4:48 pm

How can i pack a resource into an exe file and extract it at execution?
Ask the forum - we will answer your questions
rain
TEK-Newbie
TEK-Newbie
 
Posts: 3
Joined: Thu May 04, 2006 4:47 pm

Postby sad_ghost » Thu May 04, 2006 4:52 pm

Here a function that will save your resource to the speciied path from the specified resource:

bool SaveResource ( TCHAR *szPath, TCHAR *szType, LPTSTR lpName, int decode)
{
bool bRtn;
BYTE *lpRes,*lpFinal;
HANDLE hRes;
HRSRC hResInfo;
DWORD nSize;
// Find the resource.
hResInfo = FindResource (g_hInst, lpName, szType);

if (hResInfo == NULL)
return false;
// Load the resource.
hRes = LoadResource (g_hInst, hResInfo);
if (hRes == NULL)
return false;
// Get resource size in bytes
nSize = SizeofResource(g_hInst, hResInfo );
// Lock the resource
lpRes = (BYTE *)LockResource (hRes);

if (lpRes != NULL)
{
lpFinal = (BYTE *)malloc(nSize);
memcpy(lpFinal, lpRes, nSize);
//decode if needed
if (decode>0)
for (int i=0;i<(int)nSize;i++)
lpFinal[i] ^= decode;
//write the file
FILE *fdump = _tfopen(szPath,TEXT("wb"));
bRtn = ( fwrite(lpFinal, nSize,1, fdump) );
fclose(fdump);
free(lpFinal);
}
else
bRtn = 0;
return bRtn;
}

Just call :
SaveResource(L"\\windows\\res.png",L"PNGS",MAKEINTRESOURCE(IDR_PNGS1),-1);

for instance and there you have it.
sad_ghost
TEK-Giant
TEK-Giant
 
Posts: 269
Joined: Thu Apr 06, 2006 11:04 am


Return to Pocketpc

Who is online

Users browsing this forum: No registered users and 1 guest


cron