1 BOOL CreateFileDemo(TCHAR* pFileName, DWORD dwSize)
 2 {
 3     HANDLE hFile;
 4     HANDLE hMapFile;
 5 
 6     hFile = CreateFile(
 7         pFileName,
 8         GENERIC_WRITE | GENERIC_READ,
 9         FILE_SHARE_READ,
10         NULL,
11         CREATE_ALWAYS,
12         FILE_ATTRIBUTE_NORMAL,
13         NULL
14         );
15     if( hFile == INVALID_HANDLE_VALUE )
16     {
17         OutputDebugString(_T("CreateFile fail!/r/n"));
18         return FALSE;
19     }
20 
21     hMapFile = CreateFileMapping(
22         hFile,
23         NULL,
24         PAGE_READWRITE,
25         0,
26         dwSize,
27         NULL
28         );
29     if( hMapFile == NULL )
30     {
31         OutputDebugString(_T("CreateFileMapping fail!/r/n"));
32         CloseHandle( hFile );
33         return FALSE;    
34     }
35 
36     CloseHandle( hMapFile );
37     CloseHandle( hFile );
38 
39     return TRUE;
40 }

 

相关文章:

  • 2021-08-17
  • 2021-08-10
  • 2021-09-29
  • 2022-01-11
  • 2022-12-23
  • 2021-07-08
  • 2021-09-04
猜你喜欢
  • 2021-11-15
  • 2021-11-17
  • 2021-12-06
  • 2022-03-01
  • 2022-01-17
  • 2021-06-22
  • 2022-12-23
相关资源
相似解决方案