dxgi: Document some struct d3d12_swapchain fields.
[wine.git] / dlls / wbemdisp / main.c
blobb71efdb6da0f9f0bc9114f704db2229a0d5d9e48
1 /*
2 * Copyright 2013 Hans Leidekker for CodeWeavers
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.
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.
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
19 #include <stdarg.h>
21 #define COBJMACROS
23 #include "windef.h"
24 #include "winbase.h"
25 #include "objbase.h"
26 #include "wmiutils.h"
27 #include "wbemdisp.h"
28 #include "rpcproxy.h"
30 #include "wine/debug.h"
31 #include "wbemdisp_private.h"
32 #include "wbemdisp_classes.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(wbemdisp);
36 static HRESULT WINAPI WinMGMTS_QueryInterface(IParseDisplayName *iface, REFIID riid, void **ppv)
38 if(IsEqualGUID(riid, &IID_IUnknown)) {
39 TRACE("(IID_IUnknown %p)\n", ppv);
40 *ppv = iface;
41 }else if(IsEqualGUID(riid, &IID_IParseDisplayName)) {
42 TRACE("(IID_IParseDisplayName %p)\n", ppv);
43 *ppv = iface;
44 }else {
45 WARN("Unsupported riid %s\n", debugstr_guid(riid));
46 *ppv = NULL;
47 return E_NOINTERFACE;
50 IUnknown_AddRef((IUnknown*)*ppv);
51 return S_OK;
54 static ULONG WINAPI WinMGMTS_AddRef(IParseDisplayName *iface)
56 return 2;
59 static ULONG WINAPI WinMGMTS_Release(IParseDisplayName *iface)
61 return 1;
64 static HRESULT parse_path( const WCHAR *str, BSTR *server, BSTR *namespace, BSTR *relative )
66 IWbemPath *path;
67 ULONG len;
68 HRESULT hr;
70 *server = *namespace = *relative = NULL;
72 hr = CoCreateInstance( &CLSID_WbemDefPath, NULL, CLSCTX_INPROC_SERVER, &IID_IWbemPath, (void **)&path );
73 if (hr != S_OK) return hr;
75 hr = IWbemPath_SetText( path, WBEMPATH_CREATE_ACCEPT_ALL, str );
76 if (hr != S_OK) goto done;
78 len = 0;
79 hr = IWbemPath_GetServer( path, &len, NULL );
80 if (hr == S_OK)
82 if (!(*server = SysAllocStringLen( NULL, len )))
84 hr = E_OUTOFMEMORY;
85 goto done;
87 hr = IWbemPath_GetServer( path, &len, *server );
88 if (hr != S_OK) goto done;
91 len = 0;
92 hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, NULL );
93 if (hr == S_OK)
95 if (!(*namespace = SysAllocStringLen( NULL, len )))
97 hr = E_OUTOFMEMORY;
98 goto done;
100 hr = IWbemPath_GetText( path, WBEMPATH_GET_NAMESPACE_ONLY, &len, *namespace );
101 if (hr != S_OK) goto done;
103 len = 0;
104 hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, NULL );
105 if (hr == S_OK)
107 if (!(*relative = SysAllocStringLen( NULL, len )))
109 hr = E_OUTOFMEMORY;
110 goto done;
112 hr = IWbemPath_GetText( path, WBEMPATH_GET_RELATIVE_ONLY, &len, *relative );
115 done:
116 IWbemPath_Release( path );
117 if (hr != S_OK)
119 SysFreeString( *server );
120 SysFreeString( *namespace );
121 SysFreeString( *relative );
123 return hr;
126 static HRESULT WINAPI WinMGMTS_ParseDisplayName(IParseDisplayName *iface, IBindCtx *pbc, LPOLESTR pszDisplayName,
127 ULONG *pchEaten, IMoniker **ppmkOut)
129 const DWORD prefix_len = ARRAY_SIZE(L"winmgmts:") - 1;
130 ISWbemLocator *locator = NULL;
131 ISWbemServices *services = NULL;
132 ISWbemObject *obj = NULL;
133 BSTR server, namespace, relative;
134 WCHAR *p;
135 HRESULT hr;
137 TRACE( "%p, %p, %s, %p, %p\n", iface, pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut );
139 if (wcsnicmp( pszDisplayName, L"winmgmts:", prefix_len )) return MK_E_SYNTAX;
141 p = pszDisplayName + prefix_len;
142 if (*p == '{')
144 FIXME( "ignoring security settings\n" );
145 while (*p && *p != '}') p++;
146 if (*p == '}') p++;
147 if (*p == '!') p++;
149 hr = parse_path( p, &server, &namespace, &relative );
150 if (hr != S_OK) return hr;
152 hr = SWbemLocator_create( (void **)&locator );
153 if (hr != S_OK) goto done;
155 hr = ISWbemLocator_ConnectServer( locator, server, namespace, NULL, NULL, NULL, NULL, 0, NULL, &services );
156 if (hr != S_OK) goto done;
158 if (!relative || !*relative) CreatePointerMoniker( (IUnknown *)services, ppmkOut );
159 else
161 hr = ISWbemServices_Get( services, relative, 0, NULL, &obj );
162 if (hr != S_OK) goto done;
163 hr = CreatePointerMoniker( (IUnknown *)obj, ppmkOut );
166 done:
167 if (obj) ISWbemObject_Release( obj );
168 if (services) ISWbemServices_Release( services );
169 if (locator) ISWbemLocator_Release( locator );
170 SysFreeString( server );
171 SysFreeString( namespace );
172 SysFreeString( relative );
173 if (hr == S_OK) *pchEaten = lstrlenW( pszDisplayName );
174 return hr;
177 static const IParseDisplayNameVtbl WinMGMTSVtbl = {
178 WinMGMTS_QueryInterface,
179 WinMGMTS_AddRef,
180 WinMGMTS_Release,
181 WinMGMTS_ParseDisplayName
184 static IParseDisplayName winmgmts = { &WinMGMTSVtbl };
186 static HRESULT WinMGMTS_create(void **ppv)
188 *ppv = &winmgmts;
189 return S_OK;
192 struct factory
194 IClassFactory IClassFactory_iface;
195 HRESULT (*fnCreateInstance)( LPVOID * );
198 static inline struct factory *impl_from_IClassFactory( IClassFactory *iface )
200 return CONTAINING_RECORD( iface, struct factory, IClassFactory_iface );
203 static HRESULT WINAPI factory_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *obj )
205 if (IsEqualGUID( riid, &IID_IUnknown ) || IsEqualGUID( riid, &IID_IClassFactory ))
207 IClassFactory_AddRef( iface );
208 *obj = iface;
209 return S_OK;
211 WARN( "interface %s not implemented\n", debugstr_guid(riid) );
212 return E_NOINTERFACE;
215 static ULONG WINAPI factory_AddRef( IClassFactory *iface )
217 return 2;
220 static ULONG WINAPI factory_Release( IClassFactory *iface )
222 return 1;
225 static HRESULT WINAPI factory_CreateInstance( IClassFactory *iface, LPUNKNOWN outer, REFIID riid,
226 LPVOID *obj )
228 struct factory *factory = impl_from_IClassFactory( iface );
229 IUnknown *unk;
230 HRESULT hr;
232 TRACE( "%p, %s, %p\n", outer, debugstr_guid(riid), obj );
234 *obj = NULL;
235 if (outer) return CLASS_E_NOAGGREGATION;
237 hr = factory->fnCreateInstance( (LPVOID *)&unk );
238 if (FAILED( hr ))
239 return hr;
241 hr = IUnknown_QueryInterface( unk, riid, obj );
242 IUnknown_Release( unk );
243 return hr;
246 static HRESULT WINAPI factory_LockServer( IClassFactory *iface, BOOL lock )
248 FIXME( "%p, %d\n", iface, lock );
249 return S_OK;
252 static const struct IClassFactoryVtbl factory_vtbl =
254 factory_QueryInterface,
255 factory_AddRef,
256 factory_Release,
257 factory_CreateInstance,
258 factory_LockServer
261 static struct factory swbem_locator_cf = { { &factory_vtbl }, SWbemLocator_create };
262 static struct factory swbem_namedvalueset_cf = { { &factory_vtbl }, SWbemNamedValueSet_create };
263 static struct factory winmgmts_cf = { { &factory_vtbl }, WinMGMTS_create };
265 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *obj )
267 IClassFactory *cf = NULL;
269 TRACE( "%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(iid), obj );
271 if (IsEqualGUID( rclsid, &CLSID_SWbemLocator ))
272 cf = &swbem_locator_cf.IClassFactory_iface;
273 else if (IsEqualGUID( rclsid, &CLSID_WinMGMTS ))
274 cf = &winmgmts_cf.IClassFactory_iface;
275 else if (IsEqualGUID( rclsid, &CLSID_SWbemNamedValueSet ))
276 cf = &swbem_namedvalueset_cf.IClassFactory_iface;
277 else
278 return CLASS_E_CLASSNOTAVAILABLE;
280 return IClassFactory_QueryInterface( cf, iid, obj );