xref: /reactos/dll/directx/wine/qedit/main.c (revision 698fd79d)
1c2c66affSColin Finck /*              DirectShow Editing Services (qedit.dll)
2c2c66affSColin Finck  *
3c2c66affSColin Finck  * Copyright 2008 Google (Lei Zhang)
4c2c66affSColin Finck  *
5c2c66affSColin Finck  * This library is free software; you can redistribute it and/or
6c2c66affSColin Finck  * modify it under the terms of the GNU Lesser General Public
7c2c66affSColin Finck  * License as published by the Free Software Foundation; either
8c2c66affSColin Finck  * version 2.1 of the License, or (at your option) any later version.
9c2c66affSColin Finck  *
10c2c66affSColin Finck  * This library is distributed in the hope that it will be useful,
11c2c66affSColin Finck  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12c2c66affSColin Finck  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13c2c66affSColin Finck  * Lesser General Public License for more details.
14c2c66affSColin Finck  *
15c2c66affSColin Finck  * You should have received a copy of the GNU Lesser General Public
16c2c66affSColin Finck  * License along with this library; if not, write to the Free Software
17c2c66affSColin Finck  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18c2c66affSColin Finck  */
19c2c66affSColin Finck 
20c2c66affSColin Finck #include "qedit_private.h"
21d3e7f8ddSAmine Khaldi #include "rpcproxy.h"
22d3e7f8ddSAmine Khaldi #include "wine/debug.h"
23c2c66affSColin Finck 
24d3e7f8ddSAmine Khaldi WINE_DEFAULT_DEBUG_CHANNEL(qedit);
25c2c66affSColin Finck 
26c2c66affSColin Finck static HINSTANCE instance;
27c2c66affSColin Finck 
DllMain(HINSTANCE hInstDLL,DWORD fdwReason,LPVOID lpv)28c2c66affSColin Finck BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
29c2c66affSColin Finck {
30c2c66affSColin Finck     switch(fdwReason) {
31c2c66affSColin Finck         case DLL_PROCESS_ATTACH:
32c2c66affSColin Finck             instance = hInstDLL;
33c2c66affSColin Finck             DisableThreadLibraryCalls(hInstDLL);
34c2c66affSColin Finck             break;
35c2c66affSColin Finck     }
36c2c66affSColin Finck     return TRUE;
37c2c66affSColin Finck }
38c2c66affSColin Finck 
39c2c66affSColin Finck /******************************************************************************
40c2c66affSColin Finck  * DirectShow ClassFactory
41c2c66affSColin Finck  */
42c2c66affSColin Finck typedef struct {
43c2c66affSColin Finck     IClassFactory IClassFactory_iface;
44c2c66affSColin Finck     LONG ref;
45c2c66affSColin Finck     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
46c2c66affSColin Finck } IClassFactoryImpl;
47c2c66affSColin Finck 
impl_from_IClassFactory(IClassFactory * iface)48c2c66affSColin Finck static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
49c2c66affSColin Finck {
50c2c66affSColin Finck     return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
51c2c66affSColin Finck }
52c2c66affSColin Finck 
53c2c66affSColin Finck struct object_creation_info
54c2c66affSColin Finck {
55c2c66affSColin Finck     const CLSID *clsid;
56c2c66affSColin Finck     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
57c2c66affSColin Finck };
58c2c66affSColin Finck 
59c2c66affSColin Finck static const struct object_creation_info object_creation[] =
60c2c66affSColin Finck {
61c2c66affSColin Finck     { &CLSID_AMTimeline, AMTimeline_create },
62c2c66affSColin Finck     { &CLSID_MediaDet, MediaDet_create },
63c2c66affSColin Finck     { &CLSID_SampleGrabber, SampleGrabber_create },
64c2c66affSColin Finck };
65c2c66affSColin Finck 
DSCF_QueryInterface(IClassFactory * iface,REFIID riid,void ** ppobj)66c2c66affSColin Finck static HRESULT WINAPI DSCF_QueryInterface(IClassFactory *iface, REFIID riid, void **ppobj)
67c2c66affSColin Finck {
68c2c66affSColin Finck     if (IsEqualGUID(riid, &IID_IUnknown)
69c2c66affSColin Finck         || IsEqualGUID(riid, &IID_IClassFactory))
70c2c66affSColin Finck     {
71c2c66affSColin Finck         IClassFactory_AddRef(iface);
72c2c66affSColin Finck         *ppobj = iface;
73c2c66affSColin Finck         return S_OK;
74c2c66affSColin Finck     }
75c2c66affSColin Finck 
76c2c66affSColin Finck     *ppobj = NULL;
77c2c66affSColin Finck     WARN("(%p)->(%s,%p), not found\n", iface, debugstr_guid(riid), ppobj);
78c2c66affSColin Finck     return E_NOINTERFACE;
79c2c66affSColin Finck }
80c2c66affSColin Finck 
DSCF_AddRef(IClassFactory * iface)81c2c66affSColin Finck static ULONG WINAPI DSCF_AddRef(IClassFactory *iface)
82c2c66affSColin Finck {
83c2c66affSColin Finck     IClassFactoryImpl *This = impl_from_IClassFactory(iface);
84c2c66affSColin Finck     return InterlockedIncrement(&This->ref);
85c2c66affSColin Finck }
86c2c66affSColin Finck 
DSCF_Release(IClassFactory * iface)87c2c66affSColin Finck static ULONG WINAPI DSCF_Release(IClassFactory *iface)
88c2c66affSColin Finck {
89c2c66affSColin Finck     IClassFactoryImpl *This = impl_from_IClassFactory(iface);
90c2c66affSColin Finck     ULONG ref = InterlockedDecrement(&This->ref);
91c2c66affSColin Finck 
92c2c66affSColin Finck     if (ref == 0)
93c2c66affSColin Finck         CoTaskMemFree(This);
94c2c66affSColin Finck 
95c2c66affSColin Finck     return ref;
96c2c66affSColin Finck }
97c2c66affSColin Finck 
DSCF_CreateInstance(IClassFactory * iface,IUnknown * pOuter,REFIID riid,void ** ppobj)98c2c66affSColin Finck static HRESULT WINAPI DSCF_CreateInstance(IClassFactory *iface, IUnknown *pOuter, REFIID riid,
99c2c66affSColin Finck         void **ppobj)
100c2c66affSColin Finck {
101c2c66affSColin Finck     IClassFactoryImpl *This = impl_from_IClassFactory(iface);
102c2c66affSColin Finck     HRESULT hres;
103c2c66affSColin Finck     LPUNKNOWN punk;
104c2c66affSColin Finck 
105c2c66affSColin Finck     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
106c2c66affSColin Finck 
107c2c66affSColin Finck     *ppobj = NULL;
108c2c66affSColin Finck     if (pOuter && !IsEqualGUID(&IID_IUnknown, riid))
109c2c66affSColin Finck         return E_INVALIDARG;
110c2c66affSColin Finck 
111c2c66affSColin Finck     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
112c2c66affSColin Finck     if (SUCCEEDED(hres)) {
113c2c66affSColin Finck         hres = IUnknown_QueryInterface(punk, riid, ppobj);
114c2c66affSColin Finck         IUnknown_Release(punk);
115c2c66affSColin Finck     }
116c2c66affSColin Finck     return hres;
117c2c66affSColin Finck }
118c2c66affSColin Finck 
DSCF_LockServer(IClassFactory * iface,BOOL dolock)119c2c66affSColin Finck static HRESULT WINAPI DSCF_LockServer(IClassFactory *iface, BOOL dolock)
120c2c66affSColin Finck {
121c2c66affSColin Finck     IClassFactoryImpl *This = impl_from_IClassFactory(iface);
122c2c66affSColin Finck     FIXME("(%p)->(%d),stub!\n",This,dolock);
123c2c66affSColin Finck     return S_OK;
124c2c66affSColin Finck }
125c2c66affSColin Finck 
126c2c66affSColin Finck static const IClassFactoryVtbl DSCF_Vtbl =
127c2c66affSColin Finck {
128c2c66affSColin Finck     DSCF_QueryInterface,
129c2c66affSColin Finck     DSCF_AddRef,
130c2c66affSColin Finck     DSCF_Release,
131c2c66affSColin Finck     DSCF_CreateInstance,
132c2c66affSColin Finck     DSCF_LockServer
133c2c66affSColin Finck };
134c2c66affSColin Finck 
135c2c66affSColin Finck 
136c2c66affSColin Finck /***********************************************************************
137c2c66affSColin Finck  *              DllCanUnloadNow (QEDIT.@)
138c2c66affSColin Finck  */
DllCanUnloadNow(void)139c2c66affSColin Finck HRESULT WINAPI DllCanUnloadNow(void)
140c2c66affSColin Finck {
141c2c66affSColin Finck     return S_FALSE;
142c2c66affSColin Finck }
143c2c66affSColin Finck 
144c2c66affSColin Finck /*******************************************************************************
145c2c66affSColin Finck  * DllGetClassObject [QEDIT.@]
146c2c66affSColin Finck  * Retrieves class object from a DLL object
147c2c66affSColin Finck  *
148c2c66affSColin Finck  * PARAMS
149c2c66affSColin Finck  *    rclsid [I] CLSID for the class object
150c2c66affSColin Finck  *    riid   [I] Reference to identifier of interface for class object
151c2c66affSColin Finck  *    ppv    [O] Address of variable to receive interface pointer for riid
152c2c66affSColin Finck  *
153c2c66affSColin Finck  * RETURNS
154c2c66affSColin Finck  *    Success: S_OK
155c2c66affSColin Finck  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
156c2c66affSColin Finck  *             E_UNEXPECTED, E_NOINTERFACE
157c2c66affSColin Finck  */
158c2c66affSColin Finck 
DllGetClassObject(REFCLSID rclsid,REFIID riid,LPVOID * ppv)159c2c66affSColin Finck HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
160c2c66affSColin Finck {
161c2c66affSColin Finck     unsigned int i;
162c2c66affSColin Finck     IClassFactoryImpl *factory;
163c2c66affSColin Finck 
164c2c66affSColin Finck     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
165c2c66affSColin Finck 
166c2c66affSColin Finck     if ( !IsEqualGUID( &IID_IClassFactory, riid )
167c2c66affSColin Finck          && ! IsEqualGUID( &IID_IUnknown, riid) )
168c2c66affSColin Finck         return E_NOINTERFACE;
169c2c66affSColin Finck 
170*698fd79dSAmine Khaldi     for (i = 0; i < ARRAY_SIZE(object_creation); i++)
171c2c66affSColin Finck     {
172c2c66affSColin Finck         if (IsEqualGUID(object_creation[i].clsid, rclsid))
173c2c66affSColin Finck             break;
174c2c66affSColin Finck     }
175c2c66affSColin Finck 
176*698fd79dSAmine Khaldi     if (i == ARRAY_SIZE(object_creation))
177c2c66affSColin Finck     {
178c2c66affSColin Finck         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
179c2c66affSColin Finck         return CLASS_E_CLASSNOTAVAILABLE;
180c2c66affSColin Finck     }
181c2c66affSColin Finck 
182c2c66affSColin Finck     factory = CoTaskMemAlloc(sizeof(*factory));
183c2c66affSColin Finck     if (factory == NULL) return E_OUTOFMEMORY;
184c2c66affSColin Finck 
185c2c66affSColin Finck     factory->IClassFactory_iface.lpVtbl = &DSCF_Vtbl;
186c2c66affSColin Finck     factory->ref = 1;
187c2c66affSColin Finck 
188c2c66affSColin Finck     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
189c2c66affSColin Finck 
190c2c66affSColin Finck     *ppv = &factory->IClassFactory_iface;
191c2c66affSColin Finck     return S_OK;
192c2c66affSColin Finck }
193c2c66affSColin Finck 
194c2c66affSColin Finck /***********************************************************************
195c2c66affSColin Finck  *		DllRegisterServer (QEDIT.@)
196c2c66affSColin Finck  */
DllRegisterServer(void)197c2c66affSColin Finck HRESULT WINAPI DllRegisterServer(void)
198c2c66affSColin Finck {
199c2c66affSColin Finck     return __wine_register_resources( instance );
200c2c66affSColin Finck }
201c2c66affSColin Finck 
202c2c66affSColin Finck /***********************************************************************
203c2c66affSColin Finck  *		DllUnregisterServer (QEDIT.@)
204c2c66affSColin Finck  */
DllUnregisterServer(void)205c2c66affSColin Finck HRESULT WINAPI DllUnregisterServer(void)
206c2c66affSColin Finck {
207c2c66affSColin Finck     return __wine_unregister_resources( instance );
208c2c66affSColin Finck }
209