Skip to main content
gamedev.net
🔒 Locked

HANDLE to pointer

Started by DarkPretender 3 replies 300+ views
Original Post
DarkPretender
DarkPretender
Im creating a function to find the size of a file. BOOL WINAPI GetFileSizeEx( HANDLE hFile, PLARGE_INTEGER lpFileSize ) { char temp; lpFileSize = 0; FILE *File = (hFile); while(!feof(File)) { temp=fgetc(File); lpFileSize++; } if(ferror(File)) { return false; } return true; } As you can obviously tell....it doesn''t work. I get errors. It sucks. Anybody know what cast I can use to do this? FILE *File = const_cast(hFile); this gives me an error saying I need to make my own conversion, because reinterpret_cast and const_cast can not do it. Anybody have a clue? error C2440: ''initializing'' : cannot convert from ''void *'' to ''struct _iobuf *'' if that helps....
luxitan
luxitan
have you tried FILE *File = (FILE*)hFile;
or
FILE *File = (FILE*)&hFile
To be considered a genius you just have to say what everybody knows in a way very few understand
Wildfire
Wildfire

FILE *file = (FILE*)hFile;


There is a function called "GetFileSize" which returns either
a DWORD (32bit), or a double DWORD (64bit), which is the same as your version. It is probably a lot faster then your version though.
How do I set my laser printer n stun? o
MauMan
MauMan
A better way to find out the size of a file is to fseek() to the end and then to call ftell(). It''s platform independent, but it main drawback is it may not work on really big files (2-4Gig+) on some systems.
---CyberbrineDreamsSuspected implementation of the Windows idle loop: void idle_loop() { *((char*)rand()) = 0; }
DarkPretender
DarkPretender
quote:
Original post by Wildfire

FILE *file = (FILE*)hFile;


There is a function called "GetFileSize" which returns either
a DWORD (32bit), or a double DWORD (64bit), which is the same as your version. It is probably a lot faster then your version though.


Interesting....

This is what I thought. I was hired to recreate this library, Kernel32Ex.lib

Obviously a take off of the Kernel32.lib...

I was wondering why he had me do this. I must also do SetFilePointerEx(...)

[EDIT] opps, forgot to say that that worked as well. Thanks :o)

[edited by - DarkPretender on July 21, 2003 11:59:04 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.