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