Thread: getting disk size information

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    16

    getting disk size information

    as in subject, how to get disk size, not free space (GetDiskFreeSpace) but the size of c: drive...
    thanks for replies

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,793

    Re: getting disk size information

    Originally posted by Turek
    as in subject, how to get disk size, not free space (GetDiskFreeSpace) but the size of c: drive...
    thanks for replies
    Look closer at that function, and your answer will become apparent

    Code:
    BOOL GetDiskFreeSpace(
      LPCTSTR lpRootPathName,          // root path
      LPDWORD lpSectorsPerCluster,     // sectors per cluster
      LPDWORD lpBytesPerSector,        // bytes per sector
      LPDWORD lpNumberOfFreeClusters,  // free clusters
      LPDWORD lpTotalNumberOfClusters  // total clusters
    );
    BytesPerSector * SectorsPerCluster * TotalNumberOfClusters

    That will give disk size in bytes

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    god damn true!! thanks man!!!

  4. #4
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    but i get an error, look at my code:
    PHP Code:
    #include <iostream>
    #include <string>

    using namespace std;

    void main()
    {
        
    DWORD dwSectorsPerCluster,dwBytesPerSector,dwNumberOfFreeClusters,dwTotalNumberOfClusters;
        if (
    GetDiskFreeSpace(NULL,&dwSectorsPerCluster,&dwBytesPerSector,&dwNumberOfFreeClusters,&dwTotalNumberOfClusters)) {
            
    double space = &dwSectorsPerCluster * &dwBytesPerSector * &dwTotalNumberOfClusters;
            
    cout << space 1073741824 << endl;
            
    system("PAUSE");
        } else { 
            
    cout << "not hd" << endl;
            
    system("PAUSE");
        }

    error is:
    file.cpp(38) : fatal error C1010: unexpected end of file while looking for precompiled header directive
    the funniest is that file has only 37 lines
    i am having Visual C++ 60...
    any ideas ??

  5. #5
    Unregistered
    Guest
    It is trying to "precompile" the windows headers, but you are not including them. I think you can include "windows.h" first in the file to get rid of it, or you can also change the settings for the project so that it does not try to use a precompiled header. Goto project->settings. Select the c/c++ tab. Pulldown the category combo box to Precompiled headers. Select the radio button "Not using precompiled headers"

  6. #6
    Registered User
    Join Date
    Jul 2002
    Posts
    16
    thanks a lot!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. Generic heapsort
    By Sephiroth1109 in forum C Programming
    Replies: 15
    Last Post: 12-07-2007, 06:14 PM
  3. char problem
    By eXistenZ in forum Windows Programming
    Replies: 36
    Last Post: 02-21-2005, 06:32 AM
  4. Comment this Program
    By kishorepalle in forum C Programming
    Replies: 11
    Last Post: 10-05-2004, 06:41 AM
  5. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM