qedit: Add the DirectShow ClassFactory.
[wine/wine64.git] / dlls / qedit / main.c
blob1ece4ee5f9f0763d46e83995ecdfe52bb5371cc2
1 /* DirectShow Editing Services (qedit.dll)
3 * Copyright 2008 Google (Lei Zhang)
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.
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.
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
20 #include "qedit_private.h"
21 #include "wine/debug.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(qedit);
25 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
27 switch(fdwReason) {
28 case DLL_PROCESS_ATTACH:
29 DisableThreadLibraryCalls(hInstDLL);
30 break;
31 case DLL_PROCESS_DETACH:
32 break;
34 return TRUE;
37 /******************************************************************************
38 * DirectShow ClassFactory
40 typedef struct {
41 IClassFactory ITF_IClassFactory;
43 LONG ref;
44 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
45 } IClassFactoryImpl;
47 struct object_creation_info
49 const CLSID *clsid;
50 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
53 static const struct object_creation_info object_creation[] =
57 static HRESULT WINAPI
58 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
60 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
62 if (IsEqualGUID(riid, &IID_IUnknown)
63 || IsEqualGUID(riid, &IID_IClassFactory))
65 IClassFactory_AddRef(iface);
66 *ppobj = This;
67 return S_OK;
70 *ppobj = NULL;
71 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
72 return E_NOINTERFACE;
75 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
77 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
78 return InterlockedIncrement(&This->ref);
81 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
83 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
85 ULONG ref = InterlockedDecrement(&This->ref);
87 if (ref == 0)
88 CoTaskMemFree(This);
90 return ref;
93 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
95 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
96 HRESULT hres;
97 LPUNKNOWN punk;
99 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
101 *ppobj = NULL;
102 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
103 if (SUCCEEDED(hres)) {
104 hres = IUnknown_QueryInterface(punk, riid, ppobj);
105 IUnknown_Release(punk);
107 return hres;
110 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
112 IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
113 FIXME("(%p)->(%d),stub!\n",This,dolock);
114 return S_OK;
117 static const IClassFactoryVtbl DSCF_Vtbl =
119 DSCF_QueryInterface,
120 DSCF_AddRef,
121 DSCF_Release,
122 DSCF_CreateInstance,
123 DSCF_LockServer
127 /***********************************************************************
128 * DllCanUnloadNow (QEDIT.@)
130 HRESULT WINAPI DllCanUnloadNow(void)
132 return S_OK;
135 /*******************************************************************************
136 * DllGetClassObject [QEDIT.@]
137 * Retrieves class object from a DLL object
139 * PARAMS
140 * rclsid [I] CLSID for the class object
141 * riid [I] Reference to identifier of interface for class object
142 * ppv [O] Address of variable to receive interface pointer for riid
144 * RETURNS
145 * Success: S_OK
146 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
147 * E_UNEXPECTED, E_NOINTERFACE
150 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
152 unsigned int i;
153 IClassFactoryImpl *factory;
155 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
157 if ( !IsEqualGUID( &IID_IClassFactory, riid )
158 && ! IsEqualGUID( &IID_IUnknown, riid) )
159 return E_NOINTERFACE;
161 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
163 if (IsEqualGUID(object_creation[i].clsid, rclsid))
164 break;
167 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
169 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
170 return CLASS_E_CLASSNOTAVAILABLE;
173 factory = CoTaskMemAlloc(sizeof(*factory));
174 if (factory == NULL) return E_OUTOFMEMORY;
176 factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
177 factory->ref = 1;
179 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
181 *ppv = &(factory->ITF_IClassFactory);
182 return S_OK;