-
September 8th, 2009, 05:14 AM
#1
GetDiskFreeSpaceEx problem
Hello,
I am fairly new to c++ and winapi,
not new to coding though as I already code in php and javascript.
I am trying to use GetDiskFreeSpaceEx() to get the disk space sizes from my c: drive:
I define:
ULARGE_INTEGER* freeSpace;
ULARGE_INTEGER* totalSpace;
ULARGE_INTEGER* totalFreeSpace;
and on WM_LBUTTONDOWN:
if (GetDiskFreeSpaceEx( "C:\\", freeSpace, totalSpace, totalFreeSpace ))
{
cout << "-" << freeSpace << "-" << totalSpace << "-" << totalFreeSpace <<endl;
}
else
{
cout << "error";
}
It returns 0-0-0.
Any help? Thanks!
-
September 8th, 2009, 06:12 AM
#2
Re: GetDiskFreeSpaceEx problem
Actually, your program should crash, if you are coding it like this.
What you are doing, is defining some pointers to those large integers. But you must define your variables and use the pointers in the API call.
ULARGE_INTEGER freeSpace;
ULARGE_INTEGER totalSpace;
ULARGE_INTEGER totalFreeSpace;
GetDiskFreeSpaceEx( "C:\\", &freeSpace, &totalSpace, &totalFreeSpace );
will work ...
-
September 8th, 2009, 06:24 AM
#3
Re: GetDiskFreeSpaceEx problem
Ah, still fighting with pointers,
When trying to show the result like:
if (GetDiskFreeSpaceEx( "C:\\", &freeSpace, &totalSpace, &totalFreeSpace ))
{
cout << "-" << &freeSpace << "-" << &totalSpace << "-" << &totalFreeSpace <<endl;
}
else
{
cout << "error";
}
I get memory addresses instead of bytes...
-
September 8th, 2009, 07:17 AM
#4
Re: GetDiskFreeSpaceEx problem
Ah, still fighting with pointers,
it seems so :-)
maybe start with C#, as C++ and the WinAPI is dealing a lot with pointers.
Your problem ist, that you must now print your variables, not the pointers.
If there isn't an overloaded function for ULARGE_INTEGER, you must create one yourself, or you print the parts of the variable, which is a struct.
for example: freeSpace.LowPart, freeSpace.HighPart.
Or change it into a double value and cout that value.
So besides pointers you need knowledge about structures ... And then there are pointers to structures which have to get addressed and so on.
Good luck ;-)
-
September 8th, 2009, 07:54 AM
#5
Re: GetDiskFreeSpaceEx problem
Kind of makes me wonder why they didn't use another kinds of symbols to make pointers easier. XD
maybe start with C#, as C++ and the WinAPI is dealing a lot with pointers.
Well I'll look into C# later, I heard it's a bit simpler, however I am learning c++, I must , because many libraries I want to use for my games are available for c++ only. Going this way, I gave winapi a shot.
GetDiskFreeSpaceEx( "C:\\", &freeSpace, &totalSpace, &totalFreeSpace );
cout<<freeSpace.LowPart<<endl;
this works, it shows the bytes, but... what does LowPart and HighPart do?
Or change it into a double value and cout that value.
Oh can you tell me how I can convert it to double please?
Btw, in php I do:
echo $my_var.' test str';
In javascript:
alert(my_var+' test str');
I can show a variable side to side along with a text string but these:
MessageBox(hwnd, my_var+" test str", "TEST", MB_OK);
and:
cout<< my_var+" test str";
throw errors. I don't know how to do it in c++.
-
September 8th, 2009, 08:12 AM
#6
Re: GetDiskFreeSpaceEx problem
String literals don't have + operator overloads. You need to use a string class (which does provide overloads for +, =, etc) so that you can deal with it as if it were a primitive type (like int, float, etc); or use the string concatenation functions from the standard C library:
Code:
char MyStringVar[100]; //make it big enough for your max expected text
strcpy(MyStringVar,"test str");
strcat(MyStringVar," extra text.");
MessageBoxA(hwnd,MyStringVar,"TEST",MB_OK);
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
|