[RSHELL]
[reactos.git] / dll / win32 / wbemprox / main.c
1 /*
2 *
3 * Copyright 2009 Austin English
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #include "wbemprox_private.h"
21
22 #include <wbemprov.h>
23 #include <rpcproxy.h>
24
25 static HINSTANCE instance;
26
27 typedef HRESULT (*fnCreateInstance)( IUnknown *pUnkOuter, LPVOID *ppObj );
28
29 typedef struct
30 {
31 IClassFactory IClassFactory_iface;
32 fnCreateInstance pfnCreateInstance;
33 } wbemprox_cf;
34
35 static inline wbemprox_cf *impl_from_IClassFactory( IClassFactory *iface )
36 {
37 return CONTAINING_RECORD(iface, wbemprox_cf, IClassFactory_iface);
38 }
39
40 static HRESULT WINAPI wbemprox_cf_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *ppobj )
41 {
42 if (IsEqualGUID(riid, &IID_IUnknown) ||
43 IsEqualGUID(riid, &IID_IClassFactory))
44 {
45 IClassFactory_AddRef( iface );
46 *ppobj = iface;
47 return S_OK;
48 }
49 FIXME("interface %s not implemented\n", debugstr_guid(riid));
50 return E_NOINTERFACE;
51 }
52
53 static ULONG WINAPI wbemprox_cf_AddRef( IClassFactory *iface )
54 {
55 return 2;
56 }
57
58 static ULONG WINAPI wbemprox_cf_Release( IClassFactory *iface )
59 {
60 return 1;
61 }
62
63 static HRESULT WINAPI wbemprox_cf_CreateInstance( IClassFactory *iface, LPUNKNOWN pOuter,
64 REFIID riid, LPVOID *ppobj )
65 {
66 wbemprox_cf *This = impl_from_IClassFactory( iface );
67 HRESULT r;
68 IUnknown *punk;
69
70 TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj);
71
72 *ppobj = NULL;
73
74 if (pOuter)
75 return CLASS_E_NOAGGREGATION;
76
77 r = This->pfnCreateInstance( pOuter, (LPVOID *)&punk );
78 if (FAILED(r))
79 return r;
80
81 r = IUnknown_QueryInterface( punk, riid, ppobj );
82 if (FAILED(r))
83 return r;
84
85 IUnknown_Release( punk );
86 return r;
87 }
88
89 static HRESULT WINAPI wbemprox_cf_LockServer( IClassFactory *iface, BOOL dolock )
90 {
91 FIXME("(%p)->(%d)\n", iface, dolock);
92 return S_OK;
93 }
94
95 static const struct IClassFactoryVtbl wbemprox_cf_vtbl =
96 {
97 wbemprox_cf_QueryInterface,
98 wbemprox_cf_AddRef,
99 wbemprox_cf_Release,
100 wbemprox_cf_CreateInstance,
101 wbemprox_cf_LockServer
102 };
103
104 static wbemprox_cf wbem_locator_cf = { { &wbemprox_cf_vtbl }, WbemLocator_create };
105
106 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
107 {
108
109 switch (fdwReason)
110 {
111 case DLL_WINE_PREATTACH:
112 return FALSE; /* prefer native version */
113 case DLL_PROCESS_ATTACH:
114 instance = hinstDLL;
115 DisableThreadLibraryCalls(hinstDLL);
116 init_table_list();
117 break;
118 }
119
120 return TRUE;
121 }
122
123 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *ppv )
124 {
125 IClassFactory *cf = NULL;
126
127 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
128
129 if (IsEqualGUID( rclsid, &CLSID_WbemLocator ) ||
130 IsEqualGUID( rclsid, &CLSID_WbemAdministrativeLocator ))
131 {
132 cf = &wbem_locator_cf.IClassFactory_iface;
133 }
134 if (!cf) return CLASS_E_CLASSNOTAVAILABLE;
135 return IClassFactory_QueryInterface( cf, iid, ppv );
136 }
137
138 /***********************************************************************
139 * DllCanUnloadNow (WBEMPROX.@)
140 */
141 HRESULT WINAPI DllCanUnloadNow( void )
142 {
143 return S_FALSE;
144 }
145
146 /***********************************************************************
147 * DllRegisterServer (WBEMPROX.@)
148 */
149 HRESULT WINAPI DllRegisterServer(void)
150 {
151 return __wine_register_resources( instance );
152 }
153
154 /***********************************************************************
155 * DllUnregisterServer (WBEMPROX.@)
156 */
157 HRESULT WINAPI DllUnregisterServer(void)
158 {
159 return __wine_unregister_resources( instance );
160 }