폴더 이름 얻기에 관해 (::SHGetFileInfo, IShellFolder::GetDisplayNameOf)
마음끄적2010. 3. 20. 15:51
PIDL로 폴더의 이름을 얻기위해 ::SHGetFileInfo()를 사용중이었는데 "My Documents"나 "My Music" 같은 가상 폴더의 경우, "Administrator's Music" 같은 식으로 윈도우 계정의 이름이 붙어서 리턴됐다.
IShellFolder::GetDisplayNameOf()를 사용하면 "My Music" 처럼 탐색기에 보여지는 이름대로 리턴된다.
한가지 더, ::SHGetFileInfo()의 경우 IDLIST_RELATIVE 같은 부모폴더의 상대적인 PIDL을 전달하면
"C:\"나 "CD Drive (E:)" 같은 "My Computer"에 바로 붙은 노드들은 이름이 빈 문자열로 리턴되는 경우가 있다.
이럴 때 IDLIST_ABSOUTE의 PIDL을 전달해주면 제대로 이름을 얻어온다.
ITEMIDLIST의 타입에 대해선 MSDN을 참고하자.
ITEMIDLIST Strict Types
As of Windows Vista, several forms of
ITEMIDLIST are available as data types. The three main types are:
IDLIST_ABSOLUTE: Fully-qualified ITEMIDLIST relative to the root of
the namespace. It may be multi-level.
IDLIST_RELATIVE: ITEMIDLIST relative to a parent folder. It may be
multi-level.
ITEMID_CHILD: Single-level ITEMIDLIST relative to a parent folder. It
contains exactly one SHITEMID structure.
These types are used if you compile your code with the symbol
STRICT_TYPED_ITEMIDS before you include the Shell header files, as shown in the
following example code.
#define STRICT_TYPED_ITEMIDS // Better type saftey for IDLists
#include <shlobj.h> // Typical Shell header file
The meaning of each of these types can be altered with one or more of the
following modifiers:
P: The type is a pointer.
C: The type is constant.
U: The type is unaligned. It aligns to a DWORD boundary in 32-bit
architectures and a QWORD boundary in 64-bit architectures.
Some examples of these modified types are:
PIDLIST_ABSOLUTE: The ITEMIDLIST is absolute and has been allocated,
as indicated by its being non-constant. This means that it needs to be
deallocated with ILFree when it is no longer needed.
Because it is a direct pointer to allocated memory, it is aligned.
PCIDLIST_ABSOLUTE: The ITEMIDLIST is absolute and constant. This is
typically used when you are passed an absolute ITEMIDLIST as a parameter
but do not own it, and so are not allowed to change it.
PCUIDLIST_ABSOLUTE: The ITEMIDLIST is absolute, constant and
unaligned. This is rarely used. Absolute ITEMIDLIST are typically
allocated in memory aligned to a DWORD boundary in 32-bit architectures
and to a QWORD boundary in 64-bit architectures. An absolute
ITEMIDLIST would be unaligned only if it has been byte-packed along with
other data, such as in a serialization format.
PITEMID_CHILD: The ITEMIDLIST is an allocated child ITEMIDLIST
relative to a parent folder, such as a result of IEnumIDList::Next.
It contains exactly one SHITEMID structure.
PCUITEMID_CHILD: The child ITEMIDLIST is relative, constant, and
unaligned. This often occurs when you get a pointer to part of an existing
pointer to an item identifier list (PIDL). For example, if you have an absolute
PIDL and call ILFindLastID, it returns the
pointer to the last child SHITEMID in the list. It is unaligned because
the byte-packed PIDL does not ensure that its individual SHITEMID
structures fall on byte boundaries. References to child PIDLs such as these are
always constant because the memory is owned by the absolute PIDL.
PCITEMID_CHILD: The child ITEMIDLIST is constant and aligned. This is
rarely used because as a child PIDL, it is usually a part of a larger PIDL, and
therefore not aligned on byte boundaries.
PUITEMID_CHILD: The child ITEMIDLIST is unaligned. This is rarely
used because memory for this ITEMIDLIST is owned by the parent PIDL,
which is absolute. This means that modifications can be made only to the parent
PIDL, and so the child PIDL would need to be constant.
This list is not exhaustive. Other types can also exist.