• Advertisement
Sign in to follow this  

Trying to convert my app from file streams to file handles!

This topic is 4684 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
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

Share this post


Link to post
Share on other sites
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-

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Quote:
Original post by Steve-B
Kiput, I think you mean ReadFile calls the fread function, no?? ReadFile is not a core function.
No, 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.

Quote:
Original post by Steve-B
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. :)
I 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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement