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