如何将自己的文件作为资源文件放入VC工程中并释放为文件

如何将自己的文件作为资源文件放入VC工程中?如何在运行时,从EXE文件中提取(释放)出这个文件

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

resource as the new type.

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;

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

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

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

你可能感兴趣的:(如何将自己的文件作为资源文件放入VC工程中并释放为文件)