Properly implement DllCanUnloadNow ref counting.
[wine/multimedia.git] / dlls / dxdiagn / provider.c
blob9f586e7bd436deae318153c69d0824f8a2ff401f
1 /*
2 * IDxDiagProvider 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
23 #include "dxdiag_private.h"
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
28 /* IDxDiagProvider IUnknown parts follow: */
29 HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
31 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
33 if (IsEqualGUID(riid, &IID_IUnknown)
34 || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
35 IDxDiagProviderImpl_AddRef(iface);
36 *ppobj = This;
37 return S_OK;
40 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
41 return E_NOINTERFACE;
44 ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
45 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
46 ULONG refCount = InterlockedIncrement(&This->ref);
48 TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
50 DXDIAGN_LockModule();
52 return refCount;
55 ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
56 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
57 ULONG refCount = InterlockedDecrement(&This->ref);
59 TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
61 if (!refCount) {
62 HeapFree(GetProcessHeap(), 0, This);
65 DXDIAGN_UnlockModule();
67 return refCount;
70 /* IDxDiagProvider Interface follow: */
71 HRESULT WINAPI IDxDiagProviderImpl_Initialize(PDXDIAGPROVIDER iface, DXDIAG_INIT_PARAMS* pParams) {
72 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
73 TRACE("(%p,%p)\n", iface, pParams);
75 if (NULL == pParams) {
76 return E_POINTER;
78 if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS)) {
79 return E_INVALIDARG;
82 This->init = TRUE;
83 memcpy(&This->params, pParams, pParams->dwSize);
84 return S_OK;
87 HRESULT WINAPI IDxDiagProviderImpl_GetRootContainer(PDXDIAGPROVIDER iface, IDxDiagContainer** ppInstance) {
88 HRESULT hr = S_OK;
89 IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
90 TRACE("(%p,%p)\n", iface, ppInstance);
92 if (NULL == ppInstance) {
93 return E_INVALIDARG;
95 if (FALSE == This->init) {
96 return E_INVALIDARG; /* should be E_CO_UNINITIALIZED */
98 if (NULL == This->pRootContainer) {
99 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &This->pRootContainer);
100 if (FAILED(hr)) {
101 return hr;
103 hr = DXDiag_InitRootDXDiagContainer((PDXDIAGCONTAINER)This->pRootContainer);
105 return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)This->pRootContainer, &IID_IDxDiagContainer, (void**) ppInstance);
108 IDxDiagProviderVtbl DxDiagProvider_Vtbl =
110 IDxDiagProviderImpl_QueryInterface,
111 IDxDiagProviderImpl_AddRef,
112 IDxDiagProviderImpl_Release,
113 IDxDiagProviderImpl_Initialize,
114 IDxDiagProviderImpl_GetRootContainer
117 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
118 IDxDiagProviderImpl* provider;
120 TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
122 provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
123 if (NULL == provider) {
124 *ppobj = NULL;
125 return E_OUTOFMEMORY;
127 provider->lpVtbl = &DxDiagProvider_Vtbl;
128 provider->ref = 0; /* will be inited with QueryInterface */
129 return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
132 HRESULT DXDiag_InitRootDXDiagContainer(IDxDiagContainer* pRootCont) {
133 static const WCHAR DxDiag_SystemInfo[] = {'D','x','D','i','a','g','_','S','y','s','t','e','m','I','n','f','o',0};
134 static const WCHAR dwDirectXVersionMajor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','a','j','o','r',0};
135 static const WCHAR dwDirectXVersionMinor[] = {'d','w','D','i','r','e','c','t','X','V','e','r','s','i','o','n','M','i','n','o','r',0};
136 static const WCHAR szDirectXVersionLetter[] = {'s','z','D','i','r','e','c','t','X','V','e','r','s','i','o','n','L','e','t','t','e','r',0};
137 static const WCHAR szDirectXVersionLetter_v[] = {'c',0};
139 IDxDiagContainer* pSubCont = NULL;
140 VARIANT v;
141 HRESULT hr = S_OK;
143 TRACE("(%p)\n", pRootCont);
145 hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
146 if (FAILED(hr)) {
147 return hr;
149 V_VT(&v) = VT_UI4; V_UI4(&v) = 9;
150 hr = IDxDiagContainerImpl_AddProp(pSubCont, dwDirectXVersionMajor, &v);
151 V_VT(&v) = VT_UI4; V_UI4(&v) = 0;
152 hr = IDxDiagContainerImpl_AddProp(pSubCont, dwDirectXVersionMinor, &v);
153 V_VT(&v) = VT_BSTR; V_BSTR(&v) = SysAllocString(szDirectXVersionLetter_v);
154 hr = IDxDiagContainerImpl_AddProp(pSubCont, szDirectXVersionLetter, &v);
156 hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemInfo, pSubCont);
157 return hr;