In Visual C , the MFC (Microsoft Basic Class) provides two classes of CFILE and CSTDIOFILE for file input and output operations in programs. The CFILE class provides file operations based on binary stream, functionality similar to the FREAD () and fwrite () functions in the C language. CSTDIOFILE provides a string-based file operation and functionality is similar to the FGETS () and FPUTS () functions in the C language. However, when using these two classes for file operation, the amount of data read and written for a file must be limited to 65535 bytes. The reason is that the HUGE type pointer is required in the VC to access the 65535 byte, while in the CFILE and CSTDIOFILE class, the FAR type pointer is used. Since the FAR type pointer does not have a cross-segment addressing, the length of the read and write is limited to 65535 bytes. If the size of the data buffer passing to the member function of both CFILE and CSTDIOFILE is greater than 65535 bytes, the VC generates an Assert error. When using Visual C for multimedia program, the author is designed because of the amount of data processed very large, so it is necessary to frequently read and write data greater than 65535 bytes. When using the CFILE and CSTDIOFILE class, it is generally segmentation read and written, and the author feels very cumbersome, and it is easy to cause the program to compile errors. After receiving the relevant literature, the author found the method of reading and writing of giant data using Visual C . Two functions that are not loaded into the document are provided in the MFC CFILE class, which prototypes declares in AFX. H. The function prototype is as follows: DWORD CFILE :: Readhuge (Void Far * lpbuffer, dword dwcount); void cfile :: Writehuge (Const Void Far * LPBuffer, DWORD DWCOUNT); Inside these two functions are used by huge models The transfer buffer is addressed, so you can read the giant data greater than 65535 bytes. The giant buffer required for Readhuge () and Writehuge () functions can be created using Windows API functions GoBalaloc (). As an example, the following block demonstrates the process of copying a large file using the read-Huge () and Writehuge () functions.
{CSTRING NAMEL ("Data1.dat"); CString Name2 ("Data2.dat"); CFile MyFilel (Namel, CFile :: ModeRead); cfile myfile2 (name2, cfile :: modecreate | cfile :: mode write); dword Length = myfile1. GetLength (); Void Far * P = GlobalAlloc (0, Length); if (p = null) {AFXMESSAGEBOX ("Alloc Memory ErROR!");} Myfile1. Readhuge (p, length); myfile2. Readhuge (p, length); myfile1. Close (); myfile2. Close (); AfxMessageBox ( "File Copy Succeed!");} (Author: Chengdu Lu Jun)