include: Fix the CDSIZEOF_STRUCT definition to avoid warnings on 64-bit.
[wine.git] / dlls / qedit / main.c
blob40514d5a39b41986940dcca3976c4718b453a0e7
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 "rpcproxy.h"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(qedit);
26 static HINSTANCE instance;
28 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
30 switch(fdwReason) {
31 case DLL_PROCESS_ATTACH:
32 instance = hInstDLL;
33 DisableThreadLibraryCalls(hInstDLL);
34 break;
35 case DLL_PROCESS_DETACH:
36 break;
38 return TRUE;
41 /******************************************************************************
42 * DirectShow ClassFactory
44 typedef struct {
45 IClassFactory IClassFactory_iface;
46 LONG ref;
47 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
48 } IClassFactoryImpl;
50 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
52 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
55 struct object_creation_info
57 const CLSID *clsid;
58 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
61 static const struct object_creation_info object_creation[] =
63 { &CLSID_MediaDet, MediaDet_create },
64 { &CLSID_SampleGrabber, SampleGrabber_create },
67 static HRESULT WINAPI DSCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
69 if (IsEqualGUID(riid, &IID_IUnknown)
70 || IsEqualGUID(riid, &IID_IClassFactory))
72 IClassFactory_AddRef(iface);
73 *ppobj = iface;
74 return S_OK;
77 *ppobj = NULL;
78 WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
79 return E_NOINTERFACE;
82 static ULONG WINAPI DSCF_AddRef(IClassFactory *iface)
84 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
85 return InterlockedIncrement(&This->ref);
88 static ULONG WINAPI DSCF_Release(IClassFactory *iface)
90 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
91 ULONG ref = InterlockedDecrement(&This->ref);
93 if (ref == 0)
94 CoTaskMemFree(This);
96 return ref;
99 static HRESULT WINAPI DSCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter, REFIID riid,
100 void **ppobj)
102 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
103 HRESULT hres;
104 LPUNKNOWN punk;
106 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
108 *ppobj = NULL;
109 if (pOuter && !IsEqualGUID(&IID_IUnknown, riid))
110 return E_INVALIDARG;
112 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
113 if (SUCCEEDED(hres)) {
114 hres = IUnknown_QueryInterface(punk, riid, ppobj);
115 IUnknown_Release(punk);
117 return hres;
120 static HRESULT WINAPI DSCF_LockServer(IClassFactory *iface, BOOL dolock)
122 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
123 FIXME("(%p)->(%d),stub!\n",This,dolock);
124 return S_OK;
127 static const IClassFactoryVtbl DSCF_Vtbl =
129 DSCF_QueryInterface,
130 DSCF_AddRef,
131 DSCF_Release,
132 DSCF_CreateInstance,
133 DSCF_LockServer
137 /***********************************************************************
138 * DllCanUnloadNow (QEDIT.@)
140 HRESULT WINAPI DllCanUnloadNow(void)
142 return S_OK;
145 /*******************************************************************************
146 * DllGetClassObject [QEDIT.@]
147 * Retrieves class object from a DLL object
149 * PARAMS
150 * rclsid [I] CLSID for the class object
151 * riid [I] Reference to identifier of interface for class object
152 * ppv [O] Address of variable to receive interface pointer for riid
154 * RETURNS
155 * Success: S_OK
156 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
157 * E_UNEXPECTED, E_NOINTERFACE
160 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
162 unsigned int i;
163 IClassFactoryImpl *factory;
165 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
167 if ( !IsEqualGUID( &IID_IClassFactory, riid )
168 && ! IsEqualGUID( &IID_IUnknown, riid) )
169 return E_NOINTERFACE;
171 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
173 if (IsEqualGUID(object_creation[i].clsid, rclsid))
174 break;
177 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
179 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
180 return CLASS_E_CLASSNOTAVAILABLE;
183 factory = CoTaskMemAlloc(sizeof(*factory));
184 if (factory == NULL) return E_OUTOFMEMORY;
186 factory->IClassFactory_iface.lpVtbl = &DSCF_Vtbl;
187 factory->ref = 1;
189 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
191 *ppv = &factory->IClassFactory_iface;
192 return S_OK;
195 /***********************************************************************
196 * DllRegisterServer (QEDIT.@)
198 HRESULT WINAPI DllRegisterServer(void)
200 return __wine_register_resources( instance );
203 /***********************************************************************
204 * DllUnregisterServer (QEDIT.@)
206 HRESULT WINAPI DllUnregisterServer(void)
208 return __wine_unregister_resources( instance );