首页 > 编程语言 > 详细

MFC - 释放文件到指定文件夹

时间:2016-04-16 22:46:06      阅读:305      评论:0      收藏:0      [点我收藏+]
 1 // 释放文件到指定的文件夹
 2 BOOL ReleaseRes(LPCTSTR szDLLFullPath, UINT uResID, LPCTSTR szResType)
 3 {
 4     if (uResID<=0 || !szResType)
 5     {
 6         return FALSE;
 7     }
 8 
 9     HRSRC hRsrc = FindResource(NULL, MAKEINTRESOURCE(uResID), szResType);
10     if ( NULL == hRsrc )
11     {
12         return FALSE;
13     }
14 
15     DWORD dwSize = SizeofResource(NULL, hRsrc);
16     if ( dwSize <= 0)
17     {
18         return FALSE;
19     }
20 
21     HGLOBAL hGlobal = LoadResource(NULL, hRsrc);
22     if ( NULL == hGlobal )
23     {
24         return FALSE;
25     }
26 
27     LPVOID pBuffer = LockResource(hGlobal);
28     if ( NULL ==pBuffer )
29     {
30         return FALSE;
31     }
32 
33     HANDLE hFile = CreateFile(szDLLFullPath, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
34     if (INVALID_HANDLE_VALUE == hFile )
35     {
36         return FALSE;
37     }
38 
39     DWORD dwWrited = 0;
40     if (FALSE == WriteFile(hFile, pBuffer, dwSize, &dwWrited, NULL) )
41     {
42         AfxMessageBox(_T("写入失败!"));
43         return FALSE;
44     }
45 
46     UnlockResource(hGlobal);
47     CloseHandle(hFile);
48     return TRUE;
49 }

 

MFC - 释放文件到指定文件夹

原文:http://www.cnblogs.com/DuanLaoYe/p/5399344.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!