wined3d: Get rid of the remaining WINED3DSP_REGNUM_MASK usage.
[wine] / dlls / qedit / main.c
1 /*              DirectShow Editing Services (qedit.dll)
2  *
3  * Copyright 2008 Google (Lei Zhang)
4  *
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.
9  *
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.
14  *
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
18  */
19
20 #include "qedit_private.h"
21 #include "wine/debug.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(qedit);
24
25 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
26 {
27     switch(fdwReason) {
28         case DLL_PROCESS_ATTACH:
29             DisableThreadLibraryCalls(hInstDLL);
30             break;
31         case DLL_PROCESS_DETACH:
32             break;
33     }
34     return TRUE;
35 }
36
37 /******************************************************************************
38  * DirectShow ClassFactory
39  */
40 typedef struct {
41     IClassFactory ITF_IClassFactory;
42
43     LONG ref;
44     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
45 } IClassFactoryImpl;
46
47 struct object_creation_info
48 {
49     const CLSID *clsid;
50     HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
51 };
52
53 static const struct object_creation_info object_creation[] =
54 {
55     { &CLSID_MediaDet, MediaDet_create },
56 };
57
58 static HRESULT WINAPI
59 DSCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid,LPVOID *ppobj)
60 {
61     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
62
63     if (IsEqualGUID(riid, &IID_IUnknown)
64         || IsEqualGUID(riid, &IID_IClassFactory))
65     {
66         IClassFactory_AddRef(iface);
67         *ppobj = This;
68         return S_OK;
69     }
70
71     *ppobj = NULL;
72     WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
73     return E_NOINTERFACE;
74 }
75
76 static ULONG WINAPI DSCF_AddRef(LPCLASSFACTORY iface)
77 {
78     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
79     return InterlockedIncrement(&This->ref);
80 }
81
82 static ULONG WINAPI DSCF_Release(LPCLASSFACTORY iface)
83 {
84     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
85
86     ULONG ref = InterlockedDecrement(&This->ref);
87
88     if (ref == 0)
89         CoTaskMemFree(This);
90
91     return ref;
92 }
93
94 static HRESULT WINAPI DSCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
95 {
96     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
97     HRESULT hres;
98     LPUNKNOWN punk;
99
100     TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
101
102     *ppobj = NULL;
103     hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
104     if (SUCCEEDED(hres)) {
105         hres = IUnknown_QueryInterface(punk, riid, ppobj);
106         IUnknown_Release(punk);
107     }
108     return hres;
109 }
110
111 static HRESULT WINAPI DSCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
112 {
113     IClassFactoryImpl *This = (IClassFactoryImpl *)iface;
114     FIXME("(%p)->(%d),stub!\n",This,dolock);
115     return S_OK;
116 }
117
118 static const IClassFactoryVtbl DSCF_Vtbl =
119 {
120     DSCF_QueryInterface,
121     DSCF_AddRef,
122     DSCF_Release,
123     DSCF_CreateInstance,
124     DSCF_LockServer
125 };
126
127
128 /***********************************************************************
129  *              DllCanUnloadNow (QEDIT.@)
130  */
131 HRESULT WINAPI DllCanUnloadNow(void)
132 {
133     return S_OK;
134 }
135
136 /*******************************************************************************
137  * DllGetClassObject [QEDIT.@]
138  * Retrieves class object from a DLL object
139  *
140  * PARAMS
141  *    rclsid [I] CLSID for the class object
142  *    riid   [I] Reference to identifier of interface for class object
143  *    ppv    [O] Address of variable to receive interface pointer for riid
144  *
145  * RETURNS
146  *    Success: S_OK
147  *    Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
148  *             E_UNEXPECTED, E_NOINTERFACE
149  */
150
151 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
152 {
153     unsigned int i;
154     IClassFactoryImpl *factory;
155
156     TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
157
158     if ( !IsEqualGUID( &IID_IClassFactory, riid )
159          && ! IsEqualGUID( &IID_IUnknown, riid) )
160         return E_NOINTERFACE;
161
162     for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
163     {
164         if (IsEqualGUID(object_creation[i].clsid, rclsid))
165             break;
166     }
167
168     if (i == sizeof(object_creation)/sizeof(object_creation[0]))
169     {
170         FIXME("%s: no class found.\n", debugstr_guid(rclsid));
171         return CLASS_E_CLASSNOTAVAILABLE;
172     }
173
174     factory = CoTaskMemAlloc(sizeof(*factory));
175     if (factory == NULL) return E_OUTOFMEMORY;
176
177     factory->ITF_IClassFactory.lpVtbl = &DSCF_Vtbl;
178     factory->ref = 1;
179
180     factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
181
182     *ppv = &(factory->ITF_IClassFactory);
183     return S_OK;
184 }