WinStd Windows Win32 API using Standard C++

Loading...
Searching...
No Matches
Shell.h
1/*
2 SPDX-License-Identifier: MIT
3 Copyright © 1991-2024 Amebis
4 Copyright © 2016 GÉANT
5*/
6
8
9#pragma once
10
11#include "Common.h"
12#include <Shlwapi.h>
13#include <string>
14
17
19 template<class _Traits, class _Ax>
20 static BOOL PathCanonicalizeA(_Inout_ std::basic_string<char, _Traits, _Ax> &sValue, _In_ LPCSTR pszPath)
21{
22 char szBuffer[MAX_PATH + 1];
23 BOOL bResult = ::PathCanonicalizeA(szBuffer, pszPath);
24 sValue.assign(szBuffer, bResult ? MAX_PATH : 0);
25 return bResult;
26}
27
33 template<class _Traits, class _Ax>
34 static BOOL PathCanonicalizeW(_Inout_ std::basic_string<wchar_t, _Traits, _Ax> &sValue, _In_ LPCWSTR pszPath)
35{
36 wchar_t szBuffer[MAX_PATH + 1];
37 BOOL bResult = ::PathCanonicalizeW(szBuffer, pszPath);
38 sValue.assign(szBuffer, bResult ? MAX_PATH : 0);
39 return bResult;
40}
41
43 template<class _Traits, class _Ax>
44 static void PathRemoveBackslashA(_Inout_ std::basic_string<char, _Traits, _Ax>& sValue)
45{
46 char szBuffer[MAX_PATH + 1];
47 size_t len = sValue.length();
48 if (len < _countof(szBuffer)) {
49 memcpy(szBuffer, sValue.c_str(), len);
50 szBuffer[len] = 0;
51 PathRemoveBackslashA(szBuffer);
52 sValue.assign(szBuffer);
53 }
54 else {
55 std::unique_ptr<char[]> buf(new char[len + 1]);
56 memcpy(buf.get(), sValue.c_str(), len);
57 buf[len] = 0;
58 PathRemoveBackslashA(buf.get());
59 sValue.assign(buf.get());
60 }
61}
62
68 template<class _Traits, class _Ax>
69 static void PathRemoveBackslashW(_Inout_ std::basic_string<wchar_t, _Traits, _Ax>& sValue)
70{
71 wchar_t szBuffer[MAX_PATH + 1];
72 size_t len = sValue.length();
73 if (len < _countof(szBuffer)) {
74 wmemcpy(szBuffer, sValue.c_str(), len);
75 szBuffer[len] = 0;
76 PathRemoveBackslashW(szBuffer);
77 sValue.assign(szBuffer);
78 }
79 else {
80 std::unique_ptr<wchar_t[]> buf(new wchar_t[len + 1]);
81 wmemcpy(buf.get(), sValue.c_str(), len);
82 buf[len] = 0;
83 PathRemoveBackslashW(buf.get());
84 sValue.assign(buf.get());
85 }
86}
87
PathCanonicalizeW
static BOOL PathCanonicalizeW(std::basic_string< wchar_t, _Traits, _Ax > &sValue, LPCWSTR pszPath)
Simplifies a path by removing navigation elements such as "." and ".." to produce a direct,...
Definition Shell.h:34
PathRemoveBackslashW
static void PathRemoveBackslashW(std::basic_string< wchar_t, _Traits, _Ax > &sValue)
Removes the trailing backslash from a given path.
Definition Shell.h:69
PathRemoveBackslashA
static void PathRemoveBackslashA(std::basic_string< char, _Traits, _Ax > &sValue)
Removes the trailing backslash from a given path.
Definition Shell.h:44
PathCanonicalizeA
static BOOL PathCanonicalizeA(std::basic_string< char, _Traits, _Ax > &sValue, LPCSTR pszPath)
Simplifies a path by removing navigation elements such as "." and ".." to produce a direct,...
Definition Shell.h:20