windows核心编程第17章 一个文件一个缓存
// ReadFileByOneBuffer.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<Windows.h>
int main()
{
DWORD ReturnLength;
HANDLE hFile = CreateFile("E:/862.exe", GENERIC_READ | GENERIC_WRITE,
0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
{
printf("创建文件对象失败%d ", GetLastError());
return 0;
}
char*v1 = (char*)VirtualAlloc(NULL, 1281922, MEM_COMMIT, PAGE_READWRITE);
DWORD start, end;
start = GetTickCount();
BOOL IsOK=ReadFile(hFile, v1, 1281922, &ReturnLength, NULL);
if (IsOK == TRUE)
printf("%d", ReturnLength);
end = GetTickCount();
printf("time=%d\n", end - start);
CloseHandle(hFile);
getchar();
return 0;
}