I decided to write this code 'cause saw a lot of questions on detecting if a recycle bin is empty or not ( not just empty it, but detect if it has files or not). Source code is a COM component that will be helpfull for "Real Coders in C#".
If you are C++ coder you must know Shell Programming and what shlguid.h and shlobj.h contain. If you are c# coder.. hmmm what is shell, and pointers :))) In fact I created COM to make easies C# coders to import this code in their application without any PInvoke, etc...
Using the code
Coders in C++ use it as you wish: use COM or just copy "IsEmpty" function from RecycleBinOps ( do not forget to modify return value from HRESULT to BOOL). Coders in C#: add reference -> Select Com tab -> select "CommShell v1.0" component and press OK -> write in your code: "using CommShellLib" and in your method add something like this:
IRecycleBinOps recBin = new RecycleBinOps();
if (recBin.IsEmpty() == 1)
In fact function source looks in this way (so you may not download source):
BOOL bResult = FALSE;
LPSHELLFOLDER pDesktop = NULL;
LPITEMIDLIST pidlRecycleBin = NULL;
HRESULT hr = S_OK;
LPENUMIDLIST penumFiles = NULL;
LPITEMIDLIST pidl = NULL;
LPMALLOC pMalloc = NULL;
hr = SHGetDesktopFolder(&pDesktop);
hr = SHGetSpecialFolderLocation (NULL, CSIDL_BITBUCKET, &pidlRecycleBin);
hr = pDesktop->BindToObject(pidlRecycleBin, NULL, IID_IShellFolder,
hr = m_pRecycleBin->EnumObjects(NULL,
while(penumFiles->Next(1, &pidl, NULL) != S_FALSE)
bResult = TRUE;
if (NULL != penumFiles)
penumFiles = NULL;
Idea is very simple: We obtain pointer to recycle bin using SHGetSpecialFolderLocation and after this we are starting to enumerate objects from this pointer. All information is taken from MSDN where this function are described very well. I just used them in direction I need.
Ver 1.0 :)
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.