ReactOS 0.4.15-dev-8241-g63935f8
enumlist.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Shell
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: CNetworkConnections Shell Folder items enumerator
5 * COPYRIGHT: Copyright 2008 Johannes Anderwald (johannes.anderwald@reactos.org)
6 */
7
8#include "precomp.h"
9
11{
12 if (!pidl || !pidl->mkid.cb || pidl->mkid.abID[0] != 0x99)
13 return NULL;
14 return (PNETCONIDSTRUCT)(&pidl->mkid.abID[0]);
15}
16
18{
20 if (!pdata)
21 return NULL;
22 return (PWCHAR)&pidl->mkid.abID[pdata->uNameOffset];
23}
24
26{
28 if (!pdata)
29 return NULL;
30 return (PWCHAR)&pidl->mkid.abID[pdata->uDeviceNameOffset];
31}
32
34{
35 PITEMID_CHILD pidl;
37 NETCON_PROPERTIES * pProperties;
38 PNETCONIDSTRUCT pnetid;
39 PWCHAR pwchName;
40
41 if (pItem->GetProperties(&pProperties) != S_OK)
42 return NULL;
43
44 size = sizeof(WORD); /* nr of bytes in this item */
45 size += sizeof(NETCONIDSTRUCT);
46 size += (wcslen(pProperties->pszwName) + 1) * sizeof(WCHAR);
47 size += (wcslen(pProperties->pszwDeviceName) + 1) * sizeof(WCHAR);
48
49 /* Allocate enough memory for the trailing id which will indicate that this is a simple id */
50 pidl = static_cast<LPITEMIDLIST>(SHAlloc(size + sizeof(SHITEMID)));
51 pidl->mkid.cb = (WORD)size;
52 pidl->mkid.abID[0] = 0x99;
53
54 /* Copy the connection properties */
55 pnetid = ILGetConnData(pidl);
56 pnetid->guidId = pProperties->guidId;
57 pnetid->Status = pProperties->Status;
58 pnetid->MediaType = pProperties->MediaType;
59 pnetid->dwCharacter = pProperties->dwCharacter;
60 pnetid->uNameOffset = sizeof(NETCONIDSTRUCT);
61 pnetid->uDeviceNameOffset = pnetid->uNameOffset + (wcslen(pProperties->pszwName) + 1) * sizeof(WCHAR);
62
63 pwchName = ILGetConnName(pidl);
64 wcscpy(pwchName, pProperties->pszwName);
65
66 pwchName = ILGetDeviceName(pidl);
67 wcscpy(pwchName, pProperties->pszwDeviceName);
68
69 /* Set the trailing id to null */
70 memset((void*)((ULONG_PTR)pidl + size), 0, sizeof(SHITEMID));
71
72 NcFreeNetconProperties(pProperties);
73
74 return pidl;
75}
76
78{
79 HRESULT hr;
84 NETCON_PROPERTIES * pProperties;
85
87 if (!pdata)
88 return E_FAIL;
89
90 /* get an instance to of IConnectionManager */
91 hr = CNetConnectionManager_CreateInstance(IID_PPV_ARG(INetConnectionManager, &pNetConMan));
93 return hr;
94
95 hr = pNetConMan->EnumConnections(NCME_DEFAULT, &pEnumCon);
97 return hr;
98
99 while (TRUE)
100 {
101 hr = pEnumCon->Next(1, &INetCon, &Count);
102 if (hr != S_OK)
103 return E_FAIL;
104
105 hr = INetCon->GetProperties(&pProperties);
107 continue;
108
109 BOOL bSame = !memcmp(&pProperties->guidId, &pdata->guidId, sizeof(GUID));
110
111 NcFreeNetconProperties(pProperties);
112
113 if (bSame)
114 {
115 *pItem = INetCon.Detach();
116 return S_OK;
117 }
118 }
119
120 return E_FAIL;
121}
122
123typedef struct tagENUMLIST
124{
128
130 public CComObjectRootEx<CComMultiThreadModelNoCS>,
131 public IEnumIDList
132{
133 public:
134 CEnumIDList();
135 ~CEnumIDList();
136
138
139 // IEnumIDList
140 STDMETHOD(Next)(ULONG celt, PITEMID_CHILD *rgelt, ULONG *pceltFetched) override;
141 STDMETHOD(Skip)(ULONG celt) override;
142 STDMETHOD(Reset)() override;
143 STDMETHOD(Clone)(IEnumIDList **ppenum) override;
144
145 private:
147
151
152 public:
155
157 COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList)
159};
160
161/**************************************************************************
162 * AddToEnumList()
163 */
164BOOL
166{
167 LPENUMLIST pNew;
168
169 if (!pidl)
170 return FALSE;
171
172 pNew = static_cast<LPENUMLIST>(SHAlloc(sizeof(ENUMLIST)));
173 if (pNew)
174 {
175 pNew->pNext = NULL;
176 pNew->pidl = pidl;
177
178 if (!m_pFirst)
179 {
180 m_pFirst = pNew;
181 m_pCurrent = pNew;
182 }
183
184 if (m_pLast)
185 {
186 /*add the new item to the end of the list */
187 m_pLast->pNext = pNew;
188 }
189
190 /*update the last item pointer */
191 m_pLast = pNew;
192 return TRUE;
193 }
194 return FALSE;
195}
196
198 m_pFirst(NULL),
199 m_pLast(NULL),
201{
202}
203
205{
206 LPENUMLIST pDelete;
207
208 while (m_pFirst)
209 {
210 pDelete = m_pFirst;
211 m_pFirst = pDelete->pNext;
212 SHFree(pDelete->pidl);
213 SHFree(pDelete);
214 }
215}
216
219{
220 HRESULT hr;
223 ULONG Count;
224 PITEMID_CHILD pidl;
225
226 /* get an instance to of IConnectionManager */
227 hr = CNetConnectionManager_CreateInstance(IID_PPV_ARG(INetConnectionManager, &pNetConMan));
229 return S_OK;
230
231 hr = pNetConMan->EnumConnections(NCME_DEFAULT, &pEnumCon);
233 return S_OK;
234
235 while (TRUE)
236 {
238
239 hr = pEnumCon->Next(1, &INetCon, &Count);
240 if (hr != S_OK)
241 break;
242
243 pidl = ILCreateNetConnectItem(INetCon);
244 if (pidl)
245 {
246 AddToEnumList(pidl);
247 }
248 }
249
250 return S_OK;
251}
252
254WINAPI
256 ULONG celt,
257 PITEMID_CHILD *rgelt,
258 ULONG *pceltFetched)
259{
260 ULONG i;
261 HRESULT hr = S_OK;
263
264 if (pceltFetched)
265 *pceltFetched = 0;
266
267 if (celt > 1 && !pceltFetched)
268 {
269 return E_INVALIDARG;
270 }
271
272 if (celt > 0 && !m_pCurrent)
273 {
274 return S_FALSE;
275 }
276
277 for (i = 0; i < celt; i++)
278 {
279 if (!m_pCurrent)
280 {
281 hr = S_FALSE;
282 break;
283 }
284
286 if (!temp)
287 {
289 break;
290 }
291 rgelt[i] = temp;
293 }
294
295 if (pceltFetched)
296 *pceltFetched = i;
297
298 return hr;
299}
300
302WINAPI
304{
305 DWORD dwIndex;
306 HRESULT hr = S_OK;
307
308 for (dwIndex = 0; dwIndex < celt; dwIndex++)
309 {
310 if (!m_pCurrent)
311 {
312 hr = S_FALSE;
313 break;
314 }
316 }
317
318 return hr;
319}
320
322WINAPI
324{
326 return S_OK;
327}
328
330WINAPI
332 LPENUMIDLIST * ppenum)
333{
334 return E_NOTIMPL;
335}
336
338{
339 return ShellObjectCreatorInit<CEnumIDList>(riid, ppv);
340}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define STDMETHOD(m)
Definition: basetyps.h:62
T * Detach()
Definition: atlcomcli.h:186
HRESULT Initialize()
Definition: enumlist.cpp:218
STDMETHOD() Reset() override
Definition: enumlist.cpp:323
STDMETHOD() Skip(ULONG celt) override
Definition: enumlist.cpp:303
LPENUMLIST m_pFirst
Definition: enumlist.cpp:148
BOOL AddToEnumList(PITEMID_CHILD pidl)
Definition: enumlist.cpp:165
STDMETHOD() Clone(IEnumIDList **ppenum) override
Definition: enumlist.cpp:331
STDMETHOD() Next(ULONG celt, PITEMID_CHILD *rgelt, ULONG *pceltFetched) override
Definition: enumlist.cpp:255
LPENUMLIST m_pCurrent
Definition: enumlist.cpp:150
LPENUMLIST m_pLast
Definition: enumlist.cpp:149
HRESULT WINAPI CNetConnectionManager_CreateInstance(REFIID riid, LPVOID *ppv)
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
struct tagNETCONIDSTRUCT NETCONIDSTRUCT
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
void WINAPI SHFree(LPVOID pv)
Definition: shellole.c:326
LPVOID WINAPI SHAlloc(SIZE_T len)
Definition: shellole.c:304
struct tagENUMLIST * LPENUMLIST
PITEMID_CHILD ILCreateNetConnectItem(INetConnection *pItem)
Definition: enumlist.cpp:33
HRESULT CEnumIDList_CreateInstance(HWND hwndOwner, DWORD dwFlags, REFIID riid, LPVOID *ppv)
Definition: enumlist.cpp:337
struct tagENUMLIST ENUMLIST
PWCHAR ILGetDeviceName(PCITEMID_CHILD pidl)
Definition: enumlist.cpp:25
HRESULT ILGetConnection(PCITEMID_CHILD pidl, INetConnection **pItem)
Definition: enumlist.cpp:77
PNETCONIDSTRUCT ILGetConnData(PCITEMID_CHILD pidl)
Definition: enumlist.cpp:10
PWCHAR ILGetConnName(PCITEMID_CHILD pidl)
Definition: enumlist.cpp:17
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
GLsizeiptr size
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
REFIID riid
Definition: atlbase.h:39
REFIID LPVOID * ppv
Definition: atlbase.h:39
HRESULT GetProperties([out] NETCON_PROPERTIES **ppProps)
#define S_OK
Definition: intsafe.h:52
#define BEGIN_COM_MAP(x)
Definition: atlcom.h:581
#define COM_INTERFACE_ENTRY_IID(iid, x)
Definition: atlcom.h:601
#define DECLARE_PROTECT_FINAL_CONSTRUCT()
Definition: atlcom.h:679
#define DECLARE_NOT_AGGREGATABLE(x)
Definition: atlcom.h:651
#define END_COM_MAP()
Definition: atlcom.h:592
static PROTOCOLDATA * pdata
Definition: protocol.c:158
@ NCME_DEFAULT
Definition: netcon.h:10
VOID WINAPI NcFreeNetconProperties(NETCON_PROPERTIES *pProps)
Definition: netshell.cpp:119
int Count
Definition: noreturn.cpp:7
LPITEMIDLIST WINAPI ILClone(LPCITEMIDLIST pidl)
Definition: pidl.c:237
#define REFIID
Definition: guiddef.h:118
static calc_node_t temp
Definition: rpn_ieee.c:38
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define memset(x, y, z)
Definition: compat.h:39
HRESULT hr
Definition: shlfolder.c:183
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
BYTE abID[1]
Definition: shtypes.idl:28
WORD cb
Definition: shtypes.idl:27
SHITEMID mkid
Definition: shtypes.idl:34
struct tagENUMLIST * pNext
Definition: enumlist.cpp:125
PITEMID_CHILD pidl
Definition: enumlist.cpp:126
ULONG_PTR uDeviceNameOffset
Definition: precomp.h:66
DWORD dwCharacter
Definition: precomp.h:64
NETCON_MEDIATYPE MediaType
Definition: precomp.h:63
ULONG_PTR uNameOffset
Definition: precomp.h:65
NETCON_STATUS Status
Definition: precomp.h:62
NETCON_STATUS Status
Definition: netcon.h:86
LPWSTR pszwDeviceName
Definition: netcon.h:85
NETCON_MEDIATYPE MediaType
Definition: netcon.h:87
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define WINAPI
Definition: msvc.h:6
#define S_FALSE
Definition: winerror.h:2357
#define IID_PPV_ARG(Itype, ppType)
__wchar_t WCHAR
Definition: xmlstorage.h:180