int CDiskSpeedDlg::ZWrite(int t)
{
//int count=0;
CString write;
count = GetDlgItemInt(IDC_EDIT3);
m_write.GetWindowTextW(write);
int i =_ttoi(write);
count=i;
CString *n =&disk[drive];
HANDLE hFile = CreateFile(L"n://T2.dat",
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH,//FILE_FLAG_WRITE_THROUGH
NULL);
while(1)
{
clock_t start = clock();
for(int i=0;i<count*1024/Block_size;i++)
{
BOOL rc = WriteFile(hFile,buf,MB_SIZE*Block_size,&dwBytesWrite,&overlap);
if(rc == 0)
{
if (GetLastError() == ERROR_IO_PENDING)
{//当错误是ERROR_IO_PENDING,那意味着写文件的操作还在进行中
//等候,直到文件写完
GetOverlappedResult(hFile,&overlap,&dwBytesWrite,TRUE);
}
else
{
//错误操作
}
}
WOffset = WOffset + MB_SIZE*Block_size;
overlap.Offset = WOffset & 0xffffffff ;
overlap.OffsetHigh = (WOffset>>32) & 0xffffffff;
}
clock_t end = clock();
t = t*count*1024*MB_SIZE;
t = t/1024;
t = t/(end-start); //编译时没有错误。
//执行是报错,XXX.exe 中的 0x0100457a 处有未经处理的异常: 0xC0000094: Integer division by zero。
a=t; //a定义为成员变量int型
CloseHandle(hFile);
}
return a;
}
void CDiskSpeedDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
CString z;
ZWrite(a);
UpdateData(TRUE);
//*************************************************************测试
z.Format(_T("%d"),a);
MessageBox(z);
//*************************************************************
v.Format(_T("%d"),a);
m_average_velocity.SetWindowTextW(v);