Presentation is loading. Please wait.

Presentation is loading. Please wait.

Files in Windows API David Halbig Lopez.

Similar presentations


Presentation on theme: "Files in Windows API David Halbig Lopez."— Presentation transcript:

1 Files in Windows API David Halbig Lopez

2 What means files in Windows API?
Files means all the things that we can do with files that exist on the system or that we create our files with code and then we used it in the way we like

3 Things to do with files In total we have more than 50 methods that use files But the most important are:Create, Copy, Read, Write and delete

4 How to create a file hFile = CreateFile(argv[1], // name of the write GENERIC_WRITE, // open for writing 0, // do not share NULL, // default security CREATE_NEW, // create new file only FILE_ATTRIBUTE_NORMAL, // normal file NULL); // no attr. template This is the code to code to create a file as we see the first is the name we want that that file has and we can use this even to open a file, the second is the desire of access for example in that argument we can use GENERIC_WRITE or GENERIC_READ so if we want to use both we just need to put both of them and then we can read and write that file, the third argument is for if we want that this file is opened more than one time at the same time but we have to take care because data can be overwritten, the fifth parameter is for if we want to create a new file CREATE_NEW or open an existing one OPEN_EXISTING. When we open a file so it create like a road between the file and our program

5 How to delete a file BOOL WINAPI DeleteFile( _In_ LPCTSTR lpFileName ); With the method delete we just need to use that method and as parameter we use the name of the file we want to delete if it fails return 0 and if dont fail return non zero

6 Read a file ReadFileEx(hFile, ReadBuffer, BUFFERSIZE-1, &ol, FileIOCompletionRoutine) With that method we we read from a file but first of all we need to open the file using the CreateFile method or with OpenFile method, then we can use it to read from a file So the first argument is the handler, the second one is a pointer to the buffer for example we can use an array where, the third is the number of bits that are going to be read The fouth is an OverLapped (Contains information used in asynchronous (or overlapped) input and output (I/O).) data structure. And the last one is FileIOCompletionRoutine callback function And it shows if the read method has been done correctly.

7 Write file WriteFile( hFile, // open file handle DataBuffer, // start of data to write dwBytesToWrite, // number of bytes to write &dwBytesWritten, // number of bytes that were written NULL); // no overlapped structure This is the method to write in a file as i said before, we have to be sure that we have open the file with the methods i said before because there must be a conection between the programm and the file and this method dont make that conection. So for make this method work we need the handles as first argument, the buffer that have all the data that we want to write on the file as second argument then how much bytes of that buffer we want to write as third argument, and the fourth one is a pointer to the variable that has the number of bytes to write, and the last one is the overlapped structure.

8 ¿Questions? Source:


Download ppt "Files in Windows API David Halbig Lopez."

Similar presentations


Ads by Google