1

I'm using Borland C++Builder 6 Enterprise on Windows 10.

I have the following code to extract the memory size and object count of the Recycle Bin:

...
#include "shellapi.h"
...

void __fastcall TForm6::Button10Click(TObject *Sender)
{
 SHQUERYRBINFO rbinfo;
 AnsiString sSize,
            sCount;

 int rc;

 unsigned __int64   i64Size,
                    i64Cnt;

 rbinfo.cbSize=sizeof(rbinfo);
 rc=SHQueryRecycleBin("C:\\", &rbinfo);
 if (rc!=S_OK)
     Application->MessageBox( "Fehler bei SHQueryRecycleBin", "Fehler", MB_OK | MB_ICONERROR);
     else
     {

     i64Size = rbinfo.i64Size;
     i64Cnt  = rbinfo.i64NumItems;

     sSize =AnsiString(rbinfo.i64Size);
     sCount=AnsiString(rbinfo.i64NumItems);

     Application->MessageBox(sSize.c_str(), "Speicherplatz", MB_OK | MB_ICONINFORMATION);
     Application->MessageBox(sCount.c_str(), "Anzahl Objekte", MB_OK | MB_ICONINFORMATION);
     }
}

The function gets the total wrong values. The memory size is greater than disk space. The object count is 43628621390151600.

What am I doing wrong here?

Hello

  1. I replace int to HRESULT.

  2. The return values from the API function are already wrong.

     rbinfo.i64Size=433791696898
     sSize=         433791696898
     rbinfo.i64NumItems=0
     sCount            =0
    
  3. The tool Secure Eraser shows 206.195 files and 197.121,3 MB in Recycle
    Bin. (picture) The tool CCleaner shows 560 files (objects) and 36.441.834 KB in Recycle
    Bin. (CCleaner.jpg) In Windows Explorer there are also 560 objects in Recycle Bin.

Egon
  • 11
  • 2
  • 1
    Not sure what `AnsiString` is but try [`_i64toa()](https://learn.microsoft.com/en-us/previous-versions/yakksftt(v=vs.140)) – 001 Apr 30 '21 at 14:48
  • 1
    @J "*Not sure what `AnsiString` is*" - [see this](http://docwiki.embarcadero.com/Libraries/Sydney/en/System.AnsiStringT) – Remy Lebeau Apr 30 '21 at 16:11
  • 1
    @Egon is the problem that `SHQueryRecycleBin()` is returning bad values to begin with, or is the problem that they are just not being converted to `AnsiString` correctly? Please be more specific. Also, `SHQueryRecycleBin()` returns an `HRESULT` not an `int`. – Remy Lebeau Apr 30 '21 at 16:14

0 Answers0