/*************************************************************** * CMyapp::OnSomeFunction * Inputs: * * * Result: Opens a file and munches through it. * * * Effect: * * Notes: * ***************************************************************/ void CPlopDlg::OnButton2() { HANDLE hFile = CreateFile("c:\\uml\\argouml.jar", // open MYFILE.TXT GENERIC_READ, // open for reading FILE_SHARE_READ, // share for reading NULL, // no security OPEN_EXISTING, // existing file only FILE_ATTRIBUTE_NORMAL, // normal file NULL); // no attr. template if (hFile == INVALID_HANDLE_VALUE) { return; //ErrorHandler("Could not open file."); // process error } BYTE btBuffer[128000]={'\0'}; DWORD dwRead = 0; BOOL bOK = ReadFile( hFile, btBuffer, 128000,&dwRead,NULL); int iLevel = 0; while( dwRead > 0 && bOK == TRUE ) { bOK = ReadFile(hFile, btBuffer, 128000,&dwRead,NULL); for(int i = 0;i < dwRead;i++) { //Do something with the buffered data. btBuffer[i] = btBuffer[i]; } //Null out the memory when through with it. FillMemory(btBuffer,128000,'\0'); //Diag flag to indicate progress. if( iLevel % 10 == 0) { TRACE("At level %ld\n",iLevel); } iLevel++; } TRACE("File read.\n"); CloseHandle(hFile); }