aef7ecf409a42017f27aff0dfbe65840e7307f1e
[reactos.git] / reactos / dll / win32 / wbemdisp / main.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 #include "wbemdisp_private.h"
20
21 #include <rpcproxy.h>
22 #include <wbemdisp_classes.h>
23
24 static HINSTANCE instance;
25
26 static HRESULT WINAPI WinMGMTS_QueryInterface(IParseDisplayName *iface, REFIID riid, void **ppv)
27 {
28 if(IsEqualGUID(riid, &IID_IUnknown)) {
29 TRACE("(IID_IUnknown %p)\n", ppv);
30 *ppv = iface;
31 }else if(IsEqualGUID(riid, &IID_IParseDisplayName)) {
32 TRACE("(IID_IParseDisplayName %p)\n", ppv);
33 *ppv = iface;
34 }else {
35 WARN("Unsupported riid %s\n", debugstr_guid(riid));
36 *ppv = NULL;
37 return E_NOINTERFACE;
38 }
39
40 IUnknown_AddRef((IUnknown*)*ppv);
41 return S_OK;
42 }
43
44 static ULONG WINAPI WinMGMTS_AddRef(IParseDisplayName *iface)
45 {
46 return 2;
47 }
48
49 static ULONG WINAPI WinMGMTS_Release(IParseDisplayName *iface)
50 {
51 return 1;
52 }
53
54 static HRESULT WINAPI WinMGMTS_ParseDisplayName(IParseDisplayName *iface, IBindCtx *pbc, LPOLESTR pszDisplayName,
55 ULONG *pchEaten, IMoniker **ppmkOut)
56 {
57 FIXME("(%p %s %p %p)\n", pbc, debugstr_w(pszDisplayName), pchEaten, ppmkOut);
58 return E_NOTIMPL;
59 }
60
61 static const IParseDisplayNameVtbl WinMGMTSVtbl = {
62 WinMGMTS_QueryInterface,
63 WinMGMTS_AddRef,
64 WinMGMTS_Release,
65 WinMGMTS_ParseDisplayName
66 };
67
68 static IParseDisplayName winmgmts = { &WinMGMTSVtbl };
69
70 static HRESULT WinMGMTS_create(IUnknown *outer, void **ppv)
71 {
72 *ppv = &winmgmts;
73 return S_OK;
74 }
75
76 struct factory
77 {
78 IClassFactory IClassFactory_iface;
79 HRESULT (*fnCreateInstance)( IUnknown *, LPVOID * );
80 };
81
82 static inline struct factory *impl_from_IClassFactory( IClassFactory *iface )
83 {
84 return CONTAINING_RECORD( iface, struct factory, IClassFactory_iface );
85 }
86
87 static HRESULT WINAPI factory_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *obj )
88 {
89 if (IsEqualGUID( riid, &IID_IUnknown ) || IsEqualGUID( riid, &IID_IClassFactory ))
90 {
91 IClassFactory_AddRef( iface );
92 *obj = iface;
93 return S_OK;
94 }
95 FIXME( "interface %s not implemented\n", debugstr_guid(riid) );
96 return E_NOINTERFACE;
97 }
98
99 static ULONG WINAPI factory_AddRef( IClassFactory *iface )
100 {
101 return 2;
102 }
103
104 static ULONG WINAPI factory_Release( IClassFactory *iface )
105 {
106 return 1;
107 }
108
109 static HRESULT WINAPI factory_CreateInstance( IClassFactory *iface, LPUNKNOWN outer, REFIID riid,
110 LPVOID *obj )
111 {
112 struct factory *factory = impl_from_IClassFactory( iface );
113 IUnknown *unk;
114 HRESULT hr;
115
116 TRACE( "%p, %s, %p\n", outer, debugstr_guid(riid), obj );
117
118 *obj = NULL;
119 if (outer) return CLASS_E_NOAGGREGATION;
120
121 hr = factory->fnCreateInstance( outer, (LPVOID *)&unk );
122 if (FAILED( hr ))
123 return hr;
124
125 hr = IUnknown_QueryInterface( unk, riid, obj );
126 if (FAILED( hr ))
127 return hr;
128
129 IUnknown_Release( unk );
130 return hr;
131 }
132
133 static HRESULT WINAPI factory_LockServer( IClassFactory *iface, BOOL lock )
134 {
135 FIXME( "%p, %d\n", iface, lock );
136 return S_OK;
137 }
138
139 static const struct IClassFactoryVtbl factory_vtbl =
140 {
141 factory_QueryInterface,
142 factory_AddRef,
143 factory_Release,
144 factory_CreateInstance,
145 factory_LockServer
146 };
147
148 static struct factory swbem_locator_cf = { { &factory_vtbl }, SWbemLocator_create };
149 static struct factory winmgmts_cf = { { &factory_vtbl }, WinMGMTS_create };
150
151 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID reserved )
152 {
153
154 switch (reason)
155 {
156 case DLL_WINE_PREATTACH:
157 return FALSE; /* prefer native version */
158 case DLL_PROCESS_ATTACH:
159 instance = hinst;
160 DisableThreadLibraryCalls( hinst );
161 break;
162 }
163 return TRUE;
164 }
165
166 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *obj )
167 {
168 IClassFactory *cf = NULL;
169
170 TRACE( "%s, %s, %p\n", debugstr_guid(rclsid), debugstr_guid(iid), obj );
171
172 if (IsEqualGUID( rclsid, &CLSID_SWbemLocator ))
173 cf = &swbem_locator_cf.IClassFactory_iface;
174 else if (IsEqualGUID( rclsid, &CLSID_WinMGMTS ))
175 cf = &winmgmts_cf.IClassFactory_iface;
176 else
177 return CLASS_E_CLASSNOTAVAILABLE;
178
179 return IClassFactory_QueryInterface( cf, iid, obj );
180 }
181
182 /***********************************************************************
183 * DllCanUnloadNow (WBEMDISP.@)
184 */
185 HRESULT WINAPI DllCanUnloadNow(void)
186 {
187 return S_FALSE;
188 }
189
190 /***********************************************************************
191 * DllRegisterServer (WBEMDISP.@)
192 */
193 HRESULT WINAPI DllRegisterServer(void)
194 {
195 return __wine_register_resources( instance );
196 }
197
198 /***********************************************************************
199 * DllUnregisterServer (WBEMDISP.@)
200 */
201 HRESULT WINAPI DllUnregisterServer(void)
202 {
203 return __wine_unregister_resources( instance );
204 }