xref: /reactos/dll/shellext/ntobjshex/util.h (revision c2c66aff)
1 #pragma once
2 
3 #ifndef INLINE
4 #define INLINE inline
5 #endif
6 
MakeStrRetFromString(LPCWSTR string,DWORD cbLength,STRRET * str)7 HRESULT INLINE MakeStrRetFromString(LPCWSTR string, DWORD cbLength, STRRET * str)
8 {
9     str->uType = STRRET_WSTR;
10 
11     DWORD blen = cbLength + sizeof(WCHAR);
12     str->pOleStr = (LPWSTR) CoTaskMemAlloc(blen);
13     return StringCbCopyNW(str->pOleStr, blen, string, cbLength);
14 }
15 
MakeStrRetFromString(LPCWSTR string,STRRET * str)16 HRESULT INLINE MakeStrRetFromString(LPCWSTR string, STRRET * str)
17 {
18     DWORD stringLength = wcslen(string) * sizeof(WCHAR);
19     return MakeStrRetFromString(string, stringLength, str);
20 }
21 
MakeVariantString(VARIANT * pv,PCWSTR string)22 HRESULT INLINE MakeVariantString(VARIANT * pv, PCWSTR string)
23 {
24     V_VT(pv) = VT_BSTR;
25     V_BSTR(pv) = SysAllocString(string);
26     return S_OK;
27 }
28 
GetFullName(PCIDLIST_ABSOLUTE pidl,DWORD uFlags,PWSTR strName,DWORD cchName)29 HRESULT INLINE GetFullName(PCIDLIST_ABSOLUTE pidl, DWORD uFlags, PWSTR strName, DWORD cchName)
30 {
31     CComPtr<IShellFolder> psfDesktop;
32     STRRET str;
33     HRESULT hr;
34 
35     hr = SHGetDesktopFolder(&psfDesktop);
36     if (FAILED_UNEXPECTEDLY(hr))
37         return hr;
38 
39     hr = psfDesktop->GetDisplayNameOf(pidl, uFlags, &str);
40     if (FAILED_UNEXPECTEDLY(hr))
41         return hr;
42 
43     return StrRetToBufW(&str, pidl, strName, cchName);
44 }
45