include: Add transact.idl to oledb.idl.
[wine.git] / dlls / dx8vb / main.c
blob2fc7402a220809170397c58e0fc4322f0c99b23f
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 #define COBJMACROS
22 #include <stdarg.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
30 #include "ole2.h"
31 #include "rpcproxy.h"
33 #include "unknwn.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(dx8vb);
39 typedef struct {
40 IClassFactory IClassFactory_iface;
42 LONG ref;
43 HRESULT (*pfnCreateInstance)(IUnknown *unk_outer, void **ppobj);
44 } IClassFactoryImpl;
46 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
48 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
51 struct object_creation_info
53 const CLSID *clsid;
54 HRESULT (*pfnCreateInstance)(IUnknown *unk_outer, void **ppobj);
57 static const struct object_creation_info object_creation[] =
59 { &GUID_NULL, 0 },
62 static HRESULT WINAPI classfactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
64 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
66 if (IsEqualGUID(riid, &IID_IUnknown)
67 || IsEqualGUID(riid, &IID_IClassFactory))
69 IClassFactory_AddRef(iface);
70 *ppobj = &This->IClassFactory_iface;
71 return S_OK;
74 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
75 return E_NOINTERFACE;
78 static ULONG WINAPI classfactory_AddRef(IClassFactory *iface)
80 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
81 return InterlockedIncrement(&This->ref);
84 static ULONG WINAPI classfactory_Release(IClassFactory *iface)
86 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
87 ULONG ref = InterlockedDecrement(&This->ref);
89 if (ref == 0)
90 HeapFree(GetProcessHeap(), 0, This);
92 return ref;
95 static HRESULT WINAPI classfactory_CreateInstance(IClassFactory *iface, IUnknown *outer_unk, REFIID riid, void **ppobj)
97 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
98 HRESULT hres;
99 IUnknown *unk;
101 TRACE("(%p)->(%p,%s,%p)\n", This, outer_unk, debugstr_guid(riid), ppobj);
103 *ppobj = NULL;
104 hres = This->pfnCreateInstance(outer_unk, (void **) &unk);
105 if (SUCCEEDED(hres))
107 hres = IUnknown_QueryInterface(unk, riid, ppobj);
108 IUnknown_Release(unk);
110 return hres;
113 static HRESULT WINAPI classfactory_LockServer(IClassFactory *iface, BOOL dolock)
115 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
116 FIXME("(%p)->(%d), stub!\n", This, dolock);
117 return S_OK;
120 static const IClassFactoryVtbl classfactory_Vtbl =
122 classfactory_QueryInterface,
123 classfactory_AddRef,
124 classfactory_Release,
125 classfactory_CreateInstance,
126 classfactory_LockServer
129 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, void **ppv)
131 unsigned int i;
132 IClassFactoryImpl *factory;
134 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
136 if (!IsEqualGUID(&IID_IClassFactory, riid)
137 && !IsEqualGUID( &IID_IUnknown, riid))
138 return E_NOINTERFACE;
140 for (i = 0; i < ARRAY_SIZE(object_creation); i++)
142 if (IsEqualGUID(object_creation[i].clsid, rclsid))
143 break;
146 if (i == ARRAY_SIZE(object_creation))
148 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
149 return CLASS_E_CLASSNOTAVAILABLE;
152 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
153 if (factory == NULL)
154 return E_OUTOFMEMORY;
156 factory->IClassFactory_iface.lpVtbl = &classfactory_Vtbl;
157 factory->ref = 1;
159 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
161 *ppv = &factory->IClassFactory_iface;
162 return S_OK;