2 * IDxDiagContainer Implementation
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
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 (IsEqualGUID(riid
, &IID_IUnknown
)
37 || IsEqualGUID(riid
, &IID_IDxDiagContainer
)) {
38 IUnknown_AddRef(iface
);
43 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
47 static ULONG WINAPI
IDxDiagContainerImpl_AddRef(PDXDIAGCONTAINER iface
) {
48 IDxDiagContainerImpl
*This
= (IDxDiagContainerImpl
*)iface
;
49 ULONG refCount
= InterlockedIncrement(&This
->ref
);
51 TRACE("(%p)->(ref before=%u)\n", This
, refCount
- 1);
58 static ULONG WINAPI
IDxDiagContainerImpl_Release(PDXDIAGCONTAINER iface
) {
59 IDxDiagContainerImpl
*This
= (IDxDiagContainerImpl
*)iface
;
60 ULONG refCount
= InterlockedDecrement(&This
->ref
);
62 TRACE("(%p)->(ref before=%u)\n", This
, refCount
+ 1);
65 HeapFree(GetProcessHeap(), 0, This
);
68 DXDIAGN_UnlockModule();
73 /* IDxDiagContainer Interface follow: */
74 static HRESULT WINAPI
IDxDiagContainerImpl_GetNumberOfChildContainers(PDXDIAGCONTAINER iface
, DWORD
* pdwCount
) {
75 IDxDiagContainerImpl
*This
= (IDxDiagContainerImpl
*)iface
;
76 TRACE("(%p)\n", iface
);
77 if (NULL
== pdwCount
) {
80 *pdwCount
= This
->nSubContainers
;
84 static HRESULT WINAPI
IDxDiagContainerImpl_EnumChildContainerNames(PDXDIAGCONTAINER iface
, DWORD dwIndex
, LPWSTR pwszContainer
, DWORD cchContainer
) {
85 IDxDiagContainerImpl
*This
= (IDxDiagContainerImpl
*)iface
;
86 IDxDiagContainerImpl_SubContainer
* p
= NULL
;
89 TRACE("(%p, %u, %s, %u)\n", iface
, dwIndex
, debugstr_w(pwszContainer
), cchContainer
);
91 if (NULL
== pwszContainer
) {
94 if (256 > cchContainer
) {
95 return DXDIAG_E_INSUFFICIENT_BUFFER
;
98 p
= This
->subContainers
;
101 if (cchContainer
<= strlenW(p
->contName
)) {
102 return DXDIAG_E_INSUFFICIENT_BUFFER
;
104 lstrcpynW(pwszContainer
, p
->contName
, cchContainer
);
113 static HRESULT WINAPI
IDxDiagContainerImpl_GetChildContainerInternal(PDXDIAGCONTAINER iface
, LPCWSTR pwszContainer
, IDxDiagContainer
** ppInstance
) {
114 IDxDiagContainerImpl
*This
= (IDxDiagContainerImpl
*)iface
;
115 IDxDiagContainerImpl_SubContainer
* p
= NULL
;
117 p
= This
->subContainers
;
119 if (0 == lstrcmpW(p
->contName
, pwszContainer
)) {
120 *ppInstance
= (PDXDIAGCONTAINER
)p
->pCont
;
128 static HRESULT WINAPI
IDxDiagContainerImpl_GetChildContainer(PDXDIAGCONTAINER iface
, LPCWSTR pwszContainer
, IDxDiagContainer
** ppInstance
) {
129 IDxDiagContainerImpl
*This
= (IDxDiagContainerImpl
*)iface
;
130 IDxDiagContainer
* pContainer
= NULL
;
131 LPWSTR tmp
, orig_tmp
;
134 HRESULT hr
= E_INVALIDARG
;
136 FIXME("(%p, %s, %p)\n", iface
, debugstr_w(pwszContainer
), ppInstance
);
138 if (NULL
== ppInstance
|| NULL
== pwszContainer
) {
142 pContainer
= (PDXDIAGCONTAINER
) This
;
144 tmp_len
= strlenW(pwszContainer
) + 1;
145 orig_tmp
= tmp
= HeapAlloc(GetProcessHeap(), 0, tmp_len
* sizeof(WCHAR
));
146 if (NULL
== tmp
) return E_FAIL
;
147 lstrcpynW(tmp
, pwszContainer
, tmp_len
);
149 cur
= strchrW(tmp
, '.');
150 while (NULL
!= cur
) {
151 *cur
= '\0'; /* cut tmp string to '.' */
152 hr
= IDxDiagContainerImpl_GetChildContainerInternal(pContainer
, tmp
, &pContainer
);
153 if (!SUCCEEDED(hr
) || NULL
== pContainer
)
155 cur
++; /* go after '.' (just replaced by \0) */
157 cur
= strchrW(tmp
, '.');
160 hr
= IDxDiagContainerImpl_GetChildContainerInternal(pContainer
, tmp
, ppInstance
);
162 IDxDiagContainerImpl_AddRef((PDXDIAGCONTAINER
)*ppInstance
);
166 HeapFree(GetProcessHeap(), 0, orig_tmp
);
170 static HRESULT WINAPI
IDxDiagContainerImpl_GetNumberOfProps(PDXDIAGCONTAINER iface
, DWORD
* pdwCount
) {
171 IDxDiagContainerImpl
*This
= (IDxDiagContainerImpl
*)iface
;
172 TRACE("(%p)\n", iface
);
173 if (NULL
== pdwCount
) {
176 *pdwCount
= This
->nProperties
;
180 static HRESULT WINAPI
IDxDiagContainerImpl_EnumPropNames(PDXDIAGCONTAINER iface
, DWORD dwIndex
, LPWSTR pwszPropName
, DWORD cchPropName
) {
181 IDxDiagContainerImpl
*This
= (IDxDiagContainerImpl
*)iface
;
182 IDxDiagContainerImpl_Property
* p
= NULL
;
185 FIXME("(%p, %u, %s, %u)\n", iface
, dwIndex
, debugstr_w(pwszPropName
), cchPropName
);
187 if (NULL
== pwszPropName
) {
190 if (256 > cchPropName
) {
191 return DXDIAG_E_INSUFFICIENT_BUFFER
;
194 p
= This
->properties
;
197 if (cchPropName
<= lstrlenW(p
->vName
)) {
198 return DXDIAG_E_INSUFFICIENT_BUFFER
;
200 lstrcpynW(pwszPropName
, p
->vName
, cchPropName
);
209 static HRESULT WINAPI
IDxDiagContainerImpl_GetProp(PDXDIAGCONTAINER iface
, LPCWSTR pwszPropName
, VARIANT
* pvarProp
) {
210 IDxDiagContainerImpl
*This
= (IDxDiagContainerImpl
*)iface
;
211 IDxDiagContainerImpl_Property
* p
= NULL
;
212 FIXME("(%p, %s, %p)\n", iface
, debugstr_w(pwszPropName
), pvarProp
);
214 if (NULL
== pvarProp
|| NULL
== pwszPropName
) {
218 p
= This
->properties
;
220 if (0 == lstrcmpW(p
->vName
, pwszPropName
)) {
221 VariantCopy(pvarProp
, &p
->v
);
229 HRESULT WINAPI
IDxDiagContainerImpl_AddProp(PDXDIAGCONTAINER iface
, LPCWSTR pwszPropName
, VARIANT
* pVarProp
) {
230 IDxDiagContainerImpl
*This
= (IDxDiagContainerImpl
*)iface
;
231 IDxDiagContainerImpl_Property
* p
= NULL
;
232 IDxDiagContainerImpl_Property
* pNew
= NULL
;
234 FIXME("(%p, %s, %p)\n", iface
, debugstr_w(pwszPropName
), pVarProp
);
236 if (NULL
== pVarProp
|| NULL
== pwszPropName
) {
240 pNew
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDxDiagContainerImpl_Property
));
242 return E_OUTOFMEMORY
;
244 VariantInit(&pNew
->v
);
245 VariantCopy(&pNew
->v
, pVarProp
);
246 pNew
->vName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (lstrlenW(pwszPropName
) + 1) * sizeof(WCHAR
));
247 lstrcpyW(pNew
->vName
, pwszPropName
);
250 p
= This
->properties
;
252 This
->properties
= pNew
;
254 while (NULL
!= p
->next
) {
263 HRESULT WINAPI
IDxDiagContainerImpl_AddChildContainer(PDXDIAGCONTAINER iface
, LPCWSTR pszContName
, PDXDIAGCONTAINER pSubCont
) {
264 IDxDiagContainerImpl
*This
= (IDxDiagContainerImpl
*)iface
;
265 IDxDiagContainerImpl_SubContainer
* p
= NULL
;
266 IDxDiagContainerImpl_SubContainer
* pNew
= NULL
;
268 FIXME("(%p, %s, %p)\n", iface
, debugstr_w(pszContName
), pSubCont
);
270 if (NULL
== pSubCont
|| NULL
== pszContName
) {
274 pNew
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDxDiagContainerImpl_SubContainer
));
276 return E_OUTOFMEMORY
;
278 pNew
->pCont
= pSubCont
;
279 pNew
->contName
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, (lstrlenW(pszContName
) + 1) * sizeof(WCHAR
));
280 lstrcpyW(pNew
->contName
, pszContName
);
283 p
= This
->subContainers
;
285 This
->subContainers
= pNew
;
287 while (NULL
!= p
->next
) {
292 ++This
->nSubContainers
;
296 static const IDxDiagContainerVtbl DxDiagContainer_Vtbl
=
298 IDxDiagContainerImpl_QueryInterface
,
299 IDxDiagContainerImpl_AddRef
,
300 IDxDiagContainerImpl_Release
,
301 IDxDiagContainerImpl_GetNumberOfChildContainers
,
302 IDxDiagContainerImpl_EnumChildContainerNames
,
303 IDxDiagContainerImpl_GetChildContainer
,
304 IDxDiagContainerImpl_GetNumberOfProps
,
305 IDxDiagContainerImpl_EnumPropNames
,
306 IDxDiagContainerImpl_GetProp
310 HRESULT
DXDiag_CreateDXDiagContainer(REFIID riid
, LPVOID
*ppobj
) {
311 IDxDiagContainerImpl
* container
;
313 TRACE("(%p, %p)\n", debugstr_guid(riid
), ppobj
);
315 container
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(IDxDiagContainerImpl
));
316 if (NULL
== container
) {
318 return E_OUTOFMEMORY
;
320 container
->lpVtbl
= &DxDiagContainer_Vtbl
;
321 container
->ref
= 0; /* will be inited with QueryInterface */
322 return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER
)container
, riid
, ppobj
);