PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: AfxGetFileSize / AfxFileLen  (Read 190 times)

Bumblebee

  • Junior Member
  • **
  • Posts: 75
AfxGetFileSize / AfxFileLen
« 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?
Logged

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3325
Re: AfxGetFileSize / AfxFileLen
« Reply #1 on: February 13, 2021, 12:02:08 PM »

It already returns a 64 bit integer (ULONGLONG), not an ULONG.

Please try:

Code: [Select]
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.

Bumblebee

  • Junior Member
  • **
  • Posts: 75
Re: AfxGetFileSize / AfxFileLen
« Reply #2 on: February 14, 2021, 05:03:47 AM »

It works! Thank-you :)
Logged