-
Notifications
You must be signed in to change notification settings - Fork 3
/
ItemIDList.h
59 lines (58 loc) · 1.07 KB
/
ItemIDList.h
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
#pragma once
class CItemIDList
{
public:
LPITEMIDLIST m_pidl;
CItemIDList() : m_pidl(NULL)
{
}
CItemIDList(LPCITEMIDLIST pidl)
{
m_pidl = _CopyItemIDList(pidl);
}
virtual ~CItemIDList()
{
::CoTaskMemFree(m_pidl);
}
CString GetPath()
{
TCHAR szPath[MAX_PATH] = {0};
if (::SHGetPathFromIDList(m_pidl, szPath))
return szPath;
else
return CString();
}
protected:
UINT _GetSize(LPCITEMIDLIST pidl)
{
UINT cbTotal = 0;
if (pidl)
{
cbTotal += sizeof(pidl->mkid.cb);
while (pidl->mkid.cb)
{
cbTotal += pidl->mkid.cb;
pidl = _Next(pidl);
}
}
return cbTotal;
}
LPITEMIDLIST _Next(LPCITEMIDLIST pidl)
{
ATLASSERT(pidl != NULL);
LPSTR lpMem = (LPSTR)pidl;
lpMem += pidl->mkid.cb;
return (LPITEMIDLIST)lpMem;
}
LPITEMIDLIST _CopyItemIDList(LPCITEMIDLIST lpi)
{
if (lpi == NULL)
return NULL;
UINT cb = _GetSize(lpi);
LPITEMIDLIST lpiTemp = (LPITEMIDLIST)::CoTaskMemAlloc(cb);
if (lpiTemp == NULL)
return NULL;
::memcpy(lpiTemp, lpi, cb);
return lpiTemp;
}
};