2004-04-19 04:57:09 +02:00
|
|
|
/*
|
|
|
|
* IDxDiagContainer Implementation
|
|
|
|
*
|
|
|
|
* Copyright 2004 Raphael Junqueira
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-04-19 04:57:09 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2006-06-10 11:58:14 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
2004-04-19 04:57:09 +02:00
|
|
|
#include "dxdiag_private.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
|
|
|
|
|
2011-08-10 23:59:30 +02:00
|
|
|
static inline IDxDiagContainerImpl *impl_from_IDxDiagContainer(IDxDiagContainer *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, IDxDiagContainerImpl, IDxDiagContainer_iface);
|
|
|
|
}
|
|
|
|
|
2004-04-19 04:57:09 +02:00
|
|
|
/* IDxDiagContainer IUnknown parts follow: */
|
2011-08-10 23:59:30 +02:00
|
|
|
static HRESULT WINAPI IDxDiagContainerImpl_QueryInterface(IDxDiagContainer *iface, REFIID riid,
|
|
|
|
void **ppobj)
|
2004-04-19 04:57:09 +02:00
|
|
|
{
|
2011-08-10 23:59:30 +02:00
|
|
|
IDxDiagContainerImpl *This = impl_from_IDxDiagContainer(iface);
|
2004-04-19 04:57:09 +02:00
|
|
|
|
2009-12-22 11:14:56 +01:00
|
|
|
if (!ppobj) return E_INVALIDARG;
|
|
|
|
|
2004-04-19 04:57:09 +02:00
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDxDiagContainer)) {
|
2006-06-10 11:58:14 +02:00
|
|
|
IUnknown_AddRef(iface);
|
2004-04-19 04:57:09 +02:00
|
|
|
*ppobj = This;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
|
2009-12-22 11:14:56 +01:00
|
|
|
*ppobj = NULL;
|
2004-04-19 04:57:09 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2011-08-10 23:59:30 +02:00
|
|
|
static ULONG WINAPI IDxDiagContainerImpl_AddRef(IDxDiagContainer *iface)
|
|
|
|
{
|
|
|
|
IDxDiagContainerImpl *This = impl_from_IDxDiagContainer(iface);
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-06 23:01:04 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n", This, refCount - 1);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
2005-02-01 15:21:37 +01:00
|
|
|
DXDIAGN_LockModule();
|
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2004-04-19 04:57:09 +02:00
|
|
|
}
|
|
|
|
|
2011-08-10 23:59:30 +02:00
|
|
|
static ULONG WINAPI IDxDiagContainerImpl_Release(IDxDiagContainer *iface)
|
|
|
|
{
|
|
|
|
IDxDiagContainerImpl *This = impl_from_IDxDiagContainer(iface);
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-06 23:01:04 +02:00
|
|
|
TRACE("(%p)->(ref before=%u)\n", This, refCount + 1);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
|
|
|
if (!refCount) {
|
2011-02-15 08:13:22 +01:00
|
|
|
IDxDiagProvider_Release(This->pProv);
|
2004-04-19 04:57:09 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
2005-02-01 15:21:37 +01:00
|
|
|
|
|
|
|
DXDIAGN_UnlockModule();
|
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2004-04-19 04:57:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IDxDiagContainer Interface follow: */
|
2011-08-10 23:59:30 +02:00
|
|
|
static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfChildContainers(IDxDiagContainer *iface,
|
|
|
|
DWORD *pdwCount)
|
|
|
|
{
|
|
|
|
IDxDiagContainerImpl *This = impl_from_IDxDiagContainer(iface);
|
|
|
|
|
2004-04-19 04:57:09 +02:00
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
if (NULL == pdwCount) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2011-02-15 08:17:16 +01:00
|
|
|
*pdwCount = This->cont->nSubContainers;
|
2004-04-19 04:57:09 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-10 23:59:30 +02:00
|
|
|
static HRESULT WINAPI IDxDiagContainerImpl_EnumChildContainerNames(IDxDiagContainer *iface,
|
|
|
|
DWORD dwIndex, LPWSTR pwszContainer, DWORD cchContainer)
|
|
|
|
{
|
|
|
|
IDxDiagContainerImpl *This = impl_from_IDxDiagContainer(iface);
|
2011-02-15 08:17:16 +01:00
|
|
|
IDxDiagContainerImpl_Container *p;
|
2004-04-19 04:57:09 +02:00
|
|
|
DWORD i = 0;
|
|
|
|
|
2010-03-14 18:03:58 +01:00
|
|
|
TRACE("(%p, %u, %p, %u)\n", iface, dwIndex, pwszContainer, cchContainer);
|
|
|
|
|
|
|
|
if (NULL == pwszContainer || 0 == cchContainer) {
|
2004-04-19 04:57:09 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2010-03-14 18:03:58 +01:00
|
|
|
|
2011-02-15 08:17:16 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(p, &This->cont->subContainers, IDxDiagContainerImpl_Container, entry)
|
2011-02-01 11:32:05 +01:00
|
|
|
{
|
2010-03-14 23:36:30 +01:00
|
|
|
if (dwIndex == i) {
|
|
|
|
TRACE("Found container name %s, copying string\n", debugstr_w(p->contName));
|
2004-04-19 04:57:09 +02:00
|
|
|
lstrcpynW(pwszContainer, p->contName, cchContainer);
|
2019-06-04 09:05:32 +02:00
|
|
|
return (cchContainer <= lstrlenW(p->contName)) ?
|
2010-03-14 23:36:30 +01:00
|
|
|
DXDIAG_E_INSUFFICIENT_BUFFER : S_OK;
|
2004-04-19 04:57:09 +02:00
|
|
|
}
|
|
|
|
++i;
|
2010-03-14 18:03:58 +01:00
|
|
|
}
|
|
|
|
|
2010-03-14 23:36:30 +01:00
|
|
|
TRACE("Failed to find container name at specified index\n");
|
2010-03-14 18:03:58 +01:00
|
|
|
*pwszContainer = '\0';
|
2004-04-19 04:57:09 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2011-02-15 08:17:16 +01:00
|
|
|
static HRESULT IDxDiagContainerImpl_GetChildContainerInternal(IDxDiagContainerImpl_Container *cont, LPCWSTR pwszContainer, IDxDiagContainerImpl_Container **subcont) {
|
|
|
|
IDxDiagContainerImpl_Container *p;
|
2004-04-19 04:57:09 +02:00
|
|
|
|
2011-02-15 08:17:16 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(p, &cont->subContainers, IDxDiagContainerImpl_Container, entry)
|
2011-02-01 11:32:05 +01:00
|
|
|
{
|
2008-01-05 17:44:06 +01:00
|
|
|
if (0 == lstrcmpW(p->contName, pwszContainer)) {
|
2011-02-15 08:17:16 +01:00
|
|
|
*subcont = p;
|
2004-04-19 04:57:09 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
2011-02-01 11:32:05 +01:00
|
|
|
|
2004-04-19 04:57:09 +02:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2011-08-10 23:59:30 +02:00
|
|
|
static HRESULT WINAPI IDxDiagContainerImpl_GetChildContainer(IDxDiagContainer *iface,
|
|
|
|
LPCWSTR pwszContainer, IDxDiagContainer **ppInstance)
|
|
|
|
{
|
|
|
|
IDxDiagContainerImpl *This = impl_from_IDxDiagContainer(iface);
|
2011-02-15 08:17:16 +01:00
|
|
|
IDxDiagContainerImpl_Container *pContainer = This->cont;
|
2005-11-03 12:34:28 +01:00
|
|
|
LPWSTR tmp, orig_tmp;
|
|
|
|
INT tmp_len;
|
|
|
|
WCHAR* cur;
|
|
|
|
HRESULT hr = E_INVALIDARG;
|
|
|
|
|
2008-05-28 05:14:45 +02:00
|
|
|
TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszContainer), ppInstance);
|
2005-11-03 12:34:28 +01:00
|
|
|
|
|
|
|
if (NULL == ppInstance || NULL == pwszContainer) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2010-03-14 18:04:07 +01:00
|
|
|
*ppInstance = NULL;
|
2005-11-03 12:34:28 +01:00
|
|
|
|
2019-06-04 09:05:32 +02:00
|
|
|
tmp_len = lstrlenW(pwszContainer) + 1;
|
2005-11-03 12:34:28 +01:00
|
|
|
orig_tmp = tmp = HeapAlloc(GetProcessHeap(), 0, tmp_len * sizeof(WCHAR));
|
|
|
|
if (NULL == tmp) return E_FAIL;
|
|
|
|
lstrcpynW(tmp, pwszContainer, tmp_len);
|
|
|
|
|
2019-06-04 09:05:32 +02:00
|
|
|
cur = wcschr(tmp, '.');
|
2005-11-03 12:34:28 +01:00
|
|
|
while (NULL != cur) {
|
|
|
|
*cur = '\0'; /* cut tmp string to '.' */
|
2010-03-14 23:36:38 +01:00
|
|
|
if (!*(cur + 1)) break; /* Account for a lone terminating period, as in "cont1.cont2.". */
|
|
|
|
TRACE("Trying to get parent container %s\n", debugstr_w(tmp));
|
2005-11-03 12:34:28 +01:00
|
|
|
hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, &pContainer);
|
2011-02-15 08:17:16 +01:00
|
|
|
if (FAILED(hr))
|
2005-11-03 12:34:28 +01:00
|
|
|
goto on_error;
|
2006-03-02 18:03:32 +01:00
|
|
|
cur++; /* go after '.' (just replaced by \0) */
|
2005-11-03 12:34:28 +01:00
|
|
|
tmp = cur;
|
2019-06-04 09:05:32 +02:00
|
|
|
cur = wcschr(tmp, '.');
|
2005-11-03 12:34:28 +01:00
|
|
|
}
|
|
|
|
|
2010-03-14 23:36:38 +01:00
|
|
|
TRACE("Trying to get container %s\n", debugstr_w(tmp));
|
2011-02-15 08:17:16 +01:00
|
|
|
hr = IDxDiagContainerImpl_GetChildContainerInternal(pContainer, tmp, &pContainer);
|
2005-11-03 12:34:28 +01:00
|
|
|
if (SUCCEEDED(hr)) {
|
2011-02-15 08:17:16 +01:00
|
|
|
hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, pContainer, This->pProv, (void **)ppInstance);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
TRACE("Succeeded in getting the container instance\n");
|
2005-11-03 12:34:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
on_error:
|
|
|
|
HeapFree(GetProcessHeap(), 0, orig_tmp);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-08-10 23:59:30 +02:00
|
|
|
static HRESULT WINAPI IDxDiagContainerImpl_GetNumberOfProps(IDxDiagContainer *iface,
|
|
|
|
DWORD *pdwCount)
|
|
|
|
{
|
|
|
|
IDxDiagContainerImpl *This = impl_from_IDxDiagContainer(iface);
|
|
|
|
|
2005-01-27 11:42:00 +01:00
|
|
|
TRACE("(%p)\n", iface);
|
|
|
|
if (NULL == pdwCount) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2011-02-15 08:17:16 +01:00
|
|
|
*pdwCount = This->cont->nProperties;
|
2004-04-19 04:57:09 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-10 23:59:30 +02:00
|
|
|
static HRESULT WINAPI IDxDiagContainerImpl_EnumPropNames(IDxDiagContainer *iface, DWORD dwIndex,
|
|
|
|
LPWSTR pwszPropName, DWORD cchPropName)
|
|
|
|
{
|
|
|
|
IDxDiagContainerImpl *This = impl_from_IDxDiagContainer(iface);
|
2011-02-01 11:32:15 +01:00
|
|
|
IDxDiagContainerImpl_Property *p;
|
2005-01-27 11:42:00 +01:00
|
|
|
DWORD i = 0;
|
|
|
|
|
2010-03-14 18:04:20 +01:00
|
|
|
TRACE("(%p, %u, %p, %u)\n", iface, dwIndex, pwszPropName, cchPropName);
|
|
|
|
|
|
|
|
if (NULL == pwszPropName || 0 == cchPropName) {
|
2005-01-27 11:42:00 +01:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2010-03-14 18:04:20 +01:00
|
|
|
|
2011-02-15 08:17:16 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(p, &This->cont->properties, IDxDiagContainerImpl_Property, entry)
|
2011-02-01 11:32:15 +01:00
|
|
|
{
|
2010-03-14 23:36:53 +01:00
|
|
|
if (dwIndex == i) {
|
2011-02-01 11:32:15 +01:00
|
|
|
TRACE("Found property name %s, copying string\n", debugstr_w(p->propName));
|
|
|
|
lstrcpynW(pwszPropName, p->propName, cchPropName);
|
2019-06-04 09:05:32 +02:00
|
|
|
return (cchPropName <= lstrlenW(p->propName)) ?
|
2010-03-14 23:36:53 +01:00
|
|
|
DXDIAG_E_INSUFFICIENT_BUFFER : S_OK;
|
2005-01-27 11:42:00 +01:00
|
|
|
}
|
|
|
|
++i;
|
2010-03-14 18:04:20 +01:00
|
|
|
}
|
2011-02-01 11:32:15 +01:00
|
|
|
|
2010-03-14 23:36:53 +01:00
|
|
|
TRACE("Failed to find property name at specified index\n");
|
2005-01-27 11:42:00 +01:00
|
|
|
return E_INVALIDARG;
|
2004-04-19 04:57:09 +02:00
|
|
|
}
|
|
|
|
|
2011-08-10 23:59:30 +02:00
|
|
|
static HRESULT WINAPI IDxDiagContainerImpl_GetProp(IDxDiagContainer *iface, LPCWSTR pwszPropName,
|
|
|
|
VARIANT *pvarProp)
|
|
|
|
{
|
|
|
|
IDxDiagContainerImpl *This = impl_from_IDxDiagContainer(iface);
|
2011-02-01 11:32:15 +01:00
|
|
|
IDxDiagContainerImpl_Property *p;
|
2008-05-28 05:14:45 +02:00
|
|
|
|
|
|
|
TRACE("(%p, %s, %p)\n", iface, debugstr_w(pwszPropName), pvarProp);
|
2005-01-27 11:42:00 +01:00
|
|
|
|
|
|
|
if (NULL == pvarProp || NULL == pwszPropName) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2011-02-15 08:17:16 +01:00
|
|
|
LIST_FOR_EACH_ENTRY(p, &This->cont->properties, IDxDiagContainerImpl_Property, entry)
|
2011-02-01 11:32:15 +01:00
|
|
|
{
|
|
|
|
if (0 == lstrcmpW(p->propName, pwszPropName)) {
|
2011-06-15 14:10:32 +02:00
|
|
|
VariantInit(pvarProp);
|
2011-02-01 11:32:15 +01:00
|
|
|
return VariantCopy(pvarProp, &p->vProp);
|
2005-01-27 11:42:00 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-01 11:32:15 +01:00
|
|
|
|
2010-03-23 05:56:51 +01:00
|
|
|
return E_INVALIDARG;
|
2005-01-27 11:42:00 +01:00
|
|
|
}
|
|
|
|
|
2005-06-01 21:57:42 +02:00
|
|
|
static const IDxDiagContainerVtbl DxDiagContainer_Vtbl =
|
2004-04-19 04:57:09 +02:00
|
|
|
{
|
|
|
|
IDxDiagContainerImpl_QueryInterface,
|
|
|
|
IDxDiagContainerImpl_AddRef,
|
|
|
|
IDxDiagContainerImpl_Release,
|
|
|
|
IDxDiagContainerImpl_GetNumberOfChildContainers,
|
|
|
|
IDxDiagContainerImpl_EnumChildContainerNames,
|
|
|
|
IDxDiagContainerImpl_GetChildContainer,
|
|
|
|
IDxDiagContainerImpl_GetNumberOfProps,
|
|
|
|
IDxDiagContainerImpl_EnumPropNames,
|
|
|
|
IDxDiagContainerImpl_GetProp
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-02-15 08:17:16 +01:00
|
|
|
HRESULT DXDiag_CreateDXDiagContainer(REFIID riid, IDxDiagContainerImpl_Container *cont, IDxDiagProvider *pProv, LPVOID *ppobj) {
|
2004-04-19 04:57:09 +02:00
|
|
|
IDxDiagContainerImpl* container;
|
|
|
|
|
2012-03-21 23:35:13 +01:00
|
|
|
TRACE("(%s, %p)\n", debugstr_guid(riid), ppobj);
|
|
|
|
|
2011-02-15 08:17:16 +01:00
|
|
|
container = HeapAlloc(GetProcessHeap(), 0, sizeof(IDxDiagContainerImpl));
|
2004-04-19 04:57:09 +02:00
|
|
|
if (NULL == container) {
|
|
|
|
*ppobj = NULL;
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
2011-08-10 23:59:30 +02:00
|
|
|
container->IDxDiagContainer_iface.lpVtbl = &DxDiagContainer_Vtbl;
|
2004-04-19 04:57:09 +02:00
|
|
|
container->ref = 0; /* will be inited with QueryInterface */
|
2011-02-15 08:17:16 +01:00
|
|
|
container->cont = cont;
|
2011-02-15 08:13:22 +01:00
|
|
|
container->pProv = pProv;
|
|
|
|
IDxDiagProvider_AddRef(pProv);
|
2011-08-10 23:59:30 +02:00
|
|
|
return IDxDiagContainerImpl_QueryInterface(&container->IDxDiagContainer_iface, riid, ppobj);
|
2004-04-19 04:57:09 +02:00
|
|
|
}
|