Skip to main content
gamedev.net
🔒 Locked

Win GetFileSize() problem

Started by Tertsi Nov 28, 2004 at 6:27 AM 1 replies 550+ views
Original Post
Tertsi
Tertsi

// 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]
darookie
darookie
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).

Topic Locked

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

Sign in to reply to this topic.