|
-
Aug 10th, 2002, 06:39 PM
#1
Thread Starter
Ya ya Baby!!!Me is Back
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
-
Aug 10th, 2002, 06:52 PM
#2
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
-
Aug 10th, 2002, 11:57 PM
#3
Frenzied Member
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.
-
Aug 11th, 2002, 06:00 AM
#4
Monday Morning Lunatic
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
-
Aug 11th, 2002, 08:35 AM
#5
Thread Starter
Ya ya Baby!!!Me is Back
The problem is the size is ZERO always
-
Aug 11th, 2002, 08:37 AM
#6
Monday Morning Lunatic
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
-
Aug 11th, 2002, 08:44 AM
#7
Thread Starter
Ya ya Baby!!!Me is Back
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;
-
Aug 11th, 2002, 08:47 AM
#8
Monday Morning Lunatic
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
-
Aug 11th, 2002, 08:53 AM
#9
Thread Starter
Ya ya Baby!!!Me is Back
i have more than 0 for size
-
Aug 13th, 2002, 11:28 AM
#10
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.
-
Aug 13th, 2002, 11:31 AM
#11
Monday Morning Lunatic
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
-
Aug 13th, 2002, 12:11 PM
#12
Thread Starter
Ya ya Baby!!!Me is Back
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]
-
Aug 13th, 2002, 12:13 PM
#13
Monday Morning Lunatic
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
-
Aug 13th, 2002, 12:31 PM
#14
Thread Starter
Ya ya Baby!!!Me is Back
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?
-
Aug 13th, 2002, 12:34 PM
#15
Monday Morning Lunatic
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
-
Aug 13th, 2002, 12:34 PM
#16
Monday Morning Lunatic
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
-
Aug 13th, 2002, 12:35 PM
#17
Thread Starter
Ya ya Baby!!!Me is Back
I dont cast : char *cData = new char[iSize];
where do you see casting ? and iSize is __int64
-
Aug 13th, 2002, 12:38 PM
#18
Monday Morning Lunatic
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
-
Aug 13th, 2002, 01:18 PM
#19
Thread Starter
Ya ya Baby!!!Me is Back
you're trying to allocate an array big enough for the unused space on the disk...that couldn't possibly work.
C++ limit maybe....
-
Aug 13th, 2002, 01:33 PM
#20
Monday Morning Lunatic
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
-
Aug 13th, 2002, 04:51 PM
#21
Thread Starter
Ya ya Baby!!!Me is Back
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|