Results 1 to 21 of 21

Thread: GetDiskFreeSpace problem

  1. #1

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362

    GetDiskFreeSpace problem

    I have a problem with this code :
    PHP Code:
        LPCTSTR lpDirectoryName=NULL;  //Current disk         
            
    PULARGE_INTEGER lpFreeBytesAvailable=0;
            
    PULARGE_INTEGER lpTotalNumberOfBytes=0;    
            
    PULARGE_INTEGER lpTotalNumberOfFreeBytes=0;

            
    cout << GetDiskFreeSpaceEx(lpDirectoryName
                
    lpFreeBytesAvailable,
                
    lpTotalNumberOfBytes,
                
    lpTotalNumberOfFreeBytes);
        
    iSize = (unsigned int)(lpTotalNumberOfBytes); 
    Why iSize is always not the real free space that I have ? What do I do wrong ?

    reference:
    http://msdn.microsoft.com/library/de...dmref_8bso.asp

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: GetDiskFreeSpace problem

    lpTotalNumberOfBytes
    [out] Pointer to a variable that receives the total number of bytes on the disk that are available to the user associated with the calling thread.
    Windows 2000/XP: If per-user quotas are in use, this value may be less than the total number of bytes on the disk.
    Does any of the bolded stuff apply to you? Could that be the problem?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Also, an unsigned int variable isnt going to hold a value larger then ~4 billion. If you have more then 4 gigs free, you might have a problem.

    Z.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Interpret the value as __int64
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    The problem is the size is ZERO always

  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You have to pass a proper pointer. Declare them as ULARGE_INTEGER, and pass them using & to use the address.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    Code:
    	unsigned __int64 iSize;
    
    		LPCTSTR lpDirectoryName=NULL;           
    		PULARGE_INTEGER lpFreeBytesAvailable=0;
    		PULARGE_INTEGER lpTotalNumberOfBytes=0;    
    		PULARGE_INTEGER lpTotalNumberOfFreeBytes=0;
    
    		cout << GetDiskFreeSpaceEx(lpDirectoryName, 
    			lpFreeBytesAvailable,
    			lpTotalNumberOfBytes,
    			lpTotalNumberOfFreeBytes);
    	iSize = (unsigned int)(lpTotalNumberOfBytes);
                    cout << iSize;

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Originally posted by MasterDaok
    Code:
    	unsigned __int64 iSize;
    
    	LPCTSTR lpDirectoryName = NULL;           
    	ULARGE_INTEGER lpFreeBytesAvailable = 0;
    	ULARGE_INTEGER lpTotalNumberOfBytes = 0;    
    	ULARGE_INTEGER lpTotalNumberOfFreeBytes = 0;
    
    	cout << GetDiskFreeSpaceEx(lpDirectoryName, 
    			&lpFreeBytesAvailable,
    			&lpTotalNumberOfBytes,
    			&lpTotalNumberOfFreeBytes);
    	iSize = lpTotalNumberOfBytes.QuadPart;
                    cout << iSize;
    ...that should work, but passing NULL for the directory name will use the current disk.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    i have more than 0 for size

  10. #10
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Maybe you're right parksie. Maybe those windows names DO confuse people...
    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.

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Encapsulating the fact that it's a pointer inside a new type name is just inviting confusion. Far easier to say ULARGE_INTEGER* rather than PU_LARGE_INTEGER.

    And less messing around with the type system!
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  12. #12

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    Code:
    unsigned __int64 iSize;
    
    	LPCTSTR lpDirectoryName = NULL;           
    	ULARGE_INTEGER lpFreeBytesAvailable = 0;
    	ULARGE_INTEGER lpTotalNumberOfBytes = 0;    
    	ULARGE_INTEGER lpTotalNumberOfFreeBytes = 0;
    
    	cout << GetDiskFreeSpaceEx(lpDirectoryName, 
    			&lpFreeBytesAvailable,
    			&lpTotalNumberOfBytes,
    			&lpTotalNumberOfFreeBytes);
    	iSize = lpTotalNumberOfBytes.QuadPart;
                    cout << iSize;
    
    	iSize = (unsigned int)(lpTotalNumberOfBytes);
    [code]

    No constructor could take the source type, or constructor overload resolution was ambiguous
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(32) : error C2440: 'initializing' : cannot convert from 'const int' to 'union _ULARGE_INTEGER'
    No constructor could take the source type, or constructor overload resolution was ambiguous
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(33) : error C2440: 'initializing' : cannot convert from 'const int' to 'union _ULARGE_INTEGER'
    No constructor could take the source type, or constructor overload resolution was ambiguous
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(40) : error C2593: 'operator <<' is ambiguous
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002\C++.cpp(42) : error C2440: 'type cast' : cannot convert from 'union _ULARGE_INTEGER' to 'unsigned int'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(44) : error C2143: syntax error : missing ';' before 'else'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002(45) : error C2143: syntax error : missing ';' before '{'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002(45) : error C2447: missing function header (old-style formal list?)
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(49) : error C2143: syntax error : missing ';' before 'else'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(52) : error C2065: 'iSize' : undeclared identifier
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002cpp(54) : error C2501: 'memset' : missing storage-class or type specifiers
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(54) : error C2373: 'memset' : redefinition; different type modifiers
    c:\program files\microsoft visual studio\vc98\include\string.h(103) : see declaration of 'memset'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(54) : error C2078: too many initializers
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(56) : error C2143: syntax error : missing ';' before '.'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(56) : error C2501: 'fileOut' : missing storage-class or type specifiers
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(56) : error C2143: syntax error : missing ';' before '.'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(57) : error C2143: syntax error : missing ';' before '.'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(57) : error C2501: 'fileOut' : missing storage-class or type specifiers
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(57) : error C2086: 'fileOut' : redefinition
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(57) : error C2143: syntax error : missing ';' before '.'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(58) : error C2143: syntax error : missing ';' before '.'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(58) : error C2501: 'fileOut' : missing storage-class or type specifiers
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(58) : error C2086: 'fileOut' : redefinition
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(58) : error C2143: syntax error : missing ';' before '.'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(66) : error C2143: syntax error : missing ';' before '<<'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(66) : error C2501: 'cout' : missing storage-class or type specifiers
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(66) : error C2143: syntax error : missing ';' before '<<'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(68) : error C2143: syntax error : missing ';' before '}'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(68) : error C2143: syntax error : missing ';' before '}'
    C:\Documents and Settings\Patrik Desjardins\Mes documents\doc\Summer2002.cpp(68) : error C2143: syntax error : missing ';' before '}'
    Error executing cl.exe.
    [code]

  13. #13
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Take off the "=0" from those initialisers.

    The rest of the errors don't apply to that code, methinks you missed an #include or using somewhere.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  14. #14

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    ok thx you man you have a lots of patience with me

    last question. Why when I do that:
    char *cData = new char[iSize];
    and iSize is very big so when I pass it in the debug I see iSize changing to 0 when it see the live above, why?

  15. #15
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Don't cast to int, it's half the size. Use __int64 like in the variable declaration. Actually, don't even cast at all, the types match...
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  16. #16
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    No, wait.

    You can't use iSize because it's 64-bit. Pointers are only valid up to 2GB (half of 32-bit's range) on Win32. Trying to allocate more will throw a bad_alloc exception.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  17. #17

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    I dont cast : char *cData = new char[iSize];

    where do you see casting ? and iSize is __int64

  18. #18
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    iSize = (unsigned int)(lpTotalNumberOfBytes);
    If I see what you're doing, you're trying to allocate an array big enough for the unused space on the disk...that couldn't possibly work.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  19. #19

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    you're trying to allocate an array big enough for the unused space on the disk...that couldn't possibly work.
    C++ limit maybe....

  20. #20
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Nope, OS limit. How you could possibly need to allocate 2GB of memory is beyond me.

    You could do it on a native 64-bit system (my project at work running on a high-end SGI Origin server was quite happy to use 4.7GB of RAM ).
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  21. #21

    Thread Starter
    Ya ya Baby!!!Me is Back
    Join Date
    Jul 2002
    Posts
    362
    When we think of that 2GB is a lots of byte lol, I hadn't realize that

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