CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2009
    Posts
    9

    Unhappy 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!

  2. #2
    Join Date
    Sep 2009
    Posts
    7

    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 ...

  3. #3
    Join Date
    Sep 2009
    Posts
    9

    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...

  4. #4
    Join Date
    Sep 2009
    Posts
    7

    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 ;-)

  5. #5
    Join Date
    Sep 2009
    Posts
    9

    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++.

  6. #6
    Join Date
    Feb 2005
    Posts
    2,160

    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
  •  





Click Here to Expand Forum to Full Width

Featured