PlanetSquires Forums

Support Forums => WinFBX - Windows Framework for FreeBASIC => Topic started by: Bumblebee on February 13, 2021, 08:48:55 AM

Title: AfxGetFileSize / AfxFileLen
Post by: Bumblebee on February 13, 2021, 08:48:55 AM
AfxGetFileSize / AfxFileLen
Returns the size in bytes of the specified file.

FUNCTION AfxGetFileSize (BYREF wszFileSpec AS WSTRING) AS ULONGLONG
FUNCTION AfxFileLen (BYREF wszFileSpec AS WSTRING) AS ULONGLONG
Parameter   Description
wszFileSpec   The path to a file. To extend the limit of MAX_PATH wide characters to 32,767 wide characters, prepend "\\?\" to the path.
Return value
The size in bytes of the file on success, or 0 on failure.

It's not working for really big files, such as Pagefile.sys
Can ulong be replaced with a single or double type?
Title: Re: AfxGetFileSize / AfxFileLen
Post by: José Roca on February 13, 2021, 12:02:08 PM
It already returns a 64 bit integer (ULONGLONG), not an ULONG.

Please try:


PRIVATE FUNCTION AfxGetFileSize2 (BYREF wszFileSpec AS WSTRING) AS ULONGLONG
   DIM fd AS WIN32_FIND_DATAW
   DIM hFind AS HANDLE = FindFirstFileW(wszFileSpec, @fd)
   IF hFind = INVALID_HANDLE_VALUE THEN RETURN 0
   FindClose hFind
   IF (fd.dwFileAttributes AND FILE_ATTRIBUTE_DIRECTORY) <> FILE_ATTRIBUTE_DIRECTORY AND _
      (fd.dwFileAttributes AND FILE_ATTRIBUTE_TEMPORARY) <> FILE_ATTRIBUTE_TEMPORARY THEN
      DIM ullSize AS ULONGLONG = (fd.nFileSizeHigh * (&hFFFFFFFFull + 1)) + fd.nFileSizeLow
      RETURN ullSize
   END IF
END FUNCTION


and tell me if it works and I will change the original AfxGetFileSize function.

I have added the ull suffix to &hFFFFFFFFull + 1. Without it, it evaluates to -1 + 1, which is zero, instead of 4294967296.
Title: Re: AfxGetFileSize / AfxFileLen
Post by: Bumblebee on February 14, 2021, 05:03:47 AM
It works! Thank-you :)