文件操作

 1 // 释放【TXT文件】到指定的文件夹
 2 BOOL ReleaseTXTRes(LPCTSTR szFullPath, UINT uResID, LPCTSTR szResType)
 3 {
 4     if (uResID<=0 || !szResType)
 5     {
 6         return FALSE;
 7     }
 8 
 9     HRSRC hRsrc = FindResource(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(uResID), szResType);
10     if ( NULL == hRsrc )
11     {
12         return FALSE;
13     }
14 
15     DWORD dwSize = SizeofResource(AfxGetApp()->m_hInstance, hRsrc);
16     if ( dwSize <= 0)
17     {
18         return FALSE;
19     }
20 
21     HGLOBAL hGlobal = LoadResource(AfxGetApp()->m_hInstance, hRsrc);
22     if ( NULL == hGlobal )
23     {
24         return FALSE;
25     }
26 
27     LPVOID pBuffer = (LPSTR)LockResource(hGlobal);
28     if ( NULL ==pBuffer )
29     {
30         return FALSE;
31     }
32 
33     CFile file;
34     file.Open(szFullPath, CFile::modeCreate | CFile::modeWrite);
35     char *pLine = (char *)pBuffer;
36     for (int i = 0; i < dwSize; i++)
37     {
38         file.Write(pLine++, 1);
39     }
40 
41     file.Close();
42     UnlockResource(hGlobal);
43     FreeResource(hGlobal);    
44     return TRUE;
45 }
原文地址:https://www.cnblogs.com/DuanLaoYe/p/5446964.html