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