Trying to convert my app from file streams to file handles!
Hi
I've managed to convert most of my program from using the c FILE
to using proper Windows handles. I've converted my fread to ReadFile
and so on. Now part of my program requires the use of ftell() so my
program knows where it is in the file. What is the Windows equivalent
of this function? I've not been able to find it. The other command
equivalent I'm looking for is the fseek command so I can skip past
parts of a file that I'm not interested in. Any ideas??
Cheers,
Steve
it seems your taking a step away from portability, why not use std::fstream instead? Unless you are sure you will only need to work on Win32 based systems.
Doesn't readfile just read the file into memory allocated by the user? In that case I think that it is up to you to keep track of that. Check out MSDN and search for ReadFile for more info
hth
moe.ron
Doesn't readfile just read the file into memory allocated by the user? In that case I think that it is up to you to keep track of that. Check out MSDN and search for ReadFile for more info
hth
moe.ron
It's somewhat unintuitively done by using SetFilePointer() with a 0 byte offset to the current position. But searching for "obtaining file pointer position" immediately lead me to this result:
MSDN: Positioning a File Pointer
-Markus-
MSDN: Positioning a File Pointer
-Markus-
Slight off topic, but don't convert standard ansi C IO to Windows crap. If you'd had look at Windows CRT sources you would see that these functions (fopen, fread, etc.) use core win ones (ReadFile, etc.). Basically, fread calls ReadFile to perform IO.
Quote:Original post by Kiput
Slight off topic, but don't convert standard ansi C IO to Windows crap. If you'd had look at Windows CRT sources you would see that these functions (fopen, fread, etc.) use core win ones (ReadFile, etc.). Basically, fread calls ReadFile to perform IO.
Kiput, I think you mean ReadFile calls the fread function, no?? ReadFile is not a core function.
Thanks for the replies. Look, I would love to stick with the standard i/o functions but I've found no way of discovering a file's date/time stamp using these functions. Maybe I've just not looked hard enough. The only function I found which allows you to do this requires windows file handles, hence the switch to file handles. The other is an old dos function. If someone know of a better way to find the date/time stamp using standard i/o functions I'd love to hear it. :)
Steve
Quote:Original post by Steve-BNo, ReadFile() is implemented in Kernel32.dll. fread() is part of the CRT (so it's linked into your app usually), and just wraps around ReadFile() in a portable way. fread() also does buffering for performance reasons (4k buffers in my implementation [VS.NET 2003]). If you have the CRT source code installed as part of visual studio, look in fread.c.
Kiput, I think you mean ReadFile calls the fread function, no?? ReadFile is not a core function.
Quote:Original post by Steve-BI don't know of any functions offhand. The reason it's difficult to find information is that it's probably going to be platform/compiler specific. a file stream doesn't have to be a file on disk. stdin is a FILE*, but it's not a file on disk, so how would you get its creation time? Also, I think you can wrap sockets in a FILE* under unix systems.
Thanks for the replies. Look, I would love to stick with the standard i/o functions but I've found no way of discovering a file's date/time stamp using these functions. Maybe I've just not looked hard enough. The only function I found which allows you to do this requires windows file handles, hence the switch to file handles. The other is an old dos function. If someone know of a better way to find the date/time stamp using standard i/o functions I'd love to hear it. :)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement