rundll32: Check more heap allocation failure paths for consistency.
[wine] / dlls / 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 "config.h"
21
22 #include <stdarg.h>
23
24 #define COBJMACROS
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "objbase.h"
29 #include "wbemcli.h"
30
31 #include "wbemprox_private.h"
32 #include "wine/debug.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
35
36 typedef HRESULT (*fnCreateInstance)( IUnknown *pUnkOuter, LPVOID *ppObj );
37
38 typedef struct
39 {
40     const struct IClassFactoryVtbl *vtbl;
41     fnCreateInstance pfnCreateInstance;
42 } wbemprox_cf;
43
44 static inline wbemprox_cf *impl_from_IClassFactory( IClassFactory *iface )
45 {
46     return (wbemprox_cf *)((char *)iface - FIELD_OFFSET( wbemprox_cf, vtbl ));
47 }
48
49 static HRESULT WINAPI wbemprox_cf_QueryInterface( IClassFactory *iface, REFIID riid, LPVOID *ppobj )
50 {
51     if (IsEqualGUID(riid, &IID_IUnknown) ||
52         IsEqualGUID(riid, &IID_IClassFactory))
53     {
54         IClassFactory_AddRef( iface );
55         *ppobj = iface;
56         return S_OK;
57     }
58     FIXME("interface %s not implemented\n", debugstr_guid(riid));
59     return E_NOINTERFACE;
60 }
61
62 static ULONG WINAPI wbemprox_cf_AddRef( IClassFactory *iface )
63 {
64     return 2;
65 }
66
67 static ULONG WINAPI wbemprox_cf_Release( IClassFactory *iface )
68 {
69     return 1;
70 }
71
72 static HRESULT WINAPI wbemprox_cf_CreateInstance( IClassFactory *iface, LPUNKNOWN pOuter,
73                                                   REFIID riid, LPVOID *ppobj )
74 {
75     wbemprox_cf *This = impl_from_IClassFactory( iface );
76     HRESULT r;
77     IUnknown *punk;
78
79     TRACE("%p %s %p\n", pOuter, debugstr_guid(riid), ppobj);
80
81     *ppobj = NULL;
82
83     if (pOuter)
84         return CLASS_E_NOAGGREGATION;
85
86     r = This->pfnCreateInstance( pOuter, (LPVOID *)&punk );
87     if (FAILED(r))
88         return r;
89
90     r = IUnknown_QueryInterface( punk, riid, ppobj );
91     if (FAILED(r))
92         return r;
93
94     IUnknown_Release( punk );
95     return r;
96 }
97
98 static HRESULT WINAPI wbemprox_cf_LockServer( IClassFactory *iface, BOOL dolock )
99 {
100     FIXME("(%p)->(%d)\n", iface, dolock);
101     return S_OK;
102 }
103
104 static const struct IClassFactoryVtbl wbemprox_cf_vtbl =
105 {
106     wbemprox_cf_QueryInterface,
107     wbemprox_cf_AddRef,
108     wbemprox_cf_Release,
109     wbemprox_cf_CreateInstance,
110     wbemprox_cf_LockServer
111 };
112
113 static wbemprox_cf wbem_locator_cf = { &wbemprox_cf_vtbl, WbemLocator_create };
114
115 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
116 {
117
118     switch (fdwReason)
119     {
120         case DLL_WINE_PREATTACH:
121             return FALSE;    /* prefer native version */
122         case DLL_PROCESS_ATTACH:
123             DisableThreadLibraryCalls(hinstDLL);
124             break;
125         case DLL_PROCESS_DETACH:
126             break;
127     }
128
129     return TRUE;
130 }
131
132 HRESULT WINAPI DllGetClassObject( REFCLSID rclsid, REFIID iid, LPVOID *ppv )
133 {
134     IClassFactory *cf = NULL;
135
136     TRACE("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
137
138     if (IsEqualGUID( rclsid, &CLSID_WbemLocator ))
139     {
140        cf = (IClassFactory *)&wbem_locator_cf.vtbl;
141     }
142     if (!cf) return CLASS_E_CLASSNOTAVAILABLE;
143     return IClassFactory_QueryInterface( cf, iid, ppv );
144 }
145
146 HRESULT WINAPI DllCanUnloadNow( void )
147 {
148     return S_FALSE;
149 }