您的位置:首页 > 其它

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

2005-07-27 11:57 846 查看
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" );
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: