1 #pragma once 2 3 #ifdef __cplusplus 4 extern "C" { 5 #endif 6 7 #include <stdarg.h> 8 9 #define WIN32_NO_STATUS 10 #define _INC_WINDOWS 11 #define COM_NO_WINDOWS_H 12 13 #include <windef.h> 14 #include <winbase.h> 15 #include <winnls.h> 16 #include <winver.h> 17 #include <shellapi.h> 18 #include <objbase.h> 19 20 #define ANY_SIZE 1 21 22 /* Structures used by the API Interface */ 23 24 typedef struct _DELETED_FILE_DETAILS_A 25 { 26 FILETIME LastModification; 27 FILETIME DeletionTime; 28 ULARGE_INTEGER FileSize; 29 ULARGE_INTEGER PhysicalFileSize; 30 DWORD Attributes; 31 CHAR FileName[ANY_SIZE]; 32 } DELETED_FILE_DETAILS_A, *PDELETED_FILE_DETAILS_A; 33 typedef struct _DELETED_FILE_DETAILS_W 34 { 35 FILETIME LastModification; 36 FILETIME DeletionTime; 37 ULARGE_INTEGER FileSize; 38 ULARGE_INTEGER PhysicalFileSize; 39 DWORD Attributes; 40 WCHAR FileName[ANY_SIZE]; 41 } DELETED_FILE_DETAILS_W, *PDELETED_FILE_DETAILS_W; 42 #ifdef UNICODE 43 #define DELETED_FILE_DETAILS DELETED_FILE_DETAILS_W 44 #define PDELETED_FILE_DETAILS PDELETED_FILE_DETAILS_W 45 #else 46 #define DELETED_FILE_DETAILS DELETED_FILE_DETAILS_A 47 #define PDELETED_FILE_DETAILS PDELETED_FILE_DETAILS_A 48 #endif 49 50 /* API Interface */ 51 52 /* Function called for each deleted file in the recycle bin 53 * Context: value given by the caller of the EnumerateRecycleBin function 54 * hDeletedFile: a handle to the deleted file 55 * Returning FALSE stops the enumeration. 56 * Remarks: the handle must be closed with the CloseRecycleBinHandle function 57 */ 58 typedef BOOL (WINAPI *PENUMERATE_RECYCLEBIN_CALLBACK)(IN PVOID Context, IN HANDLE hDeletedFile); 59 60 /* Closes a file deleted handle. 61 * hDeletedFile: the handle to close 62 * Returns TRUE if operation succeeded, FALSE otherwise. 63 * Remark: The handle is obtained in the PENUMERATE_RECYCLEBIN_CALLBACK callback 64 */ 65 BOOL WINAPI 66 CloseRecycleBinHandle( 67 IN HANDLE hDeletedFile); 68 69 /* Moves a file to the recycle bin. 70 * FileName: the name of the file to move the recycle bin 71 * Returns TRUE if operation succeeded, FALSE otherwise. 72 */ 73 BOOL WINAPI 74 DeleteFileToRecycleBinA( 75 IN LPCSTR FileName); 76 BOOL WINAPI 77 DeleteFileToRecycleBinW( 78 IN LPCWSTR FileName); 79 #ifdef UNICODE 80 #define DeleteFileToRecycleBin DeleteFileToRecycleBinW 81 #else 82 #define DeleteFileToRecycleBin DeleteFileToRecycleBinA 83 #endif 84 85 /* Moves a file to the recycle bin. 86 * hDeletedFile: handle of the deleted file to delete 87 * Returns TRUE if operation succeeded, FALSE otherwise. 88 * Remark: The handle is obtained in the PENUMERATE_RECYCLEBIN_CALLBACK callback 89 */ 90 BOOL WINAPI 91 DeleteFileHandleToRecycleBin( 92 IN HANDLE hDeletedFile); 93 94 /* Removes all elements contained in a recycle bin 95 * pszRoot: the name of the drive containing the recycle bin 96 * Returns TRUE if operation succeeded, FALSE otherwise. 97 * Remarks: 'pszRoot' can be NULL to mean 'all recycle bins'. 98 */ 99 BOOL WINAPI 100 EmptyRecycleBinA( 101 IN LPCSTR pszRoot OPTIONAL); 102 BOOL WINAPI 103 EmptyRecycleBinW( 104 IN LPCWSTR pszRoot OPTIONAL); 105 #ifdef UNICODE 106 #define EmptyRecycleBin EmptyRecycleBinW 107 #else 108 #define EmptyRecycleBin EmptyRecycleBinA 109 #endif 110 111 /* Enumerate contents of a recycle bin. 112 * pszRoot: the name of the drive containing the recycle bin 113 * pFnCallback: callback function to be called for each deleted item found 114 * Context: some value which will be given back in the callback function 115 * Returns TRUE if operation succeeded, FALSE otherwise. 116 * Remarks: 'pszRoot' can be NULL to mean 'all recycle bins'. 117 */ 118 BOOL WINAPI 119 EnumerateRecycleBinA( 120 IN LPCSTR pszRoot OPTIONAL, 121 IN PENUMERATE_RECYCLEBIN_CALLBACK pFnCallback, 122 IN PVOID Context OPTIONAL); 123 BOOL WINAPI 124 EnumerateRecycleBinW( 125 IN LPCWSTR pszRoot OPTIONAL, 126 IN PENUMERATE_RECYCLEBIN_CALLBACK pFnCallback, 127 IN PVOID Context OPTIONAL); 128 #ifdef UNICODE 129 #define EnumerateRecycleBin EnumerateRecycleBinW 130 #else 131 #define EnumerateRecycleBin EnumerateRecycleBinA 132 #endif 133 134 BOOL WINAPI 135 GetDeletedFileTypeNameW( 136 IN HANDLE hDeletedFile, 137 OUT LPWSTR pTypeName, 138 IN DWORD BufferSize, 139 OUT LPDWORD RequiredSize OPTIONAL); 140 141 /* Gets details about a deleted file 142 * hDeletedFile: handle of the deleted file to get details about 143 * BufferSize: size of the 'FileDetails' buffer, in bytes 144 * FileDetails: if the function succeeded, contains details about the deleted file 145 * RequiredSize: contains the minimal buffer size required to get file information details 146 * Returns TRUE if operation succeeded, FALSE otherwise. 147 * Remark: The handle is obtained in the PENUMERATE_RECYCLEBIN_CALLBACK callback 148 */ 149 BOOL WINAPI 150 GetDeletedFileDetailsA( 151 IN HANDLE hDeletedFile, 152 IN DWORD BufferSize, 153 IN OUT PDELETED_FILE_DETAILS_A FileDetails OPTIONAL, 154 OUT LPDWORD RequiredSize OPTIONAL); 155 BOOL WINAPI 156 GetDeletedFileDetailsW( 157 IN HANDLE hDeletedFile, 158 IN DWORD BufferSize, 159 IN OUT PDELETED_FILE_DETAILS_W FileDetails OPTIONAL, 160 OUT LPDWORD RequiredSize OPTIONAL); 161 #ifdef UNICODE 162 #define GetDeletedFileDetails GetDeletedFileDetailsW 163 #else 164 #define GetDeletedFileDetails GetDeletedFileDetailsA 165 #endif 166 167 /* Get details about a whole recycle bin 168 * pszVolume: 169 * pulTotalItems: 170 * pulTotalSize 171 */ 172 BOOL WINAPI 173 GetRecycleBinDetails( 174 IN LPCWSTR pszVolume OPTIONAL, 175 OUT ULARGE_INTEGER *pulTotalItems, 176 OUT ULARGE_INTEGER *pulTotalSize); 177 178 /* Restores a deleted file 179 * hDeletedFile: handle of the deleted file to restore 180 * Returns TRUE if operation succeeded, FALSE otherwise. 181 * Remarks: if the function succeeds, the handle is not valid anymore. 182 */ 183 BOOL WINAPI 184 RestoreFile( 185 IN HANDLE hDeletedFile); 186 187 /* COM interface */ 188 189 #define INTERFACE IRecycleBinFile 190 DECLARE_INTERFACE_(IRecycleBinFile, IUnknown) 191 { 192 BEGIN_INTERFACE 193 194 /* IUnknown methods */ 195 STDMETHOD(QueryInterface)(THIS_ REFIID riid, void **ppvObject) PURE; 196 STDMETHOD_(ULONG, AddRef)(THIS) PURE; 197 STDMETHOD_(ULONG, Release)(THIS) PURE; 198 199 /* IRecycleBinFile methods */ 200 STDMETHOD(GetLastModificationTime)(THIS_ FILETIME *pLastModificationTime) PURE; 201 STDMETHOD(GetDeletionTime)(THIS_ FILETIME *pDeletionTime) PURE; 202 STDMETHOD(GetFileSize)(THIS_ ULARGE_INTEGER *pFileSize) PURE; 203 STDMETHOD(GetPhysicalFileSize)(THIS_ ULARGE_INTEGER *pPhysicalFileSize) PURE; 204 STDMETHOD(GetAttributes)(THIS_ DWORD *pAttributes) PURE; 205 STDMETHOD(GetFileName)(THIS_ SIZE_T BufferSize, LPWSTR Buffer, SIZE_T *RequiredSize) PURE; 206 STDMETHOD(GetTypeName)(THIS_ SIZE_T BufferSize, LPWSTR Buffer, SIZE_T *RequiredSize) PURE; 207 STDMETHOD(Delete)(THIS) PURE; 208 STDMETHOD(Restore)(THIS) PURE; 209 210 END_INTERFACE 211 }; 212 #undef INTERFACE 213 214 #define INTERFACE IRecycleBinEnumList 215 DECLARE_INTERFACE_(IRecycleBinEnumList, IUnknown) 216 { 217 BEGIN_INTERFACE 218 219 /* IUnknown methods */ 220 STDMETHOD(QueryInterface)(THIS_ REFIID riid, void **ppvObject) PURE; 221 STDMETHOD_(ULONG, AddRef)(THIS) PURE; 222 STDMETHOD_(ULONG, Release)(THIS) PURE; 223 224 /* IRecycleBinEnumList methods */ 225 STDMETHOD(Next)(THIS_ DWORD celt, IRecycleBinFile **rgelt, DWORD *pceltFetched); 226 STDMETHOD(Skip)(THIS_ DWORD celt) PURE; 227 STDMETHOD(Reset)(THIS) PURE; 228 229 END_INTERFACE 230 }; 231 #undef INTERFACE 232 233 #define INTERFACE IRecycleBin 234 DECLARE_INTERFACE_(IRecycleBin, IUnknown) 235 { 236 BEGIN_INTERFACE 237 238 /* IUnknown methods */ 239 STDMETHOD(QueryInterface)(THIS_ REFIID riid, void **ppvObject) PURE; 240 STDMETHOD_(ULONG, AddRef)(THIS) PURE; 241 STDMETHOD_(ULONG, Release)(THIS) PURE; 242 243 /* IRecycleBin methods */ 244 STDMETHOD(DeleteFile)(THIS_ LPCWSTR szFileName); 245 STDMETHOD(EmptyRecycleBin)(THIS); 246 STDMETHOD(EnumObjects)(THIS_ IRecycleBinEnumList **ppEnumList); 247 248 END_INTERFACE 249 }; 250 #undef INTERFACE 251 252 EXTERN_C const IID IID_IRecycleBinFile; 253 EXTERN_C const IID IID_IRecycleBinEnumList; 254 EXTERN_C const IID IID_IRecycleBin; 255 256 #if (!defined(__cplusplus) || defined(CINTERFACE)) && defined(COBJMACROS) 257 #define IRecycleBinFile_QueryInterface(This, riid, ppvObject) \ 258 (This)->lpVtbl->QueryInterface(This, riid, ppvObject) 259 #define IRecycleBinFile_AddRef(This) \ 260 (This)->lpVtbl->AddRef(This) 261 #define IRecycleBinFile_Release(This) \ 262 (This)->lpVtbl->Release(This) 263 #define IRecycleBinFile_GetLastModificationTime(This, pLastModificationTime) \ 264 (This)->lpVtbl->GetLastModificationTime(This, pLastModificationTime) 265 #define IRecycleBinFile_GetDeletionTime(This, pDeletionTime) \ 266 (This)->lpVtbl->GetDeletionTime(This, pDeletionTime) 267 #define IRecycleBinFile_GetFileSize(This, pFileSize) \ 268 (This)->lpVtbl->GetFileSize(This, pFileSize) 269 #define IRecycleBinFile_GetPhysicalFileSize(This, pPhysicalFileSize) \ 270 (This)->lpVtbl->GetPhysicalFileSize(This, pPhysicalFileSize) 271 #define IRecycleBinFile_GetAttributes(This, pAttributes) \ 272 (This)->lpVtbl->GetAttributes(This, pAttributes) 273 #define IRecycleBinFile_GetFileName(This, BufferSize, Buffer, RequiredSize) \ 274 (This)->lpVtbl->GetFileName(This, BufferSize, Buffer, RequiredSize) 275 #define IRecycleBinFile_GetTypeName(This, BufferSize, Buffer, RequiredSize) \ 276 (This)->lpVtbl->GetTypeName(This, BufferSize, Buffer, RequiredSize) 277 #define IRecycleBinFile_Delete(This) \ 278 (This)->lpVtbl->Delete(This) 279 #define IRecycleBinFile_Restore(This) \ 280 (This)->lpVtbl->Restore(This) 281 282 #define IRecycleBinEnumList_QueryInterface(This, riid, ppvObject) \ 283 (This)->lpVtbl->QueryInterface(This, riid, ppvObject) 284 #define IRecycleBinEnumList_AddRef(This) \ 285 (This)->lpVtbl->AddRef(This) 286 #define IRecycleBinEnumList_Release(This) \ 287 (This)->lpVtbl->Release(This) 288 #define IRecycleBinEnumList_Next(This, celt, rgelt, pceltFetched) \ 289 (This)->lpVtbl->Next(This, celt, rgelt, pceltFetched) 290 #define IRecycleBinEnumList_Skip(This, celt) \ 291 (This)->lpVtbl->Skip(This, celt) 292 #define IRecycleBinEnumList_Reset(This) \ 293 (This)->lpVtbl->Reset(This) 294 295 #define IRecycleBin_QueryInterface(This, riid, ppvObject) \ 296 (This)->lpVtbl->QueryInterface(This, riid, ppvObject) 297 #define IRecycleBin_AddRef(This) \ 298 (This)->lpVtbl->AddRef(This) 299 #define IRecycleBin_Release(This) \ 300 (This)->lpVtbl->Release(This) 301 #define IRecycleBin_DeleteFile(This, szFileName) \ 302 (This)->lpVtbl->DeleteFile(This, szFileName) 303 #define IRecycleBin_EmptyRecycleBin(This) \ 304 (This)->lpVtbl->EmptyRecycleBin(This) 305 #define IRecycleBin_EnumObjects(This, ppEnumList) \ 306 (This)->lpVtbl->EnumObjects(This, ppEnumList) 307 #endif 308 309 HRESULT WINAPI 310 GetDefaultRecycleBin( 311 IN LPCWSTR pszVolume OPTIONAL, 312 OUT IRecycleBin **pprb); 313 314 #ifdef __cplusplus 315 } 316 #endif 317