📄 memorymap.cpp
字号:
// MemoryMap.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <iostream.h>
BOOL FileReplay(char* pszPathName);
static char filepath[]="random.txt1";
int main(int argc, char* argv[])
{
char modulepath[MAX_PATH];
GetModuleFileName(NULL,modulepath,MAX_PATH);//初始化地址//
char *pdest = strrchr(modulepath,'\\');
strncpy(pdest+1,filepath,sizeof(filepath));
cout<<"Start check the resulr :s/S"<<endl;
char s;
do
{
cin>>s;
}while( s!='s'&& s!='S');
FileReplay(modulepath);
//退出
cout<<"Exit :x/X "<<endl;
char x;
do
{
cin>>x;
}while( x!='x'&& x!='X');
return 0;
}
BOOL FileReplay(char* pszPathName)
{
HANDLE hFile = CreateFile(pszPathName,GENERIC_WRITE|GENERIC_READ,0,NULL
,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
if(hFile == INVALID_HANDLE_VALUE)
{
printf("File could not be opened.");
return FALSE;
}
DWORD dwFileSize = GetFileSize(hFile,NULL);
HANDLE hFileMap = CreateFileMapping(hFile,NULL,PAGE_READWRITE,0,
dwFileSize,NULL);
if(hFileMap == NULL){
CloseHandle(hFile);
return FALSE;
}
int *pIntFile = (int *)MapViewOfFile(hFileMap,FILE_MAP_WRITE,0,0,0);
if(pIntFile == NULL){
CloseHandle(hFileMap);
CloseHandle(hFile);
return FALSE;
}
int max = 0;
for(int i(0); i < dwFileSize/sizeof(UINT) ; i++)
{
if (pIntFile[i] >= max)
{
max = pIntFile[i];
cout<<pIntFile[i]<<" ";
}
else
{
cout<<"failed"<<endl;
break;
}
}
// pIntFile[i] = 0;
UnmapViewOfFile(pIntFile);
CloseHandle(hFileMap);
SetFilePointer(hFile,dwFileSize,NULL,FILE_BEGIN);
SetEndOfFile(hFile);//实际上不需要写入了。
CloseHandle(hFile);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -