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 "d3dxof_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3dxof
);
25 /******************************************************************************
26 * DirectX File ClassFactory
29 IClassFactory IClassFactory_iface
;
32 HRESULT (*pfnCreateInstance
)(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
35 static inline IClassFactoryImpl
*impl_from_IClassFactory(IClassFactory
*iface
)
37 return CONTAINING_RECORD(iface
, IClassFactoryImpl
, IClassFactory_iface
);
40 struct object_creation_info
43 HRESULT (*pfnCreateInstance
)(IUnknown
*pUnkOuter
, LPVOID
*ppObj
);
46 static const struct object_creation_info object_creation
[] =
48 { &CLSID_CDirectXFile
, IDirectXFileImpl_Create
},
51 static HRESULT WINAPI
XFCF_QueryInterface(LPCLASSFACTORY iface
,REFIID riid
, LPVOID
*ppobj
)
53 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
55 if (IsEqualGUID(riid
, &IID_IUnknown
)
56 || IsEqualGUID(riid
, &IID_IClassFactory
))
58 IClassFactory_AddRef(iface
);
59 *ppobj
= &This
->IClassFactory_iface
;
63 WARN("(%p)->(%s,%p),not found\n",This
,debugstr_guid(riid
),ppobj
);
67 static ULONG WINAPI
XFCF_AddRef(LPCLASSFACTORY iface
)
69 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
70 return InterlockedIncrement(&This
->ref
);
73 static ULONG WINAPI
XFCF_Release(LPCLASSFACTORY iface
)
75 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
77 ULONG ref
= InterlockedDecrement(&This
->ref
);
80 HeapFree(GetProcessHeap(), 0, This
);
85 static HRESULT WINAPI
XFCF_CreateInstance(LPCLASSFACTORY iface
, LPUNKNOWN pOuter
, REFIID riid
, LPVOID
*ppobj
)
87 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
91 TRACE("(%p)->(%p,%s,%p)\n",This
,pOuter
,debugstr_guid(riid
),ppobj
);
94 hres
= This
->pfnCreateInstance(pOuter
, (LPVOID
*) &punk
);
95 if (SUCCEEDED(hres
)) {
96 hres
= IUnknown_QueryInterface(punk
, riid
, ppobj
);
97 IUnknown_Release(punk
);
102 static HRESULT WINAPI
XFCF_LockServer(LPCLASSFACTORY iface
, BOOL dolock
)
104 IClassFactoryImpl
*This
= impl_from_IClassFactory(iface
);
105 FIXME("(%p)->(%d), stub!\n",This
,dolock
);
109 static const IClassFactoryVtbl XFCF_Vtbl
=
118 /***********************************************************************
119 * DirectXFileCreate (D3DXOF.@)
121 HRESULT WINAPI
DirectXFileCreate(LPDIRECTXFILE
* lplpDirectXFile
)
125 TRACE("(%p)\n", lplpDirectXFile
);
127 if (!lplpDirectXFile
)
128 return DXFILEERR_BADVALUE
;
130 hr
= IDirectXFileImpl_Create(NULL
, (LPVOID
)lplpDirectXFile
);
133 return DXFILEERR_BADALLOC
;
138 /*******************************************************************************
139 * DllGetClassObject [D3DXOF.@]
140 * Retrieves class object from a DLL object
143 * Docs say returns STDAPI
146 * rclsid [I] CLSID for the class object
147 * riid [I] Reference to identifier of interface for class object
148 * ppv [O] Address of variable to receive interface pointer for riid
152 * Failure: CLASS_E_CLASSNOTAVAILABLE, E_OUTOFMEMORY, E_INVALIDARG,
155 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
158 IClassFactoryImpl
*factory
;
160 TRACE("(%s,%s,%p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
162 if ( !IsEqualGUID( &IID_IClassFactory
, riid
)
163 && ! IsEqualGUID( &IID_IUnknown
, riid
) )
164 return E_NOINTERFACE
;
166 for (i
= 0; i
< ARRAY_SIZE(object_creation
); i
++)
168 if (IsEqualGUID(object_creation
[i
].clsid
, rclsid
))
172 if (i
== ARRAY_SIZE(object_creation
))
174 FIXME("%s: no class found.\n", debugstr_guid(rclsid
));
175 return CLASS_E_CLASSNOTAVAILABLE
;
178 factory
= HeapAlloc(GetProcessHeap(), 0, sizeof(*factory
));
179 if (factory
== NULL
) return E_OUTOFMEMORY
;
181 factory
->IClassFactory_iface
.lpVtbl
= &XFCF_Vtbl
;
184 factory
->pfnCreateInstance
= object_creation
[i
].pfnCreateInstance
;
186 *ppv
= &(factory
->IClassFactory_iface
);