ReactOS 0.4.17-dev-966-gf06eace
container.c
Go to the documentation of this file.
1/*
2 * IDxDiagContainer Implementation
3 *
4 * Copyright 2004 Raphael Junqueira
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 *
20 */
21
22
23#define COBJMACROS
24#include "dxdiag_private.h"
25#include "wine/debug.h"
26
28
29static inline IDxDiagContainerImpl *impl_from_IDxDiagContainer(IDxDiagContainer *iface)
30{
31 return CONTAINING_RECORD(iface, IDxDiagContainerImpl, IDxDiagContainer_iface);
32}
33
34/* IDxDiagContainer IUnknown parts follow: */
36 void **ppobj)
37{
39
40 if (!ppobj) return E_INVALIDARG;
41
43 || IsEqualGUID(riid, &IID_IDxDiagContainer)) {
44 IUnknown_AddRef(iface);
45 *ppobj = &This->IDxDiagContainer_iface;
46 return S_OK;
47 }
48
49 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
50 *ppobj = NULL;
51 return E_NOINTERFACE;
52}
53
54static ULONG WINAPI IDxDiagContainerImpl_AddRef(IDxDiagContainer *iface)
55{
57 ULONG refCount = InterlockedIncrement(&This->ref);
58
59 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
60
62
63 return refCount;
64}
65
66static ULONG WINAPI IDxDiagContainerImpl_Release(IDxDiagContainer *iface)
67{
69 ULONG refCount = InterlockedDecrement(&This->ref);
70
71 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
72
73 if (!refCount) {
76 }
77
79
80 return refCount;
81}
82
83/* IDxDiagContainer Interface follow: */
85 DWORD *pdwCount)
86{
88
89 TRACE("(%p)\n", iface);
90 if (NULL == pdwCount) {
91 return E_INVALIDARG;
92 }
93 *pdwCount = This->cont->nSubContainers;
94 return S_OK;
95}
96
98 DWORD dwIndex, LPWSTR pwszContainer, DWORD cchContainer)
99{
102 DWORD i = 0;
103
104 TRACE("(%p, %lu, %p, %lu)\n", iface, dwIndex, pwszContainer, cchContainer);
105
106 if (NULL == pwszContainer || 0 == cchContainer) {
107 return E_INVALIDARG;
108 }
109
111 {
112 if (dwIndex == i) {
113 TRACE("Found container name %s, copying string\n", debugstr_w(p->contName));
114 lstrcpynW(pwszContainer, p->contName, cchContainer);
115 return (cchContainer <= lstrlenW(p->contName)) ?
117 }
118 ++i;
119 }
120
121 TRACE("Failed to find container name at specified index\n");
122 *pwszContainer = '\0';
123 return E_INVALIDARG;
124}
125
128
130 {
131 if (0 == lstrcmpW(p->contName, pwszContainer)) {
132 *subcont = p;
133 return S_OK;
134 }
135 }
136
137 return E_INVALIDARG;
138}
139
141 LPCWSTR pwszContainer, IDxDiagContainer **ppInstance)
142{
144 IDxDiagContainerImpl_Container *pContainer = This->cont;
145 LPWSTR tmp, orig_tmp;
146 INT tmp_len;
147 WCHAR* cur;
149
150 TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszContainer), ppInstance);
151
152 if (NULL == ppInstance || NULL == pwszContainer) {
153 return E_INVALIDARG;
154 }
155
156 *ppInstance = NULL;
157
158 tmp_len = lstrlenW(pwszContainer) + 1;
159 orig_tmp = tmp = HeapAlloc(GetProcessHeap(), 0, tmp_len * sizeof(WCHAR));
160 if (NULL == tmp) return E_FAIL;
161 lstrcpynW(tmp, pwszContainer, tmp_len);
162
163 /* special handling for an empty string and leaf container */
164 if (!tmp[0] && list_empty(&pContainer->subContainers)) {
165 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, pContainer, This->pProv, (void **)ppInstance);
166 if (SUCCEEDED(hr))
167 TRACE("Succeeded in getting the container instance\n");
168 goto out;
169 }
170
171 cur = wcschr(tmp, '.');
172 while (NULL != cur) {
173 *cur = '\0'; /* cut tmp string to '.' */
174 if (!*(cur + 1)) break; /* Account for a lone terminating period, as in "cont1.cont2.". */
175 TRACE("Trying to get parent container %s\n", debugstr_w(tmp));
176 hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, &pContainer);
177 if (FAILED(hr))
178 goto out;
179 cur++; /* go after '.' (just replaced by \0) */
180 tmp = cur;
181 cur = wcschr(tmp, '.');
182 }
183
184 TRACE("Trying to get container %s\n", debugstr_w(tmp));
185 hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, &pContainer);
186 if (SUCCEEDED(hr)) {
187 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, pContainer, This->pProv, (void **)ppInstance);
188 if (SUCCEEDED(hr))
189 TRACE("Succeeded in getting the container instance\n");
190 }
191
192out:
193 HeapFree(GetProcessHeap(), 0, orig_tmp);
194 return hr;
195}
196
198 DWORD *pdwCount)
199{
201
202 TRACE("(%p)\n", iface);
203 if (NULL == pdwCount) {
204 return E_INVALIDARG;
205 }
206 *pdwCount = This->cont->nProperties;
207 return S_OK;
208}
209
210static HRESULT WINAPI IDxDiagContainerImpl_EnumPropNames(IDxDiagContainer *iface, DWORD dwIndex,
211 LPWSTR pwszPropName, DWORD cchPropName)
212{
215 DWORD i = 0;
216
217 TRACE("(%p, %lu, %p, %lu)\n", iface, dwIndex, pwszPropName, cchPropName);
218
219 if (NULL == pwszPropName || 0 == cchPropName) {
220 return E_INVALIDARG;
221 }
222
224 {
225 if (dwIndex == i) {
226 TRACE("Found property name %s, copying string\n", debugstr_w(p->propName));
227 lstrcpynW(pwszPropName, p->propName, cchPropName);
228 return (cchPropName <= lstrlenW(p->propName)) ?
230 }
231 ++i;
232 }
233
234 TRACE("Failed to find property name at specified index\n");
235 return E_INVALIDARG;
236}
237
238static HRESULT WINAPI IDxDiagContainerImpl_GetProp(IDxDiagContainer *iface, LPCWSTR pwszPropName,
239 VARIANT *pvarProp)
240{
243
244 TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszPropName), pvarProp);
245
246 if (NULL == pvarProp || NULL == pwszPropName) {
247 return E_INVALIDARG;
248 }
249
251 {
252 if (0 == lstrcmpW(p->propName, pwszPropName)) {
253 VariantInit(pvarProp);
254 return VariantCopy(pvarProp, &p->vProp);
255 }
256 }
257
258 return E_INVALIDARG;
259}
260
261static const IDxDiagContainerVtbl DxDiagContainer_Vtbl =
262{
272};
273
274
277
278 TRACE("(%s, %p)\n", debugstr_guid(riid), ppobj);
279
281 if (NULL == container) {
282 *ppobj = NULL;
283 return E_OUTOFMEMORY;
284 }
285 container->IDxDiagContainer_iface.lpVtbl = &DxDiagContainer_Vtbl;
286 container->ref = 0; /* will be inited with QueryInterface */
287 container->cont = cont;
288 container->pProv = pProv;
290 return IDxDiagContainerImpl_QueryInterface(&container->IDxDiagContainer_iface, riid, ppobj);
291}
#define InterlockedIncrement
Definition: armddk.h:53
#define InterlockedDecrement
Definition: armddk.h:52
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
static int list_empty(struct list_entry *head)
Definition: list.h:58
#define WARN(fmt,...)
Definition: precomp.h:61
const GUID IID_IUnknown
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
static HRESULT WINAPI IDxDiagContainerImpl_QueryInterface(IDxDiagContainer *iface, REFIID riid, void **ppobj)
Definition: container.c:35
static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfProps(IDxDiagContainer *iface, DWORD *pdwCount)
Definition: container.c:197
static const IDxDiagContainerVtbl DxDiagContainer_Vtbl
Definition: container.c:261
static ULONG WINAPI IDxDiagContainerImpl_AddRef(IDxDiagContainer *iface)
Definition: container.c:54
static HRESULT WINAPI IDxDiagContainerImpl_GetChildContainer(IDxDiagContainer *iface, LPCWSTR pwszContainer, IDxDiagContainer **ppInstance)
Definition: container.c:140
static IDxDiagContainerImpl * impl_from_IDxDiagContainer(IDxDiagContainer *iface)
Definition: container.c:29
static HRESULT WINAPI IDxDiagContainerImpl_GetProp(IDxDiagContainer *iface, LPCWSTR pwszPropName, VARIANT *pvarProp)
Definition: container.c:238
static ULONG WINAPI IDxDiagContainerImpl_Release(IDxDiagContainer *iface)
Definition: container.c:66
HRESULT DXDiag_CreateDXDiagContainer(REFIID riid, IDxDiagContainerImpl_Container *cont, IDxDiagProvider *pProv, LPVOID *ppobj)
Definition: container.c:275
static HRESULT WINAPI IDxDiagContainerImpl_EnumChildContainerNames(IDxDiagContainer *iface, DWORD dwIndex, LPWSTR pwszContainer, DWORD cchContainer)
Definition: container.c:97
static HRESULT IDxDiagContainerImpl_GetChildContainerInternal(IDxDiagContainerImpl_Container *cont, LPCWSTR pwszContainer, IDxDiagContainerImpl_Container **subcont)
Definition: container.c:126
static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfChildContainers(IDxDiagContainer *iface, DWORD *pdwCount)
Definition: container.c:84
static HRESULT WINAPI IDxDiagContainerImpl_EnumPropNames(IDxDiagContainer *iface, DWORD dwIndex, LPWSTR pwszPropName, DWORD cchPropName)
Definition: container.c:210
#define wcschr
Definition: compat.h:17
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define lstrcpynW
Definition: compat.h:738
#define lstrlenW
Definition: compat.h:750
int WINAPI lstrcmpW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4152
static void DXDIAGN_UnlockModule(void)
static void DXDIAGN_LockModule(void)
#define IDxDiagProvider_Release(p)
Definition: dxdiag.h:61
#define IDxDiagProvider_AddRef(p)
Definition: dxdiag.h:60
#define DXDIAG_E_INSUFFICIENT_BUFFER
Definition: dxdiag.h:57
unsigned long DWORD
Definition: ntddk_ex.h:95
FxCollectionEntry * cur
GLfloat GLfloat p
Definition: glext.h:8902
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
REFIID riid
Definition: atlbase.h:39
#define S_OK
Definition: intsafe.h:52
#define SUCCEEDED(hr)
Definition: intsafe.h:50
#define FAILED(hr)
Definition: intsafe.h:51
uint32_t entry
Definition: isohybrid.c:63
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_w
Definition: kernel32.h:32
short WCHAR
Definition: pedump.c:58
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
#define REFIID
Definition: guiddef.h:118
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:236
#define TRACE(s)
Definition: solgame.cpp:4
const uint16_t * LPCWSTR
Definition: typedefs.h:57
uint16_t * LPWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
uint32_t ULONG
Definition: typedefs.h:59
HRESULT WINAPI VariantCopy(VARIANTARG *pvargDest, const VARIANTARG *pvargSrc)
Definition: variant.c:724
void WINAPI VariantInit(VARIANTARG *pVarg)
Definition: variant.c:547
wchar_t tm const _CrtWcstime_Writes_and_advances_ptr_ count wchar_t ** out
Definition: wcsftime.cpp:383
#define WINAPI
Definition: msvc.h:6
#define E_NOINTERFACE
Definition: winerror.h:3479