widl: Always check the runtimeclass interfaces presence.
[wine/zf.git] / dlls / dsquery / main.c
blobea367b63deea048a43ac37b00274f3312a79b5db
1 /*
2 * Copyright 2017 Zebediah Figura for CodeWeavers
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
20 #include <stdarg.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "objbase.h"
27 #include "rpcproxy.h"
28 #include "initguid.h"
29 #include "cmnquery.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(dsquery);
34 static HINSTANCE instance;
36 /******************************************************************
37 * IClassFactory implementation
39 struct query_class_factory {
40 IClassFactory IClassFactory_iface;
41 LONG ref;
42 HRESULT (*pfnCreateInstance)(IUnknown *outer, REFIID riid, void **out);
45 static inline struct query_class_factory *impl_from_IClassFactory(IClassFactory *iface)
47 return CONTAINING_RECORD(iface, struct query_class_factory, IClassFactory_iface);
50 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **out)
52 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), out);
54 if (IsEqualGUID(riid, &IID_IClassFactory) || IsEqualGUID(riid, &IID_IUnknown))
56 IClassFactory_AddRef(iface);
57 *out = iface;
58 return S_OK;
61 FIXME("interface %s not implemented\n", debugstr_guid(riid));
62 *out = NULL;
63 return E_NOINTERFACE;
66 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
68 struct query_class_factory *This = impl_from_IClassFactory(iface);
69 ULONG ref = InterlockedIncrement(&This->ref);
71 TRACE("(%p) increasing refcount to %u\n", iface, ref);
73 return ref;
76 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
78 struct query_class_factory *This = impl_from_IClassFactory(iface);
79 ULONG ref = InterlockedDecrement(&This->ref);
81 TRACE("(%p) decreasing refcount to %u\n", iface, ref);
83 if (ref == 0)
84 HeapFree(GetProcessHeap(), 0, This);
86 return ref;
89 static HRESULT WINAPI ClassFactory_CreateInstance(IClassFactory *iface,
90 IUnknown *outer, REFIID riid, void **out)
92 struct query_class_factory *This = impl_from_IClassFactory(iface);
94 TRACE("(%p)->(%p, %s, %p)\n", iface, outer, debugstr_guid(riid), out);
96 return This->pfnCreateInstance(outer, riid, out);
99 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL dolock)
101 FIXME("(%p)->(%d)\n", iface, dolock);
103 return S_OK;
106 static const IClassFactoryVtbl query_class_factory_vtbl =
108 ClassFactory_QueryInterface,
109 ClassFactory_AddRef,
110 ClassFactory_Release,
111 ClassFactory_CreateInstance,
112 ClassFactory_LockServer,
115 /******************************************************************
116 * ICommonQuery implementation
118 struct common_query {
119 ICommonQuery ICommonQuery_iface;
120 LONG ref;
123 static inline struct common_query *impl_from_ICommonQuery(ICommonQuery *iface)
125 return CONTAINING_RECORD(iface, struct common_query, ICommonQuery_iface);
128 static HRESULT WINAPI CommonQuery_QueryInterface(ICommonQuery *iface, REFIID riid, void **out)
130 TRACE("(%p)->(%s, %p)\n", iface, debugstr_guid(riid), out);
132 if (IsEqualGUID(riid, &IID_ICommonQuery) || IsEqualGUID(riid, &IID_IUnknown))
134 ICommonQuery_AddRef(iface);
135 *out = iface;
136 return S_OK;
139 FIXME("interface %s not implemented\n", debugstr_guid(riid));
140 *out = NULL;
141 return E_NOINTERFACE;
144 static ULONG WINAPI CommonQuery_AddRef(ICommonQuery *iface)
146 struct common_query *This = impl_from_ICommonQuery(iface);
147 ULONG ref = InterlockedIncrement(&This->ref);
149 TRACE("(%p) increasing refcount to %u\n", iface, ref);
151 return ref;
154 static ULONG WINAPI CommonQuery_Release(ICommonQuery *iface)
156 struct common_query *This = impl_from_ICommonQuery(iface);
157 ULONG ref = InterlockedDecrement(&This->ref);
159 TRACE("(%p) decreasing refcount to %u\n", iface, ref);
161 if (ref == 0)
162 HeapFree(GetProcessHeap(), 0, This);
164 return ref;
167 static HRESULT WINAPI CommonQuery_OpenQueryWindow(ICommonQuery *iface,
168 HWND parent, LPOPENQUERYWINDOW query_window, IDataObject **data_object)
170 FIXME("(%p)->(%p, %p, %p) stub!\n", iface, parent, query_window, data_object);
172 return E_NOTIMPL;
175 static const ICommonQueryVtbl CommonQuery_vtbl =
177 CommonQuery_QueryInterface,
178 CommonQuery_AddRef,
179 CommonQuery_Release,
180 CommonQuery_OpenQueryWindow,
183 static HRESULT CommonQuery_create(IUnknown *outer, REFIID riid, void **out)
185 struct common_query *query;
187 TRACE("outer %p, riid %s, out %p\n", outer, debugstr_guid(riid), out);
189 if (outer)
190 return CLASS_E_NOAGGREGATION;
192 if (!(query = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*query))))
193 return E_OUTOFMEMORY;
195 query->ICommonQuery_iface.lpVtbl = &CommonQuery_vtbl;
196 return ICommonQuery_QueryInterface(&query->ICommonQuery_iface, riid, out);
199 /***********************************************************************
200 * DllMain
202 BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, void *reserved)
204 TRACE("(%p, %u, %p)\n", inst, reason, reserved);
206 switch (reason)
208 case DLL_PROCESS_ATTACH:
209 instance = inst;
210 DisableThreadLibraryCalls(inst);
211 break;
214 return TRUE;
217 /***********************************************************************
218 * DllCanUnloadNow (DSQUERY.@)
220 HRESULT WINAPI DllCanUnloadNow(void)
222 return S_FALSE;
225 /***********************************************************************
226 * DllGetClassObject (DSQUERY.@)
228 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **out)
230 TRACE("rclsid %s, riid %s, out %p\n", debugstr_guid(rclsid), debugstr_guid(riid), out);
232 if (!IsEqualGUID( &IID_IClassFactory, riid)
233 && !IsEqualGUID( &IID_IUnknown, riid))
235 FIXME("interface %s not implemented\n", debugstr_guid(riid));
236 *out = NULL;
237 return E_NOINTERFACE;
240 if (IsEqualGUID(&CLSID_CommonQuery, rclsid))
242 struct query_class_factory *factory = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*factory));
243 if (!factory) return E_OUTOFMEMORY;
245 factory->IClassFactory_iface.lpVtbl = &query_class_factory_vtbl;
246 factory->ref = 1;
247 factory->pfnCreateInstance = CommonQuery_create;
248 *out = factory;
249 return S_OK;
252 FIXME("%s: no class found\n", debugstr_guid(rclsid));
253 *out = NULL;
254 return CLASS_E_CLASSNOTAVAILABLE;
257 /***********************************************************************
258 * DllRegisterServer (DSQUERY.@)
260 HRESULT WINAPI DllRegisterServer(void)
262 return __wine_register_resources( instance );
265 /***********************************************************************
266 * DllUnregisterServer (DSQUERY.@)
268 HRESULT WINAPI DllUnregisterServer(void)
270 return __wine_unregister_resources( instance );