[VDMDBG]
[reactos.git] / reactos / dll / win32 / wbemdisp / locator.c
1 /*
2 * Copyright 2013 Hans Leidekker for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #define COBJMACROS
20
21 #include "config.h"
22 #include <stdarg.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "wbemdisp.h"
28
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
31 #include "wbemdisp_private.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(wbemdisp);
34
35 struct locator
36 {
37 ISWbemLocator ISWbemLocator_iface;
38 LONG refs;
39 };
40
41 static inline struct locator *impl_from_ISWbemLocator( ISWbemLocator *iface )
42 {
43 return CONTAINING_RECORD( iface, struct locator, ISWbemLocator_iface );
44 }
45
46 static ULONG WINAPI locator_AddRef(
47 ISWbemLocator *iface )
48 {
49 struct locator *locator = impl_from_ISWbemLocator( iface );
50 return InterlockedIncrement( &locator->refs );
51 }
52
53 static ULONG WINAPI locator_Release(
54 ISWbemLocator *iface )
55 {
56 struct locator *locator = impl_from_ISWbemLocator( iface );
57 LONG refs = InterlockedDecrement( &locator->refs );
58 if (!refs)
59 {
60 TRACE( "destroying %p\n", locator );
61 heap_free( locator );
62 }
63 return refs;
64 }
65
66 static HRESULT WINAPI locator_QueryInterface(
67 ISWbemLocator *iface,
68 REFIID riid,
69 void **ppvObject )
70 {
71 struct locator *locator = impl_from_ISWbemLocator( iface );
72
73 TRACE( "%p, %s, %p\n", locator, debugstr_guid( riid ), ppvObject );
74
75 if (IsEqualGUID( riid, &IID_ISWbemLocator ) ||
76 IsEqualGUID( riid, &IID_IDispatch ) ||
77 IsEqualGUID( riid, &IID_IUnknown ))
78 {
79 *ppvObject = iface;
80 }
81 else
82 {
83 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
84 return E_NOINTERFACE;
85 }
86 ISWbemLocator_AddRef( iface );
87 return S_OK;
88 }
89
90 static HRESULT WINAPI locator_GetTypeInfoCount(
91 ISWbemLocator *iface,
92 UINT *count )
93 {
94 struct locator *locator = impl_from_ISWbemLocator( iface );
95
96 TRACE( "%p, %p\n", locator, count );
97 *count = 1;
98 return S_OK;
99 }
100
101 enum type_id
102 {
103 ISWbemLocator_tid,
104 last_tid
105 };
106
107 static ITypeLib *wbemdisp_typelib;
108 static ITypeInfo *wbemdisp_typeinfo[last_tid];
109
110 static REFIID wbemdisp_tid_id[] =
111 {
112 &IID_ISWbemLocator
113 };
114
115 static HRESULT get_typeinfo( enum type_id tid, ITypeInfo **ret )
116 {
117 HRESULT hr;
118
119 if (!wbemdisp_typelib)
120 {
121 ITypeLib *typelib;
122
123 hr = LoadRegTypeLib( &LIBID_WbemScripting, 1, 2, LOCALE_SYSTEM_DEFAULT, &typelib );
124 if (FAILED( hr ))
125 {
126 ERR( "LoadRegTypeLib failed: %08x\n", hr );
127 return hr;
128 }
129 if (InterlockedCompareExchangePointer( (void **)&wbemdisp_typelib, typelib, NULL ))
130 ITypeLib_Release( typelib );
131 }
132 if (!wbemdisp_typeinfo[tid])
133 {
134 ITypeInfo *typeinfo;
135
136 hr = ITypeLib_GetTypeInfoOfGuid( wbemdisp_typelib, wbemdisp_tid_id[tid], &typeinfo );
137 if (FAILED( hr ))
138 {
139 ERR( "GetTypeInfoOfGuid(%s) failed: %08x\n", debugstr_guid(wbemdisp_tid_id[tid]), hr );
140 return hr;
141 }
142 if (InterlockedCompareExchangePointer( (void **)(wbemdisp_typeinfo + tid), typeinfo, NULL ))
143 ITypeInfo_Release( typeinfo );
144 }
145 *ret = wbemdisp_typeinfo[tid];
146 return S_OK;
147 }
148
149 static HRESULT WINAPI locator_GetTypeInfo(
150 ISWbemLocator *iface,
151 UINT index,
152 LCID lcid,
153 ITypeInfo **info )
154 {
155 struct locator *locator = impl_from_ISWbemLocator( iface );
156 TRACE( "%p, %u, %u, %p\n", locator, index, lcid, info );
157
158 return get_typeinfo( ISWbemLocator_tid, info );
159 }
160
161 static HRESULT WINAPI locator_GetIDsOfNames(
162 ISWbemLocator *iface,
163 REFIID riid,
164 LPOLESTR *names,
165 UINT count,
166 LCID lcid,
167 DISPID *dispid )
168 {
169 struct locator *locator = impl_from_ISWbemLocator( iface );
170 ITypeInfo *typeinfo;
171 HRESULT hr;
172
173 TRACE( "%p, %s, %p, %u, %u, %p\n", locator, debugstr_guid(riid), names, count, lcid, dispid );
174
175 if (!names || !count || !dispid) return E_INVALIDARG;
176
177 hr = get_typeinfo( ISWbemLocator_tid, &typeinfo );
178 if (SUCCEEDED(hr))
179 {
180 hr = ITypeInfo_GetIDsOfNames( typeinfo, names, count, dispid );
181 ITypeInfo_Release( typeinfo );
182 }
183 return hr;
184 }
185
186 static HRESULT WINAPI locator_Invoke(
187 ISWbemLocator *iface,
188 DISPID member,
189 REFIID riid,
190 LCID lcid,
191 WORD flags,
192 DISPPARAMS *params,
193 VARIANT *result,
194 EXCEPINFO *excep_info,
195 UINT *arg_err )
196 {
197 struct locator *locator = impl_from_ISWbemLocator( iface );
198 ITypeInfo *typeinfo;
199 HRESULT hr;
200
201 TRACE( "%p, %d, %s, %d, %d, %p, %p, %p, %p\n", locator, member, debugstr_guid(riid),
202 lcid, flags, params, result, excep_info, arg_err );
203
204 hr = get_typeinfo( ISWbemLocator_tid, &typeinfo );
205 if (SUCCEEDED(hr))
206 {
207 hr = ITypeInfo_Invoke( typeinfo, &locator->ISWbemLocator_iface, member, flags,
208 params, result, excep_info, arg_err );
209 ITypeInfo_Release( typeinfo );
210 }
211 return hr;
212 }
213
214 static HRESULT WINAPI locator_ConnectServer(
215 ISWbemLocator *iface,
216 BSTR strServer,
217 BSTR strNamespace,
218 BSTR strUser,
219 BSTR strPassword,
220 BSTR strLocale,
221 BSTR strAuthority,
222 LONG iSecurityFlags,
223 IDispatch *objWbemNamedValueSet,
224 ISWbemServices **objWbemServices )
225 {
226 FIXME( "%p, %s, %s, %s, %p, %s, %s, 0x%08x, %p, %p\n", iface, debugstr_w(strServer),
227 debugstr_w(strNamespace), debugstr_w(strUser), strPassword, debugstr_w(strLocale),
228 debugstr_w(strAuthority), iSecurityFlags, objWbemNamedValueSet, objWbemServices );
229 return E_NOTIMPL;
230 }
231
232 static HRESULT WINAPI locator_get_Security_(
233 ISWbemLocator *iface,
234 ISWbemSecurity **objWbemSecurity )
235 {
236 FIXME( "%p, %p\n", iface, objWbemSecurity );
237 return E_NOTIMPL;
238 }
239
240 static const ISWbemLocatorVtbl locator_vtbl =
241 {
242 locator_QueryInterface,
243 locator_AddRef,
244 locator_Release,
245 locator_GetTypeInfoCount,
246 locator_GetTypeInfo,
247 locator_GetIDsOfNames,
248 locator_Invoke,
249 locator_ConnectServer,
250 locator_get_Security_
251 };
252
253 HRESULT SWbemLocator_create( IUnknown *unk, void **obj )
254 {
255 struct locator *locator;
256
257 TRACE( "%p, %p\n", unk, obj );
258
259 if (!(locator = heap_alloc( sizeof(*locator) ))) return E_OUTOFMEMORY;
260 locator->ISWbemLocator_iface.lpVtbl = &locator_vtbl;
261 locator->refs = 1;
262
263 *obj = &locator->ISWbemLocator_iface;
264 TRACE( "returning iface %p\n", *obj );
265 return S_OK;
266 }