2 * DirectX Files Functions (D3DXOF.DLL)
4 * Copyright 2004 Christian Costa
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.
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.
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
36 #include "d3dxof_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(d3dxof);
43 static HINSTANCE instance;
44 static LONG dll_ref = 0;
46 /* For the moment, do nothing here. */
47 BOOL WINAPI DllMain(HINSTANCE hInstDLL, DWORD fdwReason, LPVOID lpv)
50 case DLL_PROCESS_ATTACH:
52 DisableThreadLibraryCalls(hInstDLL);
54 case DLL_PROCESS_DETACH:
60 /******************************************************************************
61 * DirectX File ClassFactory
64 IClassFactory IClassFactory_iface;
67 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
70 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
72 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
75 struct object_creation_info
78 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
81 static const struct object_creation_info object_creation[] =
83 { &CLSID_CDirectXFile, IDirectXFileImpl_Create },
86 static HRESULT WINAPI XFCF_QueryInterface(LPCLASSFACTORY iface,REFIID riid, LPVOID *ppobj)
88 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
90 if (IsEqualGUID(riid, &IID_IUnknown)
91 || IsEqualGUID(riid, &IID_IClassFactory))
93 IClassFactory_AddRef(iface);
94 *ppobj = &This->IClassFactory_iface;
98 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
102 static ULONG WINAPI XFCF_AddRef(LPCLASSFACTORY iface)
104 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
105 return InterlockedIncrement(&This->ref);
108 static ULONG WINAPI XFCF_Release(LPCLASSFACTORY iface)
110 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
112 ULONG ref = InterlockedDecrement(&This->ref);
115 HeapFree(GetProcessHeap(), 0, This);
120 static HRESULT WINAPI XFCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
122 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
126 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
129 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
130 if (SUCCEEDED(hres)) {
131 hres = IUnknown_QueryInterface(punk, riid, ppobj);
132 IUnknown_Release(punk);
137 static HRESULT WINAPI XFCF_LockServer(LPCLASSFACTORY iface, BOOL dolock)
139 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
140 FIXME("(%p)->(%d),stub!\n",This,dolock);
144 static const IClassFactoryVtbl XFCF_Vtbl =
153 /***********************************************************************
154 * DirectXFileCreate (D3DXOF.@)
156 HRESULT WINAPI DirectXFileCreate(LPDIRECTXFILE* lplpDirectXFile)
160 TRACE("(%p)\n", lplpDirectXFile);
162 if (!lplpDirectXFile)
163 return DXFILEERR_BADVALUE;
165 hr = IDirectXFileImpl_Create(NULL, (LPVOID)lplpDirectXFile);
168 return DXFILEERR_BADALLOC;
173 /*******************************************************************************
174 * DllGetClassObject [D3DXOF.@]
175 * Retrieves class object from a DLL object
178 * Docs say returns STDAPI
181 * rclsid [I] CLSID for the class object
182 * riid [I] Reference to identifier of interface for class object
183 * ppv [O] Address of variable to receive interface pointer for riid
187 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
190 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
193 IClassFactoryImpl *factory;
195 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
197 if ( !IsEqualGUID( &IID_IClassFactory, riid )
198 && ! IsEqualGUID( &IID_IUnknown, riid) )
199 return E_NOINTERFACE;
201 for (i=0; i < sizeof(object_creation)/sizeof(object_creation[0]); i++)
203 if (IsEqualGUID(object_creation[i].clsid, rclsid))
207 if (i == sizeof(object_creation)/sizeof(object_creation[0]))
209 FIXME("%s: no class found.\n", debugstr_guid(rclsid));
210 return CLASS_E_CLASSNOTAVAILABLE;
213 factory = HeapAlloc(GetProcessHeap(), 0, sizeof(*factory));
214 if (factory == NULL) return E_OUTOFMEMORY;
216 factory->IClassFactory_iface.lpVtbl = &XFCF_Vtbl;
219 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
221 *ppv = &(factory->IClassFactory_iface);
225 /***********************************************************************
226 * DllCanUnloadNow (D3DXOF.@)
228 HRESULT WINAPI DllCanUnloadNow(void)
230 return dll_ref != 0 ? S_FALSE : S_OK;
233 /***********************************************************************
234 * DllRegisterServer (D3DXOF.@)
236 HRESULT WINAPI DllRegisterServer(void)
238 return __wine_register_resources( instance );
241 /***********************************************************************
242 * DllUnregisterServer (D3DXOF.@)
244 HRESULT WINAPI DllUnregisterServer(void)
246 return __wine_unregister_resources( instance );