VC 从资源中释放文件

将文件放入资源中,然后在程序运行的过程中释放出来,下面是代码:

BOOL FreeResFile(HINSTANCE hInstance, DWORD dwResName, LPCWSTR lpResType, LPCWSTR lpFilePathName)
{
HRSRC hResID = ::FindResource(hInstance, MAKEINTRESOURCE(dwResName), lpResType);
HGLOBAL hRes = ::LoadResource(hInstance, hResID);
LPVOID pRes = ::LockResource(hRes);
if (pRes == NULL)
{
return FALSE;
}
DWORD dwResSize = ::SizeofResource(hInstance, hResID);
HANDLE hResFile = CreateFile(lpFilePathName, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (INVALID_HANDLE_VALUE == hResFile)
{
return FALSE;
}
DWORD dwWritten = 0;
WriteFile(hResFile, pRes, dwResSize, &dwWritten, NULL);
CloseHandle(hResFile);
return (dwResSize == dwWritten);
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页