]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/wrapshl.h
Sorry, should be a __UNIX__ test
[wxWidgets.git] / include / wx / msw / wrapshl.h
CommitLineData
6bb09706
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/msw/wrapshl.h
3// Purpose: wrapper class for stuff from shell32.dll
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 2004-10-19
7// RCS-ID: $Id$
8// Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_MSW_WRAPSHL_H_
13#define _WX_MSW_WRAPSHL_H_
14
15#ifdef __WXWINCE__
16 #include <winreg.h>
17 #include <objbase.h>
18 #include <shlguid.h>
19#endif
20
21#include <shlobj.h>
22
23// ----------------------------------------------------------------------------
24// wxItemIdList implements RAII on top of ITEMIDLIST
25// ----------------------------------------------------------------------------
26
27class wxItemIdList
28{
29public:
30 // ctor takes ownership of the item and will free it
31 wxItemIdList(LPITEMIDLIST pidl)
32 {
33 m_pidl = pidl;
34 }
35
36 static void Free(LPITEMIDLIST pidl)
37 {
38 if ( pidl )
39 {
40 LPMALLOC pMalloc;
41 SHGetMalloc(&pMalloc);
42 if ( pMalloc )
43 {
44 pMalloc->Free(pidl);
45 pMalloc->Release();
46 }
47 else
48 {
49 wxLogLastError(wxT("SHGetMalloc"));
50 }
51 }
52 }
53
54 ~wxItemIdList()
55 {
56 Free(m_pidl);
57 }
58
59 // implicit conversion to LPITEMIDLIST
60 operator LPITEMIDLIST() const { return m_pidl; }
61
62 // get the corresponding path, returns empty string on error
63 wxString GetPath() const
64 {
65 wxString path;
66 if ( !SHGetPathFromIDList(m_pidl, wxStringBuffer(path, MAX_PATH)) )
67 {
68 wxLogLastError(_T("SHGetPathFromIDList"));
69 }
70
71 return path;
72 }
73
74private:
75 LPITEMIDLIST m_pidl;
76
77 DECLARE_NO_COPY_CLASS(wxItemIdList)
78};
79
80#endif // _WX_MSW_WRAPSHL_H_
81