745a29e59a316d5a00b33032ea5815d435312648
[reactos.git] / reactos / sdk / lib / 3rdparty / atlex / atlshlwapi.h
1 /*
2 Copyright 1991-2017 Amebis
3
4 This file is part of atlex.
5
6 atlex is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
10
11 atlex is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with atlex. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #pragma once
21
22 #include <atlstr.h>
23 #include <Shlwapi.h>
24
25 ///
26 /// \defgroup ATLShellWAPI Shell API
27 /// Integrates ATL classes with Microsoft Shell API
28 ///
29 /// @{
30
31 ///
32 /// Simplifies a path by removing navigation elements such as "." and ".." to produce a direct, well-formed path, and stores it in a ATL::CAtlStringA string.
33 ///
34 /// \sa [PathCanonicalize function](https://msdn.microsoft.com/en-us/library/windows/desktop/bb773569.aspx)
35 ///
36 inline BOOL PathCanonicalizeA(__out ATL::CAtlStringA &sValue, __in LPCSTR pszPath)
37 {
38 // Allocate buffer on heap and read into it.
39 LPSTR szBuffer = sValue.GetBuffer(MAX_PATH);
40 if (!szBuffer) {
41 ::SetLastError(ERROR_OUTOFMEMORY);
42 return FALSE;
43 }
44 BOOL bResult = ::PathCanonicalizeA(szBuffer, pszPath);
45 sValue.ReleaseBuffer(bResult ? (int)strnlen(szBuffer, MAX_PATH) : 0);
46 sValue.FreeExtra();
47 return bResult;
48 }
49
50
51 ///
52 /// Simplifies a path by removing navigation elements such as "." and ".." to produce a direct, well-formed path, and stores it in a ATL::CAtlStringW string.
53 ///
54 /// \sa [PathCanonicalize function](https://msdn.microsoft.com/en-us/library/windows/desktop/bb773569.aspx)
55 ///
56 inline BOOL PathCanonicalizeW(__out ATL::CAtlStringW &sValue, __in LPCWSTR pszPath)
57 {
58 // Allocate buffer on heap and read into it.
59 LPWSTR szBuffer = sValue.GetBuffer(MAX_PATH);
60 if (!szBuffer) {
61 ::SetLastError(ERROR_OUTOFMEMORY);
62 return FALSE;
63 }
64 BOOL bResult = ::PathCanonicalizeW(szBuffer, pszPath);
65 sValue.ReleaseBuffer(bResult ? (int)wcsnlen(szBuffer, MAX_PATH) : 0);
66 sValue.FreeExtra();
67 return bResult;
68 }
69
70 /// @}