- It is currently Sat May 18, 2013 2:33 pm • All times are UTC + 2 hours
Pack unpack resources
2 posts
• Page 1 of 1
Pack unpack resources
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

- Posts: 3
- Joined: Thu May 04, 2006 4:47 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.
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

- Posts: 269
- Joined: Thu Apr 06, 2006 11:04 am
2 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest