如何將本身的文件做爲資源文件放入VC工程中並釋放爲文件

如何將本身的文件做爲資源文件放入VC工程中?如何在運行時,從EXE文件中提取(釋放)出這個文件this

1. In VC IDE,add new resource type such as "RES_DATA",then add your file to the projectspa

resource as the new type.orm

2. Fetch your file from executable file at runtime,can use follow function:
BOOL Res2File( LPCTSTR lpName, LPCTSTR lpType, LPCTSTR filename ) 

 HRSRC hRes = ::FindResource( NULL, lpName, lpType ); 
 HGLOBAL gl =::LoadResource( NULL, hRes ); 
 LPVOID lp = ::LockResource( gl ); 
 HANDLE fp = ::CreateFile( filename, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL資源

); 
 if( fp == INVALID_HANDLE_VALUE ) 
 return FALSE;it

 DWORD a; 
 if( !::WriteFile( fp, lp, SizeofResource( NULL, hRes ), &a, NULL ) ) 
 return FALSE;io

 CloseHandle( fp ); 
 FreeResource( gl ); 
 return TRUE; 
}
Use this function such as this format:
Res2File( MAKEINTRESOURCE(ID_RES_DATA), "RES_DATA", "C://FontRes.TTF" );table

1. In VC IDE,add new resource type such as "RES_DATA",then add your file to the project
相關文章
相關標籤/搜索