16,471
社区成员
发帖
与我相关
我的任务
分享
// test2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "test2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// 唯一的应用程序对象
CWinApp theApp;
using namespace std;
__int64 myFileSeek (HANDLE hf, __int64 distance, DWORD MoveMethod);
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;
// 初始化 MFC 并在失败时显示错误
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: 更改错误代码以符合您的需要
_tprintf(_T("错误: MFC 初始化失败\n"));
nRetCode = 1;
}
else
{
// TODO: 在此处为应用程序的行为编写代码。
}
HANDLE hfile=CreateFile(TEXT("\\\\.\\PhysicalDrive0"),GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
int i=0,a;
byte buff[512];
__int64 end=160041885184;//最后倒数512字节前的位置
if(myFileSeek(hfile,end,FILE_BEGIN)==-1)
{
cout<<"出错:"<<i<<endl;
cout<<"到达末尾了吗?"<<endl;
}
ReadFile(hfile,buff,512,0,NULL);//最起码512字节,否则读取会出错!否则就为空!!!!!!,这里出错时因为写不到缓存里面buff
cout<<buff<<endl;
cout<<i<<endl;
cin>>a;
cout<<i<<endl;
int j;
cin>>j;
return nRetCode;
}
__int64 myFileSeek (HANDLE hf, __int64 distance, DWORD MoveMethod)
{
LARGE_INTEGER li;
li.QuadPart = distance;
li.LowPart = SetFilePointer (hf,
li.LowPart,
&li.HighPart,
MoveMethod);
if (li.LowPart == INVALID_SET_FILE_POINTER && GetLastError()
!= NO_ERROR)
{
li.QuadPart = -1;
}
return li.QuadPart;
}