如何将本身的文件做为资源文件放入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
相关文章
相关标签/搜索