Don't prefix the functions DllCanUnloadNow, DllGetClassObject and
[wine] / dlls / dxdiagn / provider.c
1 /* 
2  * IDxDiagProvider 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "config.h"
23 #include "dxdiag_private.h"
24 #include "wine/debug.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
27
28 /* IDxDiagProvider IUnknown parts follow: */
29 HRESULT WINAPI IDxDiagProviderImpl_QueryInterface(PDXDIAGPROVIDER iface, REFIID riid, LPVOID *ppobj)
30 {
31     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
32
33     if (IsEqualGUID(riid, &IID_IUnknown)
34         || IsEqualGUID(riid, &IID_IDxDiagProvider)) {
35         IDxDiagProviderImpl_AddRef(iface);
36         *ppobj = This;
37         return S_OK;
38     }
39
40     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
41     return E_NOINTERFACE;
42 }
43
44 ULONG WINAPI IDxDiagProviderImpl_AddRef(PDXDIAGPROVIDER iface) {
45     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
46     ULONG refCount = InterlockedIncrement(&This->ref);
47
48     TRACE("(%p)->(ref before=%lu)\n", This, refCount - 1);
49
50     DXDIAGN_LockModule();
51
52     return refCount;
53 }
54
55 ULONG WINAPI IDxDiagProviderImpl_Release(PDXDIAGPROVIDER iface) {
56     IDxDiagProviderImpl *This = (IDxDiagProviderImpl *)iface;
57     ULONG refCount = InterlockedDecrement(&This->ref);
58
59     TRACE("(%p)->(ref before=%lu)\n", This, refCount + 1);
60
61     if (!refCount) {
62         HeapFree(GetProcessHeap(), 0, This);
63     }
64
65     DXDIAGN_UnlockModule();
66     
67     return refCount;
68 }
69
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);
74
75     if (NULL == pParams) {
76       return E_POINTER;
77     }
78     if (pParams->dwSize != sizeof(DXDIAG_INIT_PARAMS)) {
79       return E_INVALIDARG;
80     }
81
82     This->init = TRUE;
83     memcpy(&This->params, pParams, pParams->dwSize);
84     return S_OK;
85 }
86
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);
91
92   if (NULL == ppInstance) {
93     return E_INVALIDARG;
94   }
95   if (FALSE == This->init) {
96     return E_INVALIDARG; /* should be E_CO_UNINITIALIZED */
97   }
98   if (NULL == This->pRootContainer) {
99     hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &This->pRootContainer);
100     if (FAILED(hr)) {
101       return hr;
102     }
103     hr = DXDiag_InitRootDXDiagContainer((PDXDIAGCONTAINER)This->pRootContainer);
104   }
105   return IDxDiagContainerImpl_QueryInterface((PDXDIAGCONTAINER)This->pRootContainer, &IID_IDxDiagContainer, (void**) ppInstance);
106 }
107
108 static const IDxDiagProviderVtbl DxDiagProvider_Vtbl =
109 {
110     IDxDiagProviderImpl_QueryInterface,
111     IDxDiagProviderImpl_AddRef,
112     IDxDiagProviderImpl_Release,
113     IDxDiagProviderImpl_Initialize,
114     IDxDiagProviderImpl_GetRootContainer
115 };
116
117 HRESULT DXDiag_CreateDXDiagProvider(LPCLASSFACTORY iface, LPUNKNOWN punkOuter, REFIID riid, LPVOID *ppobj) {
118   IDxDiagProviderImpl* provider;
119
120   TRACE("(%p, %s, %p)\n", punkOuter, debugstr_guid(riid), ppobj);
121   
122   provider = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDxDiagProviderImpl));
123   if (NULL == provider) {
124     *ppobj = NULL;
125     return E_OUTOFMEMORY;
126   }
127   provider->lpVtbl = &DxDiagProvider_Vtbl;
128   provider->ref = 0; /* will be inited with QueryInterface */
129   return IDxDiagProviderImpl_QueryInterface ((PDXDIAGPROVIDER)provider, riid, ppobj);
130 }
131
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};
138
139   IDxDiagContainer* pSubCont = NULL;
140   VARIANT v;
141   HRESULT hr = S_OK;
142   
143   TRACE("(%p)\n", pRootCont);
144
145   hr = DXDiag_CreateDXDiagContainer(&IID_IDxDiagContainer, (void**) &pSubCont);
146   if (FAILED(hr)) {
147     return hr;
148   }
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);
155
156   hr = IDxDiagContainerImpl_AddChildContainer(pRootCont, DxDiag_SystemInfo, pSubCont);
157   return hr;
158 }