Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
81 lines (64 loc) · 2.04 KB
/
Copy pathmain.cpp
File metadata and controls
81 lines (64 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* /////////////////////////////////////////////////////////////////////////
* File: by_library/windows_shell/shell_functions/shell_functions.cpp
*
* Purpose: C++ example program demonstrating use of the Windows Shell
* library filesystem functions.
*
* Created: 9th December 2006
* Updated: 9th October 2024
*
* ////////////////////////////////////////////////////////////////////// */
/* WinSTL header files */
#include <winstl/error/error_desc.hpp>
#include <winstl/filesystem/current_directory.hpp>
#include <winstl/shell/browse_for_folder.hpp>
#include <winstl/shell/file_operations.hpp>
#include <winstl/shell/memory/functions.h>
/* STLSoft header files */
#include <stlsoft/smartptr/scoped_handle.hpp>
/* Standard C++ header files */
#include <exception>
#include <iostream>
#include <string>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
/* Standard C header files */
#include <stdlib.h> // for EXIT_FAILURE, EXIT_SUCCESS
/* /////////////////////////////////////////////////////////////////////////
* main()
*/
int main()
{
try
{
CHAR displayName[_MAX_PATH + 1];
LPITEMIDLIST iil;
HRESULT hr = ::SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &iil);
if (FAILED(hr))
{
cerr << "Could not get the My Computer special folder location: " << winstl::error_desc(hr) << endl;
}
else
{
stlsoft::scoped_handle<void*> iil_(iil, winstl::SHMemFree);
if (winstl::browse_for_folder("Select a file to send to the recycle bin", displayName, BIF_BROWSEINCLUDEFILES, iil))
{
winstl::shell_delete(displayName, FOF_ALLOWUNDO);
}
}
return EXIT_SUCCESS;
}
catch (std::exception& x)
{
cerr << "Error: " << x.what() << endl;
return EXIT_FAILURE;
}
catch (...)
{
cerr << "Unknown error" << endl;
return EXIT_FAILURE;
}
}
/* ///////////////////////////// end of file //////////////////////////// */