CreateFileMapping 或 MapViewOfFileEx 示例
#include <windows.h>
#include <string>
#include <winbase.h>
#include <iostream>
using namespace std;
void main()
{
HANDLE h;
CHAR *filename;
filename =new CHAR[2500];
wcout<<"enter the file name:";
cin.getline (filename,2500);
h= CreateFile( filename,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,NULL);
cout<<filename;
if (h!=INVALID_HANDLE_VALUE)
{
printf("\nFile is opened/created");
DWORD size = GetFileSize(h, NULL);
HANDLE hFileMapping = CreateFileMapping(h, NULL,PAGE_READONLY, 0, 0, NULL);
CloseHandle(h);
MapViewOfFileEx(hFileMapping, FILE_MAP_READ, 0, 0,0,NULL);
system("Pause");
UnmapViewOfFile(hFileMapping);
}
else
{
printf("\nUnable to open or create file");
}
system ("pause");
}
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询