wined3d: Figure out the index data pointer inside drawPrimitive().
[wine/multimedia.git] / dlls / d3dxof / main.c
blob9ca7103b6ee68d072d20e7d91cd3d0f73f643722
1 /*
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
21 #include <stdarg.h>
22 #include <string.h>
24 #define COBJMACROS
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winuser.h"
29 #include "winreg.h"
30 #include "winerror.h"
32 #include "ole2.h"
33 #include "rpcproxy.h"
34 #include "uuids.h"
36 #include "d3dxof_private.h"
37 #include "dxfile.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)
49 switch(fdwReason) {
50 case DLL_PROCESS_ATTACH:
51 instance = hInstDLL;
52 DisableThreadLibraryCalls(hInstDLL);
53 break;
54 case DLL_PROCESS_DETACH:
55 break;
57 return TRUE;
60 /******************************************************************************
61 * DirectX File ClassFactory
63 typedef struct {
64 IClassFactory IClassFactory_iface;
66 LONG ref;
67 HRESULT (*pfnCreateInstance)(IUnknown *pUnkOuter, LPVOID *ppObj);
68 } IClassFactoryImpl;
70 static inline IClassFactoryImpl *impl_from_IClassFactory(IClassFactory *iface)
72 return CONTAINING_RECORD(iface, IClassFactoryImpl, IClassFactory_iface);
75 struct object_creation_info
77 const CLSID *clsid;
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;
95 return S_OK;
98 WARN("(%p)->(%s,%p),not found\n",This,debugstr_guid(riid),ppobj);
99 return E_NOINTERFACE;
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);
114 if (ref == 0)
115 HeapFree(GetProcessHeap(), 0, This);
117 return ref;
120 static HRESULT WINAPI XFCF_CreateInstance(LPCLASSFACTORY iface, LPUNKNOWN pOuter, REFIID riid, LPVOID *ppobj)
122 IClassFactoryImpl *This = impl_from_IClassFactory(iface);
123 HRESULT hres;
124 LPUNKNOWN punk;
126 TRACE("(%p)->(%p,%s,%p)\n",This,pOuter,debugstr_guid(riid),ppobj);
128 *ppobj = NULL;
129 hres = This->pfnCreateInstance(pOuter, (LPVOID *) &punk);
130 if (SUCCEEDED(hres)) {
131 hres = IUnknown_QueryInterface(punk, riid, ppobj);
132 IUnknown_Release(punk);
134 return hres;
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);
141 return S_OK;
144 static const IClassFactoryVtbl XFCF_Vtbl =
146 XFCF_QueryInterface,
147 XFCF_AddRef,
148 XFCF_Release,
149 XFCF_CreateInstance,
150 XFCF_LockServer
153 /***********************************************************************
154 * DirectXFileCreate (D3DXOF.@)
156 HRESULT WINAPI DirectXFileCreate(LPDIRECTXFILE* lplpDirectXFile)
158 HRESULT hr;
160 TRACE("(%p)\n", lplpDirectXFile);
162 if (!lplpDirectXFile)
163 return DXFILEERR_BADVALUE;
165 hr = IDirectXFileImpl_Create(NULL, (LPVOID)lplpDirectXFile);
167 if (FAILED(hr))
168 return DXFILEERR_BADALLOC;
170 return S_OK;
173 /*******************************************************************************
174 * DllGetClassObject [D3DXOF.@]
175 * Retrieves class object from a DLL object
177 * NOTES
178 * Docs say returns STDAPI
180 * PARAMS
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
185 * RETURNS
186 * Success: S_OK
187 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
188 * E_UNEXPECTED
190 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
192 unsigned int i;
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))
204 break;
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;
217 factory->ref = 1;
219 factory->pfnCreateInstance = object_creation[i].pfnCreateInstance;
221 *ppv = &(factory->IClassFactory_iface);
222 return S_OK;
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 );