msi: Include run mode in fixmes.
[wine.git] / dlls / dxdiagn / container.c
blobe02d1d13cf37611be30a101d2f39c51a56ee9aa2
1 /*
2 * IDxDiagContainer Implementation
3 *
4 * Copyright 2004 Raphael Junqueira
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.
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.
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
22 #include "config.h"
24 #define COBJMACROS
25 #include "dxdiag_private.h"
26 #include "wine/debug.h"
27 #include "wine/unicode.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
31 /* IDxDiagContainer IUnknown parts follow: */
32 HRESULT WINAPI IDxDiagContainerImpl_QueryInterface(PDXDIAGCONTAINER iface, REFIID riid, LPVOID *ppobj)
34 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
36 if (!ppobj) return E_INVALIDARG;
38 if (IsEqualGUID(riid, &IID_IUnknown)
39 || IsEqualGUID(riid, &IID_IDxDiagContainer)) {
40 IUnknown_AddRef(iface);
41 *ppobj = This;
42 return S_OK;
45 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
46 *ppobj = NULL;
47 return E_NOINTERFACE;
50 static ULONG WINAPI IDxDiagContainerImpl_AddRef(PDXDIAGCONTAINER iface) {
51 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
52 ULONG refCount = InterlockedIncrement(&This->ref);
54 TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
56 DXDIAGN_LockModule();
58 return refCount;
61 static ULONG WINAPI IDxDiagContainerImpl_Release(PDXDIAGCONTAINER iface) {
62 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
63 ULONG refCount = InterlockedDecrement(&This->ref);
65 TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
67 if (!refCount) {
68 HeapFree(GetProcessHeap(), 0, This);
71 DXDIAGN_UnlockModule();
73 return refCount;
76 /* IDxDiagContainer Interface follow: */
77 static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfChildContainers(PDXDIAGCONTAINER iface, DWORD* pdwCount) {
78 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
79 TRACE("(%p)\n", iface);
80 if (NULL == pdwCount) {
81 return E_INVALIDARG;
83 *pdwCount = This->nSubContainers;
84 return S_OK;
87 static HRESULT WINAPI IDxDiagContainerImpl_EnumChildContainerNames(PDXDIAGCONTAINER iface, DWORD dwIndex, LPWSTR pwszContainer, DWORD cchContainer) {
88 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
89 IDxDiagContainerImpl_SubContainer* p = NULL;
90 DWORD i = 0;
92 TRACE("(%p, %u, %s, %u)\n", iface, dwIndex, debugstr_w(pwszContainer), cchContainer);
94 if (NULL == pwszContainer) {
95 return E_INVALIDARG;
97 if (256 > cchContainer) {
98 return DXDIAG_E_INSUFFICIENT_BUFFER;
101 p = This->subContainers;
102 while (NULL != p) {
103 if (dwIndex == i) {
104 if (cchContainer <= strlenW(p->contName)) {
105 return DXDIAG_E_INSUFFICIENT_BUFFER;
107 lstrcpynW(pwszContainer, p->contName, cchContainer);
108 return S_OK;
110 p = p->next;
111 ++i;
113 return E_INVALIDARG;
116 static HRESULT IDxDiagContainerImpl_GetChildContainerInternal(PDXDIAGCONTAINER iface, LPCWSTR pwszContainer, IDxDiagContainer** ppInstance) {
117 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
118 IDxDiagContainerImpl_SubContainer* p = NULL;
120 p = This->subContainers;
121 while (NULL != p) {
122 if (0 == lstrcmpW(p->contName, pwszContainer)) {
123 *ppInstance = p->pCont;
124 return S_OK;
126 p = p->next;
128 return E_INVALIDARG;
131 static HRESULT WINAPI IDxDiagContainerImpl_GetChildContainer(PDXDIAGCONTAINER iface, LPCWSTR pwszContainer, IDxDiagContainer** ppInstance) {
132 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
133 IDxDiagContainer* pContainer = NULL;
134 LPWSTR tmp, orig_tmp;
135 INT tmp_len;
136 WCHAR* cur;
137 HRESULT hr = E_INVALIDARG;
139 TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszContainer), ppInstance);
141 if (NULL == ppInstance || NULL == pwszContainer) {
142 return E_INVALIDARG;
145 pContainer = (PDXDIAGCONTAINER) This;
147 tmp_len = strlenW(pwszContainer) + 1;
148 orig_tmp = tmp = HeapAlloc(GetProcessHeap(), 0, tmp_len * sizeof(WCHAR));
149 if (NULL == tmp) return E_FAIL;
150 lstrcpynW(tmp, pwszContainer, tmp_len);
152 cur = strchrW(tmp, '.');
153 while (NULL != cur) {
154 *cur = '\0'; /* cut tmp string to '.' */
155 hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, &pContainer);
156 if (FAILED(hr) || NULL == pContainer)
157 goto on_error;
158 cur++; /* go after '.' (just replaced by \0) */
159 tmp = cur;
160 cur = strchrW(tmp, '.');
163 hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, ppInstance);
164 if (SUCCEEDED(hr)) {
165 IDxDiagContainerImpl_AddRef(*ppInstance);
168 on_error:
169 HeapFree(GetProcessHeap(), 0, orig_tmp);
170 return hr;
173 static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfProps(PDXDIAGCONTAINER iface, DWORD* pdwCount) {
174 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
175 TRACE("(%p)\n", iface);
176 if (NULL == pdwCount) {
177 return E_INVALIDARG;
179 *pdwCount = This->nProperties;
180 return S_OK;
183 static HRESULT WINAPI IDxDiagContainerImpl_EnumPropNames(PDXDIAGCONTAINER iface, DWORD dwIndex, LPWSTR pwszPropName, DWORD cchPropName) {
184 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
185 IDxDiagContainerImpl_Property* p = NULL;
186 DWORD i = 0;
188 TRACE("(%p, %u, %s, %u)\n", iface, dwIndex, debugstr_w(pwszPropName), cchPropName);
190 if (NULL == pwszPropName) {
191 return E_INVALIDARG;
193 if (256 > cchPropName) {
194 return DXDIAG_E_INSUFFICIENT_BUFFER;
197 p = This->properties;
198 while (NULL != p) {
199 if (dwIndex == i) {
200 if (cchPropName <= strlenW(p->vName)) {
201 return DXDIAG_E_INSUFFICIENT_BUFFER;
203 lstrcpynW(pwszPropName, p->vName, cchPropName);
204 return S_OK;
206 p = p->next;
207 ++i;
209 return E_INVALIDARG;
212 static HRESULT WINAPI IDxDiagContainerImpl_GetProp(PDXDIAGCONTAINER iface, LPCWSTR pwszPropName, VARIANT* pvarProp) {
213 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
214 IDxDiagContainerImpl_Property* p = NULL;
216 TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszPropName), pvarProp);
218 if (NULL == pvarProp || NULL == pwszPropName) {
219 return E_INVALIDARG;
222 p = This->properties;
223 while (NULL != p) {
224 if (0 == lstrcmpW(p->vName, pwszPropName)) {
225 VariantCopy(pvarProp, &p->v);
226 return S_OK;
228 p = p->next;
230 return S_OK;
233 HRESULT WINAPI IDxDiagContainerImpl_AddProp(PDXDIAGCONTAINER iface, LPCWSTR pwszPropName, VARIANT* pVarProp) {
234 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
235 IDxDiagContainerImpl_Property* p = NULL;
236 IDxDiagContainerImpl_Property* pNew = NULL;
238 TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszPropName), pVarProp);
240 if (NULL == pVarProp || NULL == pwszPropName) {
241 return E_INVALIDARG;
244 pNew = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagContainerImpl_Property));
245 if (NULL == pNew) {
246 return E_OUTOFMEMORY;
248 VariantInit(&pNew->v);
249 VariantCopy(&pNew->v, pVarProp);
250 pNew->vName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pwszPropName) + 1) * sizeof(WCHAR));
251 lstrcpyW(pNew->vName, pwszPropName);
252 pNew->next = NULL;
254 p = This->properties;
255 if (NULL == p) {
256 This->properties = pNew;
257 } else {
258 while (NULL != p->next) {
259 p = p->next;
261 p->next = pNew;
263 ++This->nProperties;
264 return S_OK;
267 HRESULT WINAPI IDxDiagContainerImpl_AddChildContainer(PDXDIAGCONTAINER iface, LPCWSTR pszContName, PDXDIAGCONTAINER pSubCont) {
268 IDxDiagContainerImpl *This = (IDxDiagContainerImpl *)iface;
269 IDxDiagContainerImpl_SubContainer* p = NULL;
270 IDxDiagContainerImpl_SubContainer* pNew = NULL;
272 TRACE("(%p, %s, %p)\n", iface, debugstr_w(pszContName), pSubCont);
274 if (NULL == pSubCont || NULL == pszContName) {
275 return E_INVALIDARG;
278 pNew = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagContainerImpl_SubContainer));
279 if (NULL == pNew) {
280 return E_OUTOFMEMORY;
282 pNew->pCont = pSubCont;
283 pNew->contName = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pszContName) + 1) * sizeof(WCHAR));
284 lstrcpyW(pNew->contName, pszContName);
285 pNew->next = NULL;
287 p = This->subContainers;
288 if (NULL == p) {
289 This->subContainers = pNew;
290 } else {
291 while (NULL != p->next) {
292 p = p->next;
294 p->next = pNew;
296 ++This->nSubContainers;
297 return S_OK;
300 static const IDxDiagContainerVtbl DxDiagContainer_Vtbl =
302 IDxDiagContainerImpl_QueryInterface,
303 IDxDiagContainerImpl_AddRef,
304 IDxDiagContainerImpl_Release,
305 IDxDiagContainerImpl_GetNumberOfChildContainers,
306 IDxDiagContainerImpl_EnumChildContainerNames,
307 IDxDiagContainerImpl_GetChildContainer,
308 IDxDiagContainerImpl_GetNumberOfProps,
309 IDxDiagContainerImpl_EnumPropNames,
310 IDxDiagContainerImpl_GetProp
314 HRESULT DXDiag_CreateDXDiagContainer(REFIID riid, LPVOID *ppobj) {
315 IDxDiagContainerImpl* container;
317 TRACE("(%p, %p)\n", debugstr_guid(riid), ppobj);
319 container = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagContainerImpl));
320 if (NULL == container) {
321 *ppobj = NULL;
322 return E_OUTOFMEMORY;
324 container->lpVtbl = &DxDiagContainer_Vtbl;
325 container->ref = 0; /* will be inited with QueryInterface */
326 return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)container, riid, ppobj);