_tstati64 function is not supported on this system

Radim Langer 101 Reputation points
2020-11-19T10:40:21.86+00:00

Hello,
recently I have migrated my old VS2010 project into VS2019. But I still need a compatibility with Windows XP. Therefore, I'm using Windows SDK Version 7.0 and Visual Studio 2017 - Windows XP (v141_xp) Platform Toolset. Everything works but now I have encountered this issue. In my program, I call _tstati64 function. When running the application on XP the function fails and there is "This function is not supported on this system" message in GetLastError. However, it works on Windows 7 and Windows 2010.

Why this function worked when application was linked in VS2010 and doesn't work when linked in VS2019? Is there any list of functions which should not be used when linked in VS2019?

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,660 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,772 questions
{count} votes

Accepted answer
  1. Strive Sun-MSFT 426 Reputation points
    2020-11-20T03:18:10.657+00:00

    Hello @Radim Langer ,

    The _tstat64 function is actually a package of GetFileAttributesEx and _getdrive. You can add <windows.h> and <direct.h>to your project to call these two functions separately.  The minimum supported system is windows xp.

    int CDECL _tstat64(const _TCHAR *path, struct __stat64 *buf)  
    {  
      DWORD dw;  
      WIN32_FILE_ATTRIBUTE_DATA hfi;  
      unsigned short mode = ALL_S_IREAD;  
      int plen;  
      
      TRACE(":file (%s) buf(%p)\n",path,buf);  
      
      plen = _tcslen(path);  
      while (plen && path[plen-1]==' ')  
        plen--;  
      
      if (plen && (plen<2 || path[plen-2]!=':') &&  
              (path[plen-1]==':' || path[plen-1]=='\\' || path[plen-1]=='/'))  
      {  
        *_errno() = ENOENT;  
        return -1;  
      }  
      
      if (!GetFileAttributesEx(path, GetFileExInfoStandard, &hfi))  
      {  
          TRACE("failed (%d)\n",GetLastError());  
          *_errno() = ENOENT;  
          return -1;  
      }  
      
      memset(buf,0,sizeof(struct __stat64));  
      
      /* FIXME: rdev isn't drive num, despite what the docs say-what is it?  
         Bon 011120: This FIXME seems incorrect  
                     Also a letter as first char isn't enough to be classified  
    		 as a drive letter  
      */  
      if (isalpha(*path)&& (*(path+1)==':'))  
        buf->st_dev = buf->st_rdev = toupper(*path) - 'A'; /* drive num */  
      else  
        buf->st_dev = buf->st_rdev = _getdrive() - 1;  
       ...  
    

    Refer: _tstat64

    You can also use the GetFileInformationByHandle function to obtain file information. The minimum supported system for this function is Windows XP.

    typedef struct _BY_HANDLE_FILE_INFORMATION {  
       DWORD    dwFileAttributes;  
       FILETIME ftCreationTime;  
       FILETIME ftLastAccessTime;  
       FILETIME ftLastWriteTime;  
       DWORD    dwVolumeSerialNumber;  
       DWORD    nFileSizeHigh;  
       DWORD    nFileSizeLow;  
       DWORD    nNumberOfLinks;  
       DWORD    nFileIndexHigh;  
       DWORD    nFileIndexLow;  
     } BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION, *LPBY_HANDLE_FILE_INFORMATION;  
    

    Thank you!

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.