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 /******************************************************************************
44 * DirectX File ClassFactory
47 IClassFactory IClassFactory_iface
;
50 HRESULT (*pfnCreateInstance
)(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
53 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
55 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
58 struct object_creation_info
61 HRESULT (*pfnCreateInstance
)(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
64 static const struct object_creation_info object_creation
[] =
66 { &CLSID_CDirectXFile
, IDirectXFileImpl_Create
},
69 static HRESULT WINAPI
XFCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
, LPVOID
*ppobj
)
71 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
73 if (IsEqualGUID(riid
, &IID_IUnknown
)
74 || IsEqualGUID(riid
, &IID_IClassFactory
))
76 IClassFactory_AddRef(iface
);
77 *ppobj
= &This
->IClassFactory_iface
;
81 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
85 static ULONG WINAPI
XFCF_AddRef(LPCLASSFACTORY iface
)
87 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
88 return InterlockedIncrement(&This
->ref
);
91 static ULONG WINAPI
XFCF_Release(LPCLASSFACTORY iface
)
93 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
95 ULONG ref
= InterlockedDecrement(&This
->ref
);
98 HeapFree(GetProcessHeap(), 0, This
);
103 static HRESULT WINAPI
XFCF_CreateInstance(LPCLASSFACTORY iface
, LPUNKNOWN pOuter
, REFIID riid
, LPVOID
*ppobj
)
105 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
109 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
112 hres
= This
->pfnCreateInstance(pOuter
, (LPVOID
*) &punk
);
113 if (SUCCEEDED(hres
)) {
114 hres
= IUnknown_QueryInterface(punk
, riid
, ppobj
);
115 IUnknown_Release(punk
);
120 static HRESULT WINAPI
XFCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
122 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
123 FIXME("(%p)->(%d), stub!\n",This
,dolock
);
127 static const IClassFactoryVtbl XFCF_Vtbl
=
136 /***********************************************************************
137 * DirectXFileCreate (D3DXOF.@)
139 HRESULT WINAPI
DirectXFileCreate(LPDIRECTXFILE
* lplpDirectXFile
)
143 TRACE("(%p)\n", lplpDirectXFile
);
145 if (!lplpDirectXFile
)
146 return DXFILEERR_BADVALUE
;
148 hr
= IDirectXFileImpl_Create(NULL
, (LPVOID
)lplpDirectXFile
);
151 return DXFILEERR_BADALLOC
;
156 /*******************************************************************************
157 * DllGetClassObject [D3DXOF.@]
158 * Retrieves class object from a DLL object
161 * Docs say returns STDAPI
164 * rclsid [I] CLSID for the class object
165 * riid [I] Reference to identifier of interface for class object
166 * ppv [O] Address of variable to receive interface pointer for riid
170 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
173 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
176 IClassFactoryImpl
*factory
;
178 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
180 if ( !IsEqualGUID( &IID_IClassFactory
, riid
)
181 && ! IsEqualGUID( &IID_IUnknown
, riid
) )
182 return E_NOINTERFACE
;
184 for (i
= 0; i
< ARRAY_SIZE(object_creation
); i
++)
186 if (IsEqualGUID(object_creation
[i
].clsid
, rclsid
))
190 if (i
== ARRAY_SIZE(object_creation
))
192 FIXME("%s: no class found.\n", debugstr_guid(rclsid
));
193 return CLASS_E_CLASSNOTAVAILABLE
;
196 factory
= HeapAlloc(GetProcessHeap(), 0, sizeof(*factory
));
197 if (factory
== NULL
) return E_OUTOFMEMORY
;
199 factory
->IClassFactory_iface
.lpVtbl
= &XFCF_Vtbl
;
202 factory
->pfnCreateInstance
= object_creation
[i
].pfnCreateInstance
;
204 *ppv
= &(factory
->IClassFactory_iface
);