Jump to content
  • Advertisement
Sign in to follow this  
Tertsi

Win GetFileSize() problem

This topic is 5043 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

// C++

HANDLE hFile = CreateFile("C:\\whatever\\whatever.log", GENERIC_READ | GENERIC_WRITE, 0, NULL, NULL, FILE_ATTRIBUTE_NORMAL, NULL);
	unsigned long filesize = GetFileSize(hFile, NULL);
	cout << "MGEngine.log filesize: " << filesize << endl;

	CloseHandle(hFile);
	return 0;



How come this code doesn't display the correct filesize of any file you try to test this with, and instead GetFileSize just returns an error? [Edited by - Tertsi on November 28, 2004 7:15:56 AM]

Share this post


Link to post
Share on other sites
Advertisement
Read the docs for CreateFile carefully:

HANDLE hFile = CreateFile("C:\\whatever\\whatever.log", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);


Attributes need to be OR'ed bit-wise, not logically.
A logical OR will always result in the value TRUE ('1' IIRC), while bit-wise OR will combine the values (same as adding them for powers of two).

Share this post


Link to post
Share on other sites
heh, oops I knew that, just a typo. ^^

Anyway the docs also mentioned that you can use either one of the access flags and I had tried using read without write. The open existing flag seemed to solve my problem though, thanks!

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!