Results 1 to 6 of 6

Thread: using GetDiskFreeSpaceEx

  1. #1

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Lightbulb using GetDiskFreeSpaceEx

    Anyone have any examples of how to use this function? Thanks
    Matt

  2. #2
    jim mcnamara
    Guest
    Code:
    typedef BOOL (WINAPI* PFNGETDISKFREESPACEEX)(LPCTSTR,   
                                              PULARGE_INTEGER,	
    		 	                  PULARGE_INTEGER,  
                                              PULARGE_INTEGER); 
    if((hModule = ::LoadLibrary("KERNEL32.DLL"))){  
             PFNGETDISKFREESPACEEX pDiskFreeSpaceEx = NULL;   // Get free space on partition  
              if(!(pDiskFreeSpaceEx = (PFNGETDISKFREESPACEEX) ::GetProcAddress(hModule, "GetDiskFreeSpaceExA")))  
                {DWORD dwSectorsPerCluster = 0;     
                 DWORD dwBytesPerSector    = 0;        
                 DWORD dwFreeClusters      = 0;          
                 DWORD dwClusters          = 0;          		             
                if(::GetDiskFreeSpace(m_DriveInfo.m_aPartitions[iIndex].m_szRoot,
                                       &dwSectorsPerCluster,                          
                                       &dwBytesPerSector,                           
                                       &dwFreeClusters,                          
                                       &dwClusters) == FALSE) { 
         // Error      // Release library      ::FreeLibrary(hModule);       
         return;    }              
        ULARGE_INTEGER uliTotalNumberOfBytes;    
        ULARGE_INTEGER uliTotalNumberOfFreeBytes;              
        uliTotalNumberOfBytes.QuadPart     = dwClusters * dwBytesPerSector * dwSectorsPerCluster;
        uliTotalNumberOfFreeBytes.QuadPart = dwFreeClusters * dwBytesPerSector * dwSectorsPerCluster;  }  
    else  {    
        ULARGE_INTEGER uliFreeBytesAvailableToCaller;    
        ULARGE_INTEGER uliTotalNumberOfBytes;    
        ULARGE_INTEGER uliTotalNumberOfFreeBytes;     
        if(::GetDiskFreeSpaceEx(m_DriveInfo.m_aPartitions[iIndex].m_szRoot,                            
                                  &uliFreeBytesAvailableToCaller,
                                &uliTotalNumberOfBytes,
                                &uliTotalNumberOfFreeBytes) == FALSE)    {      
              // Error       // Release library      ::FreeLibrary(hModule);      
         return;    }  
    }}

  3. #3
    New Member
    Join Date
    Apr 2002
    Posts
    1

    Hi

    Here is an example of how I use it...

    PHP Code:
        __int64 userBytes;
    __int64 totalBytes;
    __int64 totalFreeBytes;


    GetDiskFreeSpaceEx("C:",(PULARGE_INTEGER) &userBytes, (PULARGE_INTEGER) &totalBytes, (PULARGE_INTEGER) &totalFreeBytes); 
    With Visual Studio, cout has problems with __int64's, so you have to add something like this:

    PHP Code:

    ostream
    operator<<(ostreamos__int64 i )
    {
           
    char buf[20];
           
    sprintf(buf,"%I64d");
           
    os << buf;
           return 
    os;
    }; 
    Anyhow, the code above shows correct drive information for my drives under XP. Good luck.
    Last edited by chachi; Apr 6th, 2002 at 04:18 PM.

  4. #4

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    great, thanks guys
    Matt

  5. #5

    Thread Starter
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    I was wondering could I use just plain 'int' as the data type becasue I have to display it in a message box which needs to convert it from a integer to string format. Thanks
    Matt

  6. #6
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    no, it's too small
    but I think sprintf supports 64-bit integers (look in the flags table)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width