How can I read the size of "C:\"?

This is a discussion on How can I read the size of "C:\"? within the C++ Programming forums, part of the General Programming Boards category; How can I read the size of "C:\"?...

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Question How can I read the size of "C:\\"?

    How can I read the size of "C:\\"?

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    What in god's good name dost thou mean?

    1. C
    2. :
    3. \\
    4. \0

    4 bytes. Not to be confused with the sizeof the char* pointer that composes this string. That's how I read it. I don't know how you are reading things. Or where you are reading them from. Or in what context. You should probably elaborate, google, etc. on all these threads you are making because they're pretty vague really.

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Okay, I admit that I was not clear enough, I am sorry.

    I meant the capacity of the partition C.

  4. #4
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    If you're using Windows, then the call GetDiskFreeSpaceEx will help you. Might have to remove the Ex depending on which version of the OS you have. Look it up in MSDN for further help.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  5. #5
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I have allready tried that but I gave up on it.

    converting LPDWORD to DWORD

    Could you show me exactly how to do I want to do?

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    this worked for me. The code in the thread "converting LPDWORD to DWORD" is incorrect. GetDiskFreeSpace() parameters are pointer to your own objects -- whenever you see LPDWROD in Win32 API function parameters you must pass a pointer to your own object as shown below.
    Code:
    #include <windows.h>
    
    
    int main()
    {
    
      const char* lpRootPathName = "C:\\";
      DWORD SectorsPerCluster = 0;
      DWORD BytesPerSector = 0;
      DWORD NumberOfFreeClusters = 0;
      DWORD TotalNumberOfClusters = 0;
      GetDiskFreeSpace(lpRootPathName,&SectorsPerCluster,
    	  &BytesPerSector,&NumberOfFreeClusters,&TotalNumberOfClusters);
      char user[255];
      sprintf(user,"Sectors Per Cluster: %d\r\n",SectorsPerCluster);
      if(SectorsPerCluster > 0)
      MessageBox(0, user, "C:\\/%Details%/", MB_OK | MB_ICONINFORMATION);
    
      return 0;
    
    }
    Last edited by Ancient Dragon; 09-11-2005 at 04:01 PM.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Well learning basic C++ would be a start.

    Your code
    Code:
      LPCTSTR lpRootPathName = "C:\\";
      LPDWORD lpSectorsPerCluster = 0;
      LPDWORD lpBytesPerSector = 0;
      LPDWORD lpNumberOfFreeClusters = 0;
      LPDWORD lpTotalNumberOfClusters = 0;
      GetDiskFreeSpace ( lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, 
        lpNumberOfFreeClusters, lpTotalNumberOfClusters);
      char* user;
      wsprintf(user,"Sectors Per Cluster: %d\r\n",dwSectorsPerCluster);
      if(dwSectorsPerCluster > 0)
      MessageBox(hwnd, user, "C:\\/%Details%/", MB_OK | MB_ICONINFORMATION);
    You pay no attention to the meaning of the parameters, you simply declare variables of the right type in the hopes that it will shut the compiler up. It takes more than that to write a program. You can't just create say a char * variable and then just use it because that's what the function says it wants.

    For example, any reading of the manual page would reveal that all those DWORD parameters were output parameters (that's where the answers would be stored).

    So it might be something like this
    Code:
      LPCTSTR lpRootPathName = "C:\\";
      DWORD SectorsPerCluster = 0;
      DWORD BytesPerSector = 0;
      DWORD NumberOfFreeClusters = 0;
      DWORD TotalNumberOfClusters = 0;
      GetDiskFreeSpace ( lpRootPathName, &SectorsPerCluster, &BytesPerSector, 
        &NumberOfFreeClusters, &TotalNumberOfClusters);
      char user[100];
      wsprintf(user,"Sectors Per Cluster: %lu\r\n",SectorsPerCluster);
      if(SectorsPerCluster > 0)
      MessageBox(hwnd, user, "C:\\/%Details%/", MB_OK | MB_ICONINFORMATION);
    > If the function fails, the return value is zero. To get extended error information, call GetLastError.
    Oh yeah, you need to do this as well, that's something else you can bone up on - handling errors.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Thanks.
    Oh yeah, you need to do this as well, that's something else you can bone up on - handling errors.
    Okay, where do I start?

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    > Okay, where do I start?
    By reading "If the function fails, the return value is zero. "
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I meant: bone up how?

  11. #11
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by Cool-August
    I meant: bone up how?
    by reading MSDN documentation for the Wine32 api functions you want to use. see www.msdn.microsoft.com

  12. #12
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    Start learning to read stuff for yourself - we're not going to spoon-feed you every single API function!!!!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 12:48 PM
  2. Trouble with DMA Segmentation Faults
    By firestorm717 in forum C Programming
    Replies: 2
    Last Post: 05-07-2006, 09:20 PM
  3. Invalid conversion from 'void*' to 'BYTE' help
    By bikr692002 in forum C++ Programming
    Replies: 9
    Last Post: 02-22-2006, 10:27 AM
  4. char problem
    By eXistenZ in forum Windows Programming
    Replies: 36
    Last Post: 02-21-2005, 05:32 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21