* Sync up to trunk head (r65270).
[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)( 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( (LPVOID *)&punk );
76 if (FAILED(r))
77 return r;
78
79 r = IUnknown_QueryInterface( punk, riid, ppobj );
80 IUnknown_Release( punk );
81 return r;
82 }
83
84 static HRESULT WINAPI wucf_LockServer( IClassFactory *iface, BOOL dolock )
85 {
86 FIXME("(%p)->(%d)\n", iface, dolock);
87 return S_OK;
88 }
89
90 static const struct IClassFactoryVtbl wucf_vtbl =
91 {
92 wucf_QueryInterface,
93 wucf_AddRef,
94 wucf_Release,
95 wucf_CreateInstance,
96 wucf_LockServer
97 };
98
99 static wucf sessioncf = { { &wucf_vtbl }, UpdateSession_create };
100 static wucf updatescf = { { &wucf_vtbl }, AutomaticUpdates_create };
101 static wucf sysinfocf = { { &wucf_vtbl }, SystemInformation_create };
102
103 static HINSTANCE instance;
104
105 BOOL WINAPI DllMain( HINSTANCE hinst, DWORD reason, LPVOID lpv )
106 {
107 switch(reason)
108 {
109 case DLL_WINE_PREATTACH:
110 return FALSE; /* prefer native version */
111 case DLL_PROCESS_ATTACH:
112 instance = hinst;
113 DisableThreadLibraryCalls( hinst );
114 break;
115 }
116 return TRUE;
117 }
118
119 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *ppv )
120 {
121 IClassFactory *cf = NULL;
122
123 TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
124
125 if (IsEqualGUID( rclsid, &CLSID_UpdateSession ))
126 {
127 cf = &sessioncf.IClassFactory_iface;
128 }
129 else if (IsEqualGUID( rclsid, &CLSID_AutomaticUpdates ))
130 {
131 cf = &updatescf.IClassFactory_iface;
132 }
133 else if (IsEqualGUID( rclsid, &CLSID_SystemInformation ))
134 {
135 cf = &sysinfocf.IClassFactory_iface;
136 }
137 if (!cf) return CLASS_E_CLASSNOTAVAILABLE;
138 return IClassFactory_QueryInterface( cf, iid, ppv );
139 }
140
141 HRESULT WINAPI DllCanUnloadNow( void )
142 {
143 return S_FALSE;
144 }
145
146 /***********************************************************************
147 * DllRegisterServer (WUAPI.@)
148 */
149 HRESULT WINAPI DllRegisterServer(void)
150 {
151 return __wine_register_resources( instance );
152 }
153
154 /***********************************************************************
155 * DllUnregisterServer (WUAPI.@)
156 */
157 HRESULT WINAPI DllUnregisterServer(void)
158 {
159 return __wine_unregister_resources( instance );
160 }