举例: 将一个文件做为资源导入到VC工程的*.rc文件中,程序运行时再将资源释放出来写到文件中去.
bool DeliverResource(const CString& strDestPath, const char * pszID, const char * pszType)
{
HRSRC hRsrc = FindResource(NULL, pszID, pszType);
if(NULL == hRsrc)
return false;
DWORD dwSize = SizeofResource(NULL, hRsrc);
if(0 == dwSize)
return false;
HGLOBAL hGlobal = LoadResource(NULL, hRsrc);
if(NULL == hGlobal)
return false;
LPVOID pBuffer = LockResource(hGlobal);
if(NULL == pBuffer)
return false;
tool::CreateMidDir(strDestPath);
FILE *fp = fopen(strDestPath, "wb");
DWORD dwRemain = dwSize;
while(dwRemain > 0)
{
dwRemain -= fwrite(pBuffer, sizeof(char), dwRemain, fp);
}
fclose(fp);
return true;
}