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