[WBEMPROX] Sync with Wine Staging 1.7.55. CORE-10536
[reactos.git] / reactos / 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)( 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( (LPVOID *)&punk );
78 if (FAILED(r))
79 return r;
80
81 r = IUnknown_QueryInterface( punk, riid, ppobj );
82 IUnknown_Release( punk );
83 return r;
84 }
85
86 static HRESULT WINAPI wbemprox_cf_LockServer( IClassFactory *iface, BOOL dolock )
87 {
88 FIXME("(%p)->(%d)\n", iface, dolock);
89 return S_OK;
90 }
91
92 static const struct IClassFactoryVtbl wbemprox_cf_vtbl =
93 {
94 wbemprox_cf_QueryInterface,
95 wbemprox_cf_AddRef,
96 wbemprox_cf_Release,
97 wbemprox_cf_CreateInstance,
98 wbemprox_cf_LockServer
99 };
100
101 static wbemprox_cf wbem_locator_cf = { { &wbemprox_cf_vtbl }, WbemLocator_create };
102
103 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
104 {
105
106 switch (fdwReason)
107 {
108 case DLL_PROCESS_ATTACH:
109 instance = hinstDLL;
110 DisableThreadLibraryCalls(hinstDLL);
111 init_table_list();
112 break;
113 }
114
115 return TRUE;
116 }
117
118 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *ppv )
119 {
120 IClassFactory *cf = NULL;
121
122 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
123
124 if (IsEqualGUID( rclsid, &CLSID_WbemLocator ) ||
125 IsEqualGUID( rclsid, &CLSID_WbemAdministrativeLocator ))
126 {
127 cf = &wbem_locator_cf.IClassFactory_iface;
128 }
129 if (!cf) return CLASS_E_CLASSNOTAVAILABLE;
130 return IClassFactory_QueryInterface( cf, iid, ppv );
131 }
132
133 /***********************************************************************
134 * DllCanUnloadNow (WBEMPROX.@)
135 */
136 HRESULT WINAPI DllCanUnloadNow( void )
137 {
138 return S_FALSE;
139 }
140
141 /***********************************************************************
142 * DllRegisterServer (WBEMPROX.@)
143 */
144 HRESULT WINAPI DllRegisterServer(void)
145 {
146 return __wine_register_resources( instance );
147 }
148
149 /***********************************************************************
150 * DllUnregisterServer (WBEMPROX.@)
151 */
152 HRESULT WINAPI DllUnregisterServer(void)
153 {
154 return __wine_unregister_resources( instance );
155 }