Release 2.16.
[wine.git] / dlls / uiribbon / main.c
blob9306338086c813e7548cee54f3380ae0c671d986
1 /*
2 * Copyright 2017 Fabian Maurer
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdarg.h>
20 #include <string.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "winreg.h"
29 #include "ole2.h"
30 #include "rpcproxy.h"
32 /* Define GUIDs, but only our own */
33 #include <unknwn.h>
34 #include <propsys.h>
35 #include "initguid.h"
36 #include "uiribbon_private.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(uiribbon);
42 static HINSTANCE instance;
44 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpvReserved)
46 TRACE("(0x%p, %d, %p)\n", hInstDLL, fdwReason, lpvReserved);
48 switch (fdwReason)
50 case DLL_PROCESS_ATTACH:
51 instance = hInstDLL;
52 DisableThreadLibraryCalls(hInstDLL);
53 break;
56 return TRUE;
59 typedef struct {
60 IClassFactory IClassFactory_iface;
62 LONG ref;
63 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, void **ppObj);
64 } IClassFactoryImpl;
66 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
68 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
71 struct object_creation_info
73 const CLSID *clsid;
74 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, void **ppObj);
77 static const struct object_creation_info object_creation[] =
79 { &CLSID_UIRibbonFramework, UIRibbonFrameworkImpl_Create },
82 static HRESULT WINAPI XFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid, void **ppobj)
84 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
86 if (IsEqualGUID(riid, &IID_IUnknown)
87 || IsEqualGUID(riid, &IID_IClassFactory))
89 IClassFactory_AddRef(iface);
90 *ppobj = &This->IClassFactory_iface;
91 return S_OK;
94 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
95 return E_NOINTERFACE;
98 static ULONG WINAPI XFCF_AddRef(LPCLASSFACTORY iface)
100 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
101 return InterlockedIncrement(&This->ref);
104 static ULONG WINAPI XFCF_Release(LPCLASSFACTORY iface)
106 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
108 ULONG ref = InterlockedDecrement(&This->ref);
110 if (ref == 0)
111 HeapFree(GetProcessHeap(), 0, This);
113 return ref;
116 static HRESULT WINAPI XFCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, void **ppobj)
118 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
119 HRESULT hres;
120 LPUNKNOWN punk;
122 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
124 *ppobj = NULL;
125 hres = This->pfnCreateInstance(pOuter, (void **) &punk);
126 if (SUCCEEDED(hres)) {
127 hres = IUnknown_QueryInterface(punk, riid, ppobj);
128 IUnknown_Release(punk);
130 return hres;
133 static HRESULT WINAPI XFCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
135 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
136 FIXME("(%p)->(%d), stub!\n",This,dolock);
137 return S_OK;
140 static const IClassFactoryVtbl XFCF_Vtbl =
142 XFCF_QueryInterface,
143 XFCF_AddRef,
144 XFCF_Release,
145 XFCF_CreateInstance,
146 XFCF_LockServer
149 /*******************************************************************************
150 * Retrieves class object from a DLL object
152 * NOTES
153 * Docs say returns STDAPI
155 * PARAMS
156 * rclsid [I] CLSID for the class object
157 * riid [I] Reference to identifier of interface for class object
158 * ppv [O] Address of variable to receive interface pointer for riid
160 * RETURNS
161 * Success: S_OK
162 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
163 * E_UNEXPECTED
165 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
167 unsigned int i;
168 IClassFactoryImpl *factory;
170 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
172 if ( !IsEqualGUID( &IID_IClassFactory, riid )
173 && ! IsEqualGUID( &IID_IUnknown, riid) )
174 return E_NOINTERFACE;
176 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
178 if (IsEqualGUID(object_creation[i].clsid, rclsid))
179 break;
182 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
184 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
185 return CLASS_E_CLASSNOTAVAILABLE;
188 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
189 if (factory == NULL) return E_OUTOFMEMORY;
191 factory->IClassFactory_iface.lpVtbl = &XFCF_Vtbl;
192 factory->ref = 1;
194 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
196 *ppv = &(factory->IClassFactory_iface);
197 return S_OK;
200 HRESULT WINAPI DllCanUnloadNow(void)
202 return S_FALSE;
205 HRESULT WINAPI DllRegisterServer(void)
207 return __wine_register_resources( instance );
210 HRESULT WINAPI DllUnregisterServer(void)
212 return __wine_unregister_resources( instance );