ReactOS 0.4.16-dev-334-g4d9f67c
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 >= 2 + sizeof(NETCONIDSTRUCT))
13 {
15 if (pData->Signature == NETCONIDSTRUCT_SIG)
16 return pData;
17 }
18 return NULL;
19}
20
22{
24 if (!pdata)
25 return NULL;
26 return (PWCHAR)&pidl->mkid.abID[pdata->uNameOffset];
27}
28
30{
32 if (!pdata)
33 return NULL;
34 return (PWCHAR)&pidl->mkid.abID[pdata->uDeviceNameOffset];
35}
36
38{
39 PITEMID_CHILD pidl;
41 NETCON_PROPERTIES * pProperties;
42 PNETCONIDSTRUCT pnetid;
43 PWCHAR pwchName;
44
45 if (pItem->GetProperties(&pProperties) != S_OK)
46 return NULL;
47
48 size = sizeof(WORD); /* nr of bytes in this item */
49 size += sizeof(NETCONIDSTRUCT);
50 size += (wcslen(pProperties->pszwName) + 1) * sizeof(WCHAR);
51 size += (wcslen(pProperties->pszwDeviceName) + 1) * sizeof(WCHAR);
52
53 /* Allocate enough memory for the trailing id which will indicate that this is a simple id */
54 pidl = static_cast<LPITEMIDLIST>(SHAlloc(size + sizeof(SHITEMID)));
55 if (!pidl)
56 goto end;
57 pidl->mkid.cb = (WORD)size;
59
60 /* Copy the connection properties */
61 pnetid = ILGetConnData(pidl);
62 memset(pnetid->Unknown, 0, sizeof(pnetid->Unknown));
63 pnetid->clsidThisObject = pProperties->clsidThisObject;
64 pnetid->guidId = pProperties->guidId;
65 pnetid->Status = pProperties->Status;
66 pnetid->MediaType = pProperties->MediaType;
67 pnetid->dwCharacter = pProperties->dwCharacter;
68 pnetid->uNameOffset = sizeof(NETCONIDSTRUCT);
69 pnetid->uDeviceNameOffset = ULONG(pnetid->uNameOffset + (wcslen(pProperties->pszwName) + 1) * sizeof(WCHAR));
70
71 pwchName = ILGetConnName(pidl);
72 wcscpy(pwchName, pProperties->pszwName);
73
74 pwchName = ILGetDeviceName(pidl);
75 wcscpy(pwchName, pProperties->pszwDeviceName);
76
77 /* Set the trailing id to null */
78 memset((void*)((ULONG_PTR)pidl + size), 0, sizeof(SHITEMID));
79end:
80 NcFreeNetconProperties(pProperties);
81
82 return pidl;
83}
84
86{
87 HRESULT hr;
92 NETCON_PROPERTIES * pProperties;
93
95 if (!pdata)
96 return E_FAIL;
97
98 /* get an instance to of IConnectionManager */
99 hr = CNetConnectionManager_CreateInstance(IID_PPV_ARG(INetConnectionManager, &pNetConMan));
101 return hr;
102
103 hr = pNetConMan->EnumConnections(NCME_DEFAULT, &pEnumCon);
105 return hr;
106
107 while (TRUE)
108 {
109 hr = pEnumCon->Next(1, &INetCon, &Count);
110 if (hr != S_OK)
111 return E_FAIL;
112
113 hr = INetCon->GetProperties(&pProperties);
115 continue;
116
117 BOOL bSame = !memcmp(&pProperties->guidId, &pdata->guidId, sizeof(GUID));
118
119 NcFreeNetconProperties(pProperties);
120
121 if (bSame)
122 {
123 *pItem = INetCon.Detach();
124 return S_OK;
125 }
126 }
127
128 return E_FAIL;
129}
130
131typedef struct tagENUMLIST
132{
136
137class CEnumIDList:
138 public CComObjectRootEx<CComMultiThreadModelNoCS>,
139 public IEnumIDList
140{
141 public:
144
146
147 // IEnumIDList
148 STDMETHOD(Next)(ULONG celt, PITEMID_CHILD *rgelt, ULONG *pceltFetched) override;
149 STDMETHOD(Skip)(ULONG celt) override;
150 STDMETHOD(Reset)() override;
151 STDMETHOD(Clone)(IEnumIDList **ppenum) override;
152
153 private:
155
159
160 public:
163
165 COM_INTERFACE_ENTRY_IID(IID_IEnumIDList, IEnumIDList)
167};
168
169/**************************************************************************
170 * AddToEnumList()
171 */
172BOOL
174{
175 LPENUMLIST pNew;
176
177 if (!pidl)
178 return FALSE;
179
180 pNew = static_cast<LPENUMLIST>(SHAlloc(sizeof(ENUMLIST)));
181 if (pNew)
182 {
183 pNew->pNext = NULL;
184 pNew->pidl = pidl;
185
186 if (!m_pFirst)
187 {
188 m_pFirst = pNew;
189 m_pCurrent = pNew;
190 }
191
192 if (m_pLast)
193 {
194 /*add the new item to the end of the list */
195 m_pLast->pNext = pNew;
196 }
197
198 /*update the last item pointer */
199 m_pLast = pNew;
200 return TRUE;
201 }
202 return FALSE;
203}
204
206 m_pFirst(NULL),
207 m_pLast(NULL),
209{
210}
211
213{
214 LPENUMLIST pDelete;
215
216 while (m_pFirst)
217 {
218 pDelete = m_pFirst;
219 m_pFirst = pDelete->pNext;
220 SHFree(pDelete->pidl);
221 SHFree(pDelete);
222 }
223}
224
227{
228 HRESULT hr;
231 ULONG Count;
232 PITEMID_CHILD pidl;
233
234 /* get an instance to of IConnectionManager */
235 hr = CNetConnectionManager_CreateInstance(IID_PPV_ARG(INetConnectionManager, &pNetConMan));
237 return S_OK;
238
239 hr = pNetConMan->EnumConnections(NCME_DEFAULT, &pEnumCon);
241 return S_OK;
242
243 while (TRUE)
244 {
246
247 hr = pEnumCon->Next(1, &INetCon, &Count);
248 if (hr != S_OK)
249 break;
250
251 pidl = ILCreateNetConnectItem(INetCon);
252 if (pidl)
253 {
254 AddToEnumList(pidl);
255 }
256 }
257
258 return S_OK;
259}
260
262WINAPI
264 ULONG celt,
265 PITEMID_CHILD *rgelt,
266 ULONG *pceltFetched)
267{
268 ULONG i;
269 HRESULT hr = S_OK;
271
272 if (pceltFetched)
273 *pceltFetched = 0;
274
275 if (celt > 1 && !pceltFetched)
276 {
277 return E_INVALIDARG;
278 }
279
280 if (celt > 0 && !m_pCurrent)
281 {
282 return S_FALSE;
283 }
284
285 for (i = 0; i < celt; i++)
286 {
287 if (!m_pCurrent)
288 {
289 hr = S_FALSE;
290 break;
291 }
292
294 if (!temp)
295 {
297 break;
298 }
299 rgelt[i] = temp;
301 }
302
303 if (pceltFetched)
304 *pceltFetched = i;
305
306 return hr;
307}
308
310WINAPI
312{
313 DWORD dwIndex;
314 HRESULT hr = S_OK;
315
316 for (dwIndex = 0; dwIndex < celt; dwIndex++)
317 {
318 if (!m_pCurrent)
319 {
320 hr = S_FALSE;
321 break;
322 }
324 }
325
326 return hr;
327}
328
330WINAPI
332{
334 return S_OK;
335}
336
338WINAPI
340 LPENUMIDLIST * ppenum)
341{
342 return E_NOTIMPL;
343}
344
346{
347 return ShellObjectCreatorInit<CEnumIDList>(riid, ppv);
348}
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
IFACEMETHODIMP Reset()
Definition: cabview.h:80
HRESULT Initialize()
Definition: enumlist.cpp:226
IFACEMETHODIMP Next(ULONG celt, PITEMID_CHILD *rgelt, ULONG *pceltFetched)
Definition: cabview.h:63
LPENUMLIST m_pFirst
Definition: enumlist.cpp:156
BOOL AddToEnumList(PITEMID_CHILD pidl)
Definition: enumlist.cpp:173
IFACEMETHODIMP Skip(ULONG celt)
Definition: cabview.h:86
LPENUMLIST m_pCurrent
Definition: enumlist.cpp:158
LPENUMLIST m_pLast
Definition: enumlist.cpp:157
IFACEMETHODIMP Clone(IEnumIDList **ppenum)
Definition: cabview.h:95
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
#define NETCONIDSTRUCT_SIG
Definition: precomp.h:59
struct tagNETCONIDSTRUCT NETCONIDSTRUCT
struct tagNETCONIDSTRUCT * PNETCONIDSTRUCT
#define FAILED_UNEXPECTEDLY(hr)
Definition: precomp.h:121
static const WCHAR Signature[]
Definition: parser.c:141
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:37
HRESULT CEnumIDList_CreateInstance(HWND hwndOwner, DWORD dwFlags, REFIID riid, LPVOID *ppv)
Definition: enumlist.cpp:345
struct tagENUMLIST ENUMLIST
PWCHAR ILGetDeviceName(PCITEMID_CHILD pidl)
Definition: enumlist.cpp:29
HRESULT ILGetConnection(PCITEMID_CHILD pidl, INetConnection **pItem)
Definition: enumlist.cpp:85
PNETCONIDSTRUCT ILGetConnData(PCITEMID_CHILD pidl)
Definition: enumlist.cpp:10
PWCHAR ILGetConnName(PCITEMID_CHILD pidl)
Definition: enumlist.cpp:21
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
GLuint GLuint end
Definition: gl.h:1545
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
if(dx< 0)
Definition: linetemp.h:194
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:133
PITEMID_CHILD pidl
Definition: enumlist.cpp:134
DWORD dwCharacter
Definition: precomp.h:66
NETCON_MEDIATYPE MediaType
Definition: precomp.h:67
BYTE Unknown[8]
Definition: precomp.h:63
NETCON_STATUS Status
Definition: precomp.h:68
ULONG uDeviceNameOffset
Definition: precomp.h:70
ULONG uNameOffset
Definition: precomp.h:69
CLSID clsidThisObject
Definition: precomp.h:64
NETCON_STATUS Status
Definition: netcon.h:86
LPWSTR pszwDeviceName
Definition: netcon.h:85
CLSID clsidThisObject
Definition: netcon.h:89
NETCON_MEDIATYPE MediaType
Definition: netcon.h:87
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1830
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