Search code examples
c++visual-studiodelphicomwindows-shell

Trying to convert Delphi interface definition to C++ for VS 2008


I need to convert an interface defined in Delpi to C++. I made small demo project that contains all of the stuff shown below.

First is the Delphi function that the person claims to be working on this thread:

function CanFileBeDeletedToRecycleBin(const AFileName: UnicodeString): Boolean;
var
  RecycleBinManager: IRecycleBinManager;
begin
  OleCheck(CoCreateInstance(CLSID_RecycleBinManager, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IRecycleBinManager, RecycleBinManager));
  try
    Result := RecycleBinManager.WillRecycle(PWideChar(AFileName)) = S_OK;
  finally
    RecycleBinManager := nil;
  end;
end;

The rest of the Delphi interface definitions are here.

So I came up with the following C++ code that unfortunately crashes. (Again, let me repeat that the person who wrote Delphi version claims that it works fine for him.)

HRESULT hr;

CoInitializeEx(NULL, COINIT_DISABLE_OLE1DDE | COINIT_APARTMENTTHREADED);

// {4A04656D-52AA-49DE-8A09-CB178760E748}
const CLSID CLSID_RecycleBinManager = {0x4A04656D, 0x52AA, 0x49DE, {0x8A, 0x09, 0xCB, 0x17, 0x87, 0x60, 0xE7, 0x48}};

// {5869092D-8AF9-4A6C-AE84-1F03BE2246CC}
const IID IID_IRecycleBinManager = {0x5869092D, 0x8AF9, 0x4A6C, {0xAE, 0x84, 0x1F, 0x03, 0xBE, 0x22, 0x46, 0xCC}};

IRecycleBinManager* pIRBM = NULL;

hr = CoCreateInstance(CLSID_RecycleBinManager, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
    IID_IRecycleBinManager, (void**) &pIRBM);
//  hr = SHCoCreateInstance(NULL, &CLSID_RecycleBinManager, NULL, IID_IRecycleBinManager, (void **)&pIRBM);
if (SUCCEEDED(hr))
{
    //I get a crash on the next line:
    //Unhandled exception at 0x76175ed2: 0xC0000005: Access violation writing location 0xa84d252b.
    hr = pIRBM->WillRecycle(L"C:\\test del");

    pIRBM->Release();
}

I tried my best to convert that interface from Delphi (here) to C++. Here's what I got (after @RemyLebeau's suggestions, which unfortunately still didn't work for me.)

#pragma pack(push,1)
struct DELETEDITEM
{
    DWORD dwFileSizeLow;
    DWORD dwFileSizeHigh;
#pragma pack(push,8)
    FILETIME ftDeletionTime;
#pragma pack(pop)
    WCHAR szOriginalPath[MAX_PATH];
    WCHAR szDisplacedPath[MAX_PATH];
};
#pragma pack(pop)

enum RECYCLEBIN_TYPE : unsigned char 
{ 
    RBTYPE_VOLUME, 
    RBTYPE_KNOWNFOLDER 
};


#if defined(__cplusplus) && !defined(CINTERFACE)

    MIDL_INTERFACE("6E325F88-D12F-49E5-895B-8EC98630C021")
    IEnumRecycleItems : public IUnknown
    {
    public:
        //virtual HRESULT __stdcall Next(unsigned celt, /* out */ tagDELETEDITEM &rgelt, unsigned &pceltFetched) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE Next( 
            __RPC__in ULONG celt,
            __RPC__deref_out DELETEDITEM* rgelt,
            __RPC__deref_out ULONG* pceltFetched
            ) = 0;

        //virtual HRESULT __stdcall Skip(unsigned celt) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE Skip( 
            __RPC__in ULONG celt
            ) = 0;

        //virtual HRESULT __stdcall Reset(void) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE Reset(
            void
            ) = 0;

        //virtual HRESULT __stdcall Clone(/* out */ _di_IEnumRecycleItems &ppenum) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE Clone( 
            __RPC__deref_out IEnumRecycleItems** ppenum
            ) = 0;

    };




    MIDL_INTERFACE("0125E62F-8349-443A-854B-A55FB84CFA35")
    IRecycle : public IUnknown
    {
    public:
        //virtual HRESULT __stdcall Compact(void) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE Compact(void) = 0;

        //virtual HRESULT __stdcall GetFileData(const System::WideChar * pszPath, /* out */ tagDELETEDITEM &lpData) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetFileData( 
            __RPC__in const WCHAR* pszPath,
            __RPC__deref_out DELETEDITEM* lpData
            ) = 0;

        //virtual HRESULT __stdcall GetItemCount(/* out */ __int64 &lpCount) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetItemCount( 
            __RPC__deref_out __int64* lpCount
            ) = 0;

        //virtual HRESULT __stdcall GetUsedSpace(/* out */ __int64 &lpUsedSpace) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetUsedSpace( 
            __RPC__deref_out __int64* lpUsedSpace
            ) = 0;

        //virtual HRESULT __stdcall IsEmpty(void) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE IsEmpty( 
            void
            ) = 0;

        //virtual HRESULT __stdcall PurgeAll(_di_IFileOperation pfo) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE PurgeAll( 
            __RPC__in IFileOperation* pfo
            ) = 0;

        //virtual HRESULT __stdcall PurgeItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE PurgeItems( 
            __RPC__in const WCHAR* lpstrItems,
            __RPC__in IFileOperation* pfo
            ) = 0;

        //virtual HRESULT __stdcall SuspendUpdating(BOOL fSuspend) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE SuspendUpdating( 
            __RPC__in BOOL fSuspend
            ) = 0;

        //virtual HRESULT __stdcall RecycleItem(const System::WideChar * lpstrItem, const unsigned dwAttrs, const __int64 iFileSize, /* out */ _di_IShellItem &psi) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE RecycleItem( 
            __RPC__in const WCHAR* lpstrItem,
            __RPC__in const DWORD dwAttrs,
            __RPC__in const __int64 iFileSize,
            __RPC__deref_out IShellItem** psi
            ) = 0;

        //virtual HRESULT __stdcall RestoreItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE RestoreItems( 
            __RPC__in const WCHAR* lpstrItems,
            __RPC__in IFileOperation* pfo
            ) = 0;

        //virtual HRESULT __stdcall IsRecycled(const System::WideChar * pszPath, PBOOL lpRecycled) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE IsRecycled( 
            __RPC__in const WCHAR* pszPath,
            __RPC__out PBOOL lpRecycled
            ) = 0;

        //virtual HRESULT __stdcall EnumItems(unsigned dwFlags, /* out */ _di_IEnumRecycleItems &EnumRecycleItems) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE EnumItems( 
            __RPC__in DWORD dwFlags,
            __RPC__deref_out IEnumRecycleItems** enm
            ) = 0;

        //virtual HRESULT __stdcall WillRecycle(const System::WideChar * pszPath) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE WillRecycle( 
            __RPC__in const WCHAR* pszPath
            ) = 0;

    };




    MIDL_INTERFACE("F964AD97-96F4-48AB-B444-E8588BC7C7B3")
    IRecycleBin : public IUnknown
    {
    public:
        //virtual HRESULT __stdcall Compact(void) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE Compact(void) = 0;

        //virtual HRESULT __stdcall GetFileData(const System::WideChar * pszPath, /* out */ tagDELETEDITEM &lpData) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetFileData( 
            __RPC__in const WCHAR* pszPath,
            __RPC__deref_out DELETEDITEM* lpData
            ) = 0;

        //virtual HRESULT __stdcall GetItemCount(/* out */ __int64 &lpCount) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetItemCount( 
            __RPC__deref_out __int64* lpCount
            ) = 0;

        //virtual HRESULT __stdcall GetUsedSpace(/* out */ __int64 &lpUsedSpace) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetUsedSpace( 
            __RPC__deref_out __int64* lpUsedSpace
            ) = 0;

        //virtual HRESULT __stdcall IsEmpty(void) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE IsEmpty( 
            void
            ) = 0;

        //virtual HRESULT __stdcall PurgeAll(_di_IFileOperation pfo) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE PurgeAll( 
            __RPC__in IFileOperation* pfo
            ) = 0;

        //virtual HRESULT __stdcall PurgeItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE PurgeItems( 
            __RPC__in const WCHAR* lpstrItems,
            __RPC__in IFileOperation* pfo
            ) = 0;

        //virtual HRESULT __stdcall SuspendUpdating(BOOL fSuspend) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE SuspendUpdating( 
            __RPC__in BOOL fSuspend
            ) = 0;

        //virtual HRESULT __stdcall RecycleItem(const System::WideChar * lpstrItem, const unsigned dwAttrs, const __int64 iFileSize, /* out */ _di_IShellItem &psi) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE RecycleItem( 
            __RPC__in const WCHAR* lpstrItem,
            __RPC__in const DWORD dwAttrs,
            __RPC__in const __int64 iFileSize,
            __RPC__deref_out IShellItem** psi
            ) = 0;

        //virtual HRESULT __stdcall RestoreItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE RestoreItems( 
            __RPC__in const WCHAR* lpstrItems,
            __RPC__in IFileOperation* pfo
            ) = 0;

        //virtual HRESULT __stdcall IsRecycled(const System::WideChar * pszPath, PBOOL lpRecycled) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE IsRecycled( 
            __RPC__in const WCHAR* pszPath,
            __RPC__out PBOOL lpRecycled
            ) = 0;

        //virtual HRESULT __stdcall EnumItems(unsigned dwFlags, /* out */ _di_IEnumRecycleItems &EnumRecycleItems) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE EnumItems( 
            __RPC__in DWORD dwFlags,
            __RPC__deref_out IEnumRecycleItems** enm
            ) = 0;

        //virtual HRESULT __stdcall WillRecycle(const System::WideChar * pszPath) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE WillRecycle( 
            __RPC__in const WCHAR* pszPath
            ) = 0;

        //virtual HRESULT __stdcall Initialize(const tagRECYCLEBIN_TYPE rbType, const System::WideChar * pszID) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE Initialize(
            __RPC__in const RECYCLEBIN_TYPE rbType,
            __RPC__in const WCHAR* pszID
            ) = 0;

        //virtual HRESULT __stdcall GetTypeID(/* out */ tagRECYCLEBIN_TYPE &rbType, System::WideChar * &pszID) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetTypeID(
            __RPC__deref_out RECYCLEBIN_TYPE* rbType,
            __RPC__in const WCHAR* pszID
            ) = 0;

        //virtual HRESULT __stdcall GetIDList(/* out */ Winapi::Shlobj::PItemIDList &ppidl) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetIDList(
            __RPC__deref_out LPITEMIDLIST *ppidl
            ) = 0;

        //virtual HRESULT __stdcall GetLocation(System::WideChar * pszPathBuffer, unsigned cchMax) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetLocation( 
            __RPC__in WCHAR* pszPathBuffer,
            __RPC__in UINT cchMax
            ) = 0;

        //virtual HRESULT __stdcall GetMaxCapacityRange(/* out */ __int64 &lpMin, /* out */ __int64 &lpMax) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetMaxCapacityRange( 
            __RPC__deref_out __int64* lpMin,
            __RPC__deref_out __int64* lpMax
            ) = 0;

        //virtual HRESULT __stdcall GetMaxCapacity(/* out */ __int64 &lpCapacity) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetMaxCapacity( 
            __RPC__deref_out __int64* lpCapacity
            ) = 0;

        //virtual HRESULT __stdcall SetMaxCapacity(const __int64 lpCapacity) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE SetMaxCapacity( 
            __RPC__in const __int64 lpCapacity
            ) = 0;

        //virtual HRESULT __stdcall GetPurgeOnDelete(/* out */ BOOL &fNukeOnDelete) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetPurgeOnDelete( 
            __RPC__deref_out BOOL* fNukeOnDelete
            ) = 0;

        //virtual HRESULT __stdcall SetPurgeOnDelete(const BOOL fNukeOnDelete) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE SetPurgeOnDelete( 
            __RPC__in const BOOL fNukeOnDelete
            ) = 0;

    };




    MIDL_INTERFACE("5869092D-8AF9-4A6C-AE84-1F03BE2246CC")
    IRecycleBinManager : public IUnknown
    {
    public:

        //virtual HRESULT __stdcall Compact(void) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE Compact(void) = 0;

        //virtual HRESULT __stdcall GetFileData(const System::WideChar * pszPath, /* out */ tagDELETEDITEM &lpData) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetFileData( 
            __RPC__in const WCHAR* pszPath,
            __RPC__deref_out DELETEDITEM* pDeletedItem
            ) = 0;

        //virtual HRESULT __stdcall GetItemCount(/* out */ __int64 &lpCount) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetItemCount( 
            __RPC__deref_out __int64* lpCount
            ) = 0;

        //virtual HRESULT __stdcall GetUsedSpace(/* out */ __int64 &lpUsedSpace) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetUsedSpace( 
            __RPC__deref_out __int64* lpUsedSpace
            ) = 0;

        //virtual HRESULT __stdcall IsEmpty(void) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE IsEmpty( 
            void
            ) = 0;

        //virtual HRESULT __stdcall PurgeAll(_di_IFileOperation pfo) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE PurgeAll( 
            __RPC__in IFileOperation* pfo
            ) = 0;

        //virtual HRESULT __stdcall PurgeItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE PurgeItems( 
            __RPC__in const WCHAR* lpstrItems,
            __RPC__in IFileOperation* pfo
            ) = 0;

        //virtual HRESULT __stdcall SuspendUpdating(BOOL fSuspend) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE SuspendUpdating( 
            __RPC__in BOOL fSuspend
            ) = 0;

        //virtual HRESULT __stdcall RecycleItem(const System::WideChar * lpstrItem, const unsigned dwAttrs, const __int64 iFileSize, /* out */ _di_IShellItem &psi) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE RecycleItem( 
            __RPC__in const WCHAR* lpstrItem,
            __RPC__in const DWORD dwAttrs,
            __RPC__in const __int64 iFileSize,
            __RPC__deref_out IShellItem** psi
            ) = 0;

        //virtual HRESULT __stdcall RestoreItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE RestoreItems( 
            __RPC__in const WCHAR* lpstrItems,
            __RPC__in IFileOperation* pfo
            ) = 0;

        //virtual HRESULT __stdcall IsRecycled(const System::WideChar * pszPath, PBOOL lpRecycled) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE IsRecycled( 
            __RPC__in const WCHAR* pszPath,
            __RPC__out PBOOL lpRecycled
            ) = 0;

        //virtual HRESULT __stdcall EnumItems(unsigned dwFlags, /* out */ _di_IEnumRecycleItems &EnumRecycleItems) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE EnumItems( 
            __RPC__in DWORD dwFlags,
            __RPC__deref_out IEnumRecycleItems** enm
            ) = 0;

        //virtual HRESULT __stdcall WillRecycle(const System::WideChar * pszPath) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE WillRecycle( 
            __RPC__in const WCHAR* pszPath
            ) = 0;

        //virtual HRESULT __stdcall DelayCompaction(const BOOL fDelay) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE DelayCompaction( 
            __RPC__in const BOOL fDelay
            ) = 0;

        //virtual HRESULT __stdcall GetRecycleBinCount(/* out */ int &iCount) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetRecycleBinCount( 
            __RPC__deref_out int* iCount
            ) = 0;

        //virtual HRESULT __stdcall GetRecycleBinAt(const int index, const GUID &iid, /* out */ void *ppv) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetRecycleBinAt( 
            __RPC__in const int index,
            const GUID *iid,
            __RPC__deref_out void **ppv
            ) = 0;

        //virtual HRESULT __stdcall GetRecycleBin(const System::WideChar * pszPath, const GUID &iid, /* out */ void *ppv) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE GetRecycleBin( 
            __RPC__in const WCHAR* pszRootPath,
            const GUID *iid,
            __RPC__deref_out void **ppv
            ) = 0;

        //virtual HRESULT __stdcall Refresh(void) = 0 ;
        virtual HRESULT STDMETHODCALLTYPE Refresh( 
            void
            ) = 0;

    };

#endif

Can someone take a look. What am I missing there?


Solution

  • Rather than translating the interface code from Delphi to C++, you can take the original code from the Russian site, put it in a .pas file as-is, and then add that file to your C++ project. When you build the project (or just compile the .pas file by itself), a C++ .hpp file will be generated for you, which you can then #include into your C++ code.

    Doing it this way, the following code works fine for me in C++Builder XE2 on Windows 7:

    #include "URecycleBinStuff.hpp"
    #include <ComObj.hpp>
    
    bool __fastcall CanFileBeDeletedToRecycleBin(const UnicodeString &AFileName)
    {
        DelphiInterface<IRecycleBinManager> RecycleBinManager;
        OleCheck(CoCreateInstance(CLSID_RecycleBinManager, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IRecycleBinManager, (void**)&RecycleBinManager));
        return (RecycleBinManager->WillRecycle(AFileName.c_str()) == S_OK);
    }
    
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
        if (CanFileBeDeletedToRecycleBin(L"C:\\test del"))
            ShowMessage("Can be deleted"); // <-- code makes it here
        else
            ShowMessage("Can not be deleted");
    }
    

    Here is what the generated .hpp file looks like:

    // CodeGear C++Builder
    // Copyright (c) 1995, 2011 by Embarcadero Technologies, Inc.
    // All rights reserved
    
    // (DO NOT EDIT: machine generated header) 'URecycleBinStuff.pas' rev: 23.00 (Win32)
    
    #ifndef UrecyclebinstuffHPP
    #define UrecyclebinstuffHPP
    
    #pragma delphiheader begin
    #pragma option push
    #pragma option -w-      // All warnings off
    #pragma option -Vx      // Zero-length empty class member functions
    #pragma pack(push,8)
    #include <System.hpp>   // Pascal unit
    #include <SysInit.hpp>  // Pascal unit
    #include <Winapi.Windows.hpp>   // Pascal unit
    #include <Winapi.Messages.hpp>  // Pascal unit
    #include <Winapi.ShlObj.hpp>    // Pascal unit
    
    //-- user supplied -----------------------------------------------------------
    
    namespace Urecyclebinstuff
    {
    //-- type declarations -------------------------------------------------------
    #pragma option push -b-
    enum tagRECYCLEBIN_TYPE : unsigned char { RBTYPE_VOLUME, RBTYPE_KNOWNFOLDER };
    #pragma option pop
    
    typedef tagRECYCLEBIN_TYPE TRecycleBinType;
    
    struct tagDELETEDITEM;
    typedef tagDELETEDITEM *PDeletedItem;
    
    #pragma pack(push,1)
    struct DECLSPEC_DRECORD tagDELETEDITEM
    {
    
    public:
        unsigned dwFileSizeLow;
        unsigned dwFileSizeHigh;
        #pragma pack(push,8)
        _FILETIME ftDeletionTime;
        #pragma pack(pop)
        System::StaticArray<System::WideChar, 260> szOriginalPath;
        System::StaticArray<System::WideChar, 260> szDisplacedPath;
    };
    #pragma pack(pop)
    
    
    typedef tagDELETEDITEM TDeletedItem;
    
    __interface IEnumRecycleItems;
    typedef System::DelphiInterface<IEnumRecycleItems> _di_IEnumRecycleItems;
    __interface  INTERFACE_UUID("{6E325F88-D12F-49E5-895B-8EC98630C021}") IEnumRecycleItems  : public System::IInterface 
    {
    
    public:
        virtual HRESULT __stdcall Next(unsigned celt, /* out */ tagDELETEDITEM &rgelt, unsigned &pceltFetched) = 0 ;
        virtual HRESULT __stdcall Skip(unsigned celt) = 0 ;
        virtual HRESULT __stdcall Reset(void) = 0 ;
        virtual HRESULT __stdcall Clone(/* out */ _di_IEnumRecycleItems &ppenum) = 0 ;
    };
    
    __interface IRecycle;
    typedef System::DelphiInterface<IRecycle> _di_IRecycle;
    __interface  INTERFACE_UUID("{0125E62F-8349-443A-854B-A55FB84CFA35}") IRecycle  : public System::IInterface 
    {
    
    public:
        virtual HRESULT __stdcall Compact(void) = 0 ;
        virtual HRESULT __stdcall GetFileData(const System::WideChar * pszPath, /* out */ tagDELETEDITEM &lpData) = 0 ;
        virtual HRESULT __stdcall GetItemCount(/* out */ __int64 &lpCount) = 0 ;
        virtual HRESULT __stdcall GetUsedSpace(/* out */ __int64 &lpUsedSpace) = 0 ;
        virtual HRESULT __stdcall IsEmpty(void) = 0 ;
        virtual HRESULT __stdcall PurgeAll(_di_IFileOperation pfo) = 0 ;
        virtual HRESULT __stdcall PurgeItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT __stdcall SuspendUpdating(BOOL fSuspend) = 0 ;
        virtual HRESULT __stdcall RecycleItem(const System::WideChar * lpstrItem, const unsigned dwAttrs, const __int64 iFileSize, /* out */ _di_IShellItem &psi) = 0 ;
        virtual HRESULT __stdcall RestoreItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT __stdcall IsRecycled(const System::WideChar * pszPath, PBOOL lpRecycled) = 0 ;
        virtual HRESULT __stdcall EnumItems(unsigned dwFlags, /* out */ _di_IEnumRecycleItems &EnumRecycleItems) = 0 ;
        virtual HRESULT __stdcall WillRecycle(const System::WideChar * pszPath) = 0 ;
    };
    
    __interface IRecycleBin;
    typedef System::DelphiInterface<IRecycleBin> _di_IRecycleBin;
    __interface  INTERFACE_UUID("{F964AD97-96F4-48AB-B444-E8588BC7C7B3}") IRecycleBin  : public System::IInterface 
    {
    
    public:
        virtual HRESULT __stdcall Compact(void) = 0 ;
        virtual HRESULT __stdcall GetFileData(const System::WideChar * pszPath, /* out */ tagDELETEDITEM &lpData) = 0 ;
        virtual HRESULT __stdcall GetItemCount(/* out */ __int64 &lpCount) = 0 ;
        virtual HRESULT __stdcall GetUsedSpace(/* out */ __int64 &lpUsedSpace) = 0 ;
        virtual HRESULT __stdcall IsEmpty(void) = 0 ;
        virtual HRESULT __stdcall PurgeAll(_di_IFileOperation pfo) = 0 ;
        virtual HRESULT __stdcall PurgeItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT __stdcall SuspendUpdating(BOOL fSuspend) = 0 ;
        virtual HRESULT __stdcall RecycleItem(const System::WideChar * lpstrItem, const unsigned dwAttrs, const __int64 iFileSize, /* out */ _di_IShellItem &psi) = 0 ;
        virtual HRESULT __stdcall RestoreItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT __stdcall IsRecycled(const System::WideChar * pszPath, PBOOL lpRecycled) = 0 ;
        virtual HRESULT __stdcall EnumItems(unsigned dwFlags, /* out */ _di_IEnumRecycleItems &EnumRecycleItems) = 0 ;
        virtual HRESULT __stdcall WillRecycle(const System::WideChar * pszPath) = 0 ;
        virtual HRESULT __stdcall Initialize(const tagRECYCLEBIN_TYPE rbType, const System::WideChar * pszID) = 0 ;
        virtual HRESULT __stdcall GetTypeID(/* out */ tagRECYCLEBIN_TYPE &rbType, System::WideChar * &pszID) = 0 ;
        virtual HRESULT __stdcall GetIDList(/* out */ Winapi::Shlobj::PItemIDList &ppidl) = 0 ;
        virtual HRESULT __stdcall GetLocation(System::WideChar * pszPathBuffer, unsigned cchMax) = 0 ;
        virtual HRESULT __stdcall GetMaxCapacityRange(/* out */ __int64 &lpMin, /* out */ __int64 &lpMax) = 0 ;
        virtual HRESULT __stdcall GetMaxCapacity(/* out */ __int64 &lpCapacity) = 0 ;
        virtual HRESULT __stdcall SetMaxCapacity(const __int64 lpCapacity) = 0 ;
        virtual HRESULT __stdcall GetPurgeOnDelete(/* out */ BOOL &fNukeOnDelete) = 0 ;
        virtual HRESULT __stdcall SetPurgeOnDelete(const BOOL fNukeOnDelete) = 0 ;
    };
    
    __interface IRecycleBinManager;
    typedef System::DelphiInterface<IRecycleBinManager> _di_IRecycleBinManager;
    __interface  INTERFACE_UUID("{5869092D-8AF9-4A6C-AE84-1F03BE2246CC}") IRecycleBinManager  : public System::IInterface 
    {
    
    public:
        virtual HRESULT __stdcall Compact(void) = 0 ;
        virtual HRESULT __stdcall GetFileData(const System::WideChar * pszPath, /* out */ tagDELETEDITEM &lpData) = 0 ;
        virtual HRESULT __stdcall GetItemCount(/* out */ __int64 &lpCount) = 0 ;
        virtual HRESULT __stdcall GetUsedSpace(/* out */ __int64 &lpUsedSpace) = 0 ;
        virtual HRESULT __stdcall IsEmpty(void) = 0 ;
        virtual HRESULT __stdcall PurgeAll(_di_IFileOperation pfo) = 0 ;
        virtual HRESULT __stdcall PurgeItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT __stdcall SuspendUpdating(BOOL fSuspend) = 0 ;
        virtual HRESULT __stdcall RecycleItem(const System::WideChar * lpstrItem, const unsigned dwAttrs, const __int64 iFileSize, /* out */ _di_IShellItem &psi) = 0 ;
        virtual HRESULT __stdcall RestoreItems(const System::WideChar * lpstrItems, _di_IFileOperation pfo) = 0 ;
        virtual HRESULT __stdcall IsRecycled(const System::WideChar * pszPath, PBOOL lpRecycled) = 0 ;
        virtual HRESULT __stdcall EnumItems(unsigned dwFlags, /* out */ _di_IEnumRecycleItems &EnumRecycleItems) = 0 ;
        virtual HRESULT __stdcall WillRecycle(const System::WideChar * pszPath) = 0 ;
        virtual HRESULT __stdcall DelayCompaction(const BOOL fDelay) = 0 ;
        virtual HRESULT __stdcall GetRecycleBinCount(/* out */ int &iCount) = 0 ;
        virtual HRESULT __stdcall GetRecycleBinAt(const int index, const GUID &iid, /* out */ void *ppv) = 0 ;
        virtual HRESULT __stdcall GetRecycleBin(const System::WideChar * pszPath, const GUID &iid, /* out */ void *ppv) = 0 ;
        virtual HRESULT __stdcall Refresh(void) = 0 ;
    };
    
    //-- var, const, procedure ---------------------------------------------------
    extern PACKAGE GUID IID_IEnumRecycleItems;
    extern PACKAGE GUID IID_IRecycle;
    extern PACKAGE GUID IID_IRecycleBin;
    extern PACKAGE GUID IID_IRecycleBinManager;
    extern PACKAGE GUID CLSID_RecycleBinManager;
    
    }   /* namespace Urecyclebinstuff */
    #if !defined(DELPHIHEADER_NO_IMPLICIT_NAMESPACE_USE) && !defined(NO_USING_NAMESPACE_URECYCLEBINSTUFF)
    using namespace Urecyclebinstuff;
    #endif
    #pragma pack(pop)
    #pragma option pop
    
    #pragma delphiheader end.
    //-- end unit ----------------------------------------------------------------
    #endif  // UrecyclebinstuffHPP
    

    If you compare the .hpp file's IRecycleBinManager to your manual IRecycleBinManager, there are some discrepancies in your code. Such as, you have the RecycleItem() and IsRecycled() methods named as PurgeItems() and RestoreItems() instead, and you have two RestoreItems() methods.