{
DWORD timebegin = ::timeGetTime();
HANDLE fp = CreateFile(TEXT("E:\\jyzhj2.rar"),//这里输入需要复制的文件 src
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if(fp == NULL)
{
cout<<"错误"<
}
DWORD dwBytesInBlock = GetFileSize(fp,NULL); //文件长度
// 创建文件映射内核对象,句柄保存于hFileMapping
HANDLE hFileMapping = CreateFileMapping(fp,
NULL,
PAGE_READWRITE,
0,//(DWORD)(dwBytesInBlock >> 16),
dwBytesInBlock,//(DWORD)(dwBytesInBlock & 0x0000FFFF),
NULL);
int dwError = GetLastError();
// 释放文件内核对象
CloseHandle(fp);
// 偏移地址
__int64 qwFileOffset = 0;
// 将文件数据映射到进程的地址空间
LPVOID pbFile = (LPVOID)MapViewOfFile( hFileMapping,
FILE_MAP_ALL_ACCESS,
(DWORD)(qwFileOffset >> 32),
(DWORD)(qwFileOffset & 0xFFFFFFFF),
dwBytesInBlock);
HANDLE wp = CreateFile( TEXT("E://仙剑5.rar"),//这里输入 需要粘贴的文件 dst
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_FLAG_SEQUENTIAL_SCAN | FILE_FLAG_WRITE_THROUGH,
NULL);
HANDLE hFileMapping2 = CreateFileMapping( wp,
NULL,
PAGE_READWRITE,
0,//(DWORD)(dwBytesInBlock >> 16),
dwBytesInBlock,//(DWORD)(dwBytesInBlock & 0x0000FFFF),
NULL);
CloseHandle(wp);
LPVOID pbFile2 = (LPVOID)MapViewOfFile( hFileMapping2,
FILE_MAP_ALL_ACCESS,
(DWORD)(qwFileOffset >> 32),
(DWORD)(qwFileOffset & 0xFFFFFFFF),
dwBytesInBlock);
memcpy(pbFile2,pbFile,dwBytesInBlock);
UnmapViewOfFile(pbFile2);
UnmapViewOfFile(pbFile);
CloseHandle(hFileMapping2);
CloseHandle(hFileMapping);
DWORD timeend = ::timeGetTime();
cout<<"CreateFileMapping和MapViewOfFile程序运行时间为"<