Added regedit unit test, a couple minor changes to regedit.
[wine] / dlls / ddraw / direct3d / main.c
1 /*
2  * Copyright 2000 Marcus Meissner
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "config.h"
20
21 #include <assert.h>
22 #include <unistd.h>
23 #include <fcntl.h>
24 #include <string.h>
25 #include <stdio.h>
26
27 #include "winerror.h"
28 #include "ddraw.h"
29 #include "d3d.h"
30 #include "wine/debug.h"
31
32 #include "d3d_private.h"
33
34 WINE_DEFAULT_DEBUG_CHANNEL(ddraw);
35
36 static ICOM_VTABLE(IDirect3D) d3dvt;
37 static ICOM_VTABLE(IDirect3D2) d3d2vt;
38
39 /*******************************************************************************
40  *                              IDirect3D
41  */
42 HRESULT WINAPI IDirect3DImpl_QueryInterface(
43     LPDIRECT3D iface,REFIID refiid,LPVOID *obj
44 ) {
45     ICOM_THIS(IDirect3DImpl,iface);
46     /* FIXME: Not sure if this is correct */
47
48     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
49     if (( IsEqualGUID( &IID_IDirectDraw,  refiid ) ) ||
50         ( IsEqualGUID (&IID_IDirectDraw2, refiid ) ) ||
51         ( IsEqualGUID( &IID_IDirectDraw4, refiid ) )
52     ) {
53         *obj = This->ddraw;
54         IDirect3D_AddRef(iface);
55         TRACE("  Creating IDirectDrawX interface (%p)\n", *obj);
56         return S_OK;
57     }
58     if (( IsEqualGUID( &IID_IDirect3D, refiid ) ) ||
59         ( IsEqualGUID( &IID_IUnknown,  refiid ) ) ) {
60         *obj = This;
61         IDirect3D_AddRef(iface);
62         TRACE("  Creating IDirect3D interface (%p)\n", *obj);
63         return S_OK;
64     }
65     if ( IsEqualGUID( &IID_IDirect3D2, refiid ) ) {
66         IDirect3D2Impl*  d3d;
67
68         d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
69         d3d->ref = 1;
70         d3d->ddraw = This->ddraw;
71         IDirect3D_AddRef(iface);
72         ICOM_VTBL(d3d) = &d3d2vt;
73         *obj = d3d;
74         TRACE("  Creating IDirect3D2 interface (%p)\n", *obj);
75         return S_OK;
76     }
77     FIXME("(%p):interface for IID %s NOT found!\n",This,debugstr_guid(refiid));
78     return OLE_E_ENUM_NOMORE;
79 }
80
81 ULONG WINAPI IDirect3DImpl_AddRef(LPDIRECT3D iface) {
82     ICOM_THIS(IDirect3DImpl,iface);
83     TRACE("(%p)->() incrementing from %lu.\n", This, This->ref );
84
85     return ++(This->ref);
86 }
87
88 ULONG WINAPI IDirect3DImpl_Release(LPDIRECT3D iface)
89 {
90     ICOM_THIS(IDirect3DImpl,iface);
91     TRACE("(%p)->() decrementing from %lu.\n", This, This->ref );
92
93     if (!--(This->ref)) {
94         IDirectDraw2_Release((IDirectDraw2*)This->ddraw);
95         HeapFree(GetProcessHeap(),0,This);
96         return S_OK;
97     }
98     return This->ref;
99 }
100
101 HRESULT WINAPI IDirect3DImpl_Initialize(LPDIRECT3D iface,REFIID refiid) {
102     ICOM_THIS(IDirect3DImpl,iface);
103     /* FIXME: Not sure if this is correct */
104     FIXME("(%p)->(%s):stub.\n",This,debugstr_guid(refiid));
105     return DDERR_ALREADYINITIALIZED;
106 }
107
108 HRESULT WINAPI IDirect3DImpl_EnumDevices(
109     LPDIRECT3D iface, LPD3DENUMDEVICESCALLBACK cb, LPVOID context
110 ) {
111     ICOM_THIS(IDirect3DImpl,iface);
112     FIXME("(%p)->(%p,%p),stub!\n",This,cb,context);
113     return DD_OK;
114 }
115
116 HRESULT WINAPI IDirect3DImpl_CreateLight(
117     LPDIRECT3D iface, LPDIRECT3DLIGHT *lplight, IUnknown *lpunk
118 ) {
119     ICOM_THIS(IDirect3DImpl,iface);
120     FIXME("(%p)->(%p,%p): stub\n", This, lplight, lpunk);
121     return E_FAIL;
122 }
123
124 HRESULT WINAPI IDirect3DImpl_CreateMaterial(
125     LPDIRECT3D iface, LPDIRECT3DMATERIAL *lpmaterial, IUnknown *lpunk
126 ) {
127     ICOM_THIS(IDirect3DImpl,iface);
128     FIXME("(%p)->(%p,%p): stub\n", This, lpmaterial, lpunk);
129     return E_FAIL;
130 }
131
132 HRESULT WINAPI IDirect3DImpl_CreateViewport(
133     LPDIRECT3D iface, LPDIRECT3DVIEWPORT *lpviewport, IUnknown *lpunk
134 ) {
135     ICOM_THIS(IDirect3DImpl,iface);
136     FIXME("(%p)->(%p,%p): stub\n", This, lpviewport, lpunk);
137
138     return E_FAIL;
139 }
140
141 HRESULT WINAPI IDirect3DImpl_FindDevice(
142     LPDIRECT3D iface, LPD3DFINDDEVICESEARCH lpfinddevsrc,
143     LPD3DFINDDEVICERESULT lpfinddevrst)
144 {
145     ICOM_THIS(IDirect3DImpl,iface);
146     FIXME("(%p)->(%p,%p): stub\n", This, lpfinddevsrc, lpfinddevrst);
147     return DD_OK;
148 }
149
150 /* This is for checking the correctness of the prototypes/functions.
151  * Do not remove.
152  */
153 static ICOM_VTABLE(IDirect3D) WINE_UNUSED d3dvt = {
154     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
155     IDirect3DImpl_QueryInterface,
156     IDirect3DImpl_AddRef,
157     IDirect3DImpl_Release,
158     IDirect3DImpl_Initialize,
159     IDirect3DImpl_EnumDevices,
160     IDirect3DImpl_CreateLight,
161     IDirect3DImpl_CreateMaterial,
162     IDirect3DImpl_CreateViewport,
163     IDirect3DImpl_FindDevice
164 };
165
166 /*******************************************************************************
167  *                              IDirect3D2
168  */
169 HRESULT WINAPI IDirect3D2Impl_QueryInterface(
170     LPDIRECT3D2 iface,REFIID refiid,LPVOID *obj) {
171     ICOM_THIS(IDirect3D2Impl,iface);
172
173     /* FIXME: Not sure if this is correct */
174
175     TRACE("(%p)->(%s,%p)\n",This,debugstr_guid(refiid),obj);
176     if ( ( IsEqualGUID( &IID_IDirectDraw,  refiid ) ) ||
177          ( IsEqualGUID( &IID_IDirectDraw2, refiid ) ) ||
178          ( IsEqualGUID( &IID_IDirectDraw4, refiid ) ) ) {
179         *obj = This->ddraw;
180         IDirect3D2_AddRef(iface);
181
182         TRACE("  Creating IDirectDrawX interface (%p)\n", *obj);
183
184         return S_OK;
185     }
186     if ( ( IsEqualGUID( &IID_IDirect3D2, refiid ) ) ||
187          ( IsEqualGUID( &IID_IUnknown,   refiid ) ) ) {
188         *obj = This;
189         IDirect3D2_AddRef(iface);
190
191         TRACE("  Creating IDirect3D2 interface (%p)\n", *obj);
192
193         return S_OK;
194     }
195     if ( IsEqualGUID( &IID_IDirect3D, refiid ) ) {
196         IDirect3DImpl*  d3d;
197
198         d3d = HeapAlloc(GetProcessHeap(),0,sizeof(*d3d));
199         d3d->ref = 1;
200         d3d->ddraw = This->ddraw;
201         IDirect3D2_AddRef(iface);
202         ICOM_VTBL(d3d) = &d3dvt;
203         *obj = d3d;
204         TRACE("  Creating IDirect3D interface (%p)\n", *obj);
205         return S_OK;
206     }
207     FIXME("(%p):interface for IID %s NOT found!\n",This,debugstr_guid(refiid));
208     return OLE_E_ENUM_NOMORE;
209 }
210
211 ULONG WINAPI IDirect3D2Impl_AddRef(LPDIRECT3D2 iface) {
212     ICOM_THIS(IDirect3D2Impl,iface);
213     TRACE("(%p)->() incrementing from %lu.\n", This, This->ref );
214
215     return ++(This->ref);
216 }
217
218 ULONG WINAPI IDirect3D2Impl_Release(LPDIRECT3D2 iface) {
219     ICOM_THIS(IDirect3D2Impl,iface);
220     TRACE("(%p)->() decrementing from %lu.\n", This, This->ref );
221
222     if (!--(This->ref)) {
223         IDirectDraw2_Release((IDirectDraw2*)This->ddraw);
224         HeapFree(GetProcessHeap(),0,This);
225         return S_OK;
226     }
227     return This->ref;
228 }
229
230 HRESULT WINAPI IDirect3D2Impl_EnumDevices(
231     LPDIRECT3D2 iface,LPD3DENUMDEVICESCALLBACK cb, LPVOID context
232 ) {
233     ICOM_THIS(IDirect3D2Impl,iface);
234     FIXME("(%p)->(%p,%p),stub!\n",This,cb,context);
235     return DD_OK;
236 }
237
238 HRESULT WINAPI IDirect3D2Impl_CreateLight(
239     LPDIRECT3D2 iface, LPDIRECT3DLIGHT *lplight, IUnknown *lpunk
240 ) {
241     ICOM_THIS(IDirect3D2Impl,iface);
242     FIXME("(%p)->(%p,%p): stub\n", This, lplight, lpunk);
243     return E_FAIL;
244 }
245
246 HRESULT WINAPI IDirect3D2Impl_CreateMaterial(
247     LPDIRECT3D2 iface, LPDIRECT3DMATERIAL2 *lpmaterial, IUnknown *lpunk
248 ) {
249     ICOM_THIS(IDirect3D2Impl,iface);
250     FIXME("(%p)->(%p,%p): stub\n", This, lpmaterial, lpunk);
251     return E_FAIL;
252 }
253
254 HRESULT WINAPI IDirect3D2Impl_CreateViewport(
255     LPDIRECT3D2 iface, LPDIRECT3DVIEWPORT2 *lpviewport, IUnknown *lpunk
256 ) {
257     ICOM_THIS(IDirect3D2Impl,iface);
258     FIXME("(%p)->(%p,%p): stub\n", This, lpviewport, lpunk);
259     return E_FAIL;
260 }
261
262 HRESULT WINAPI IDirect3D2Impl_FindDevice(
263     LPDIRECT3D2 iface, LPD3DFINDDEVICESEARCH lpfinddevsrc,
264     LPD3DFINDDEVICERESULT lpfinddevrst)
265 {
266     ICOM_THIS(IDirect3D2Impl,iface);
267     FIXME("(%p)->(%p,%p): stub\n", This, lpfinddevsrc, lpfinddevrst);
268     return DD_OK;
269 }
270
271 HRESULT WINAPI IDirect3D2Impl_CreateDevice(
272     LPDIRECT3D2 iface, REFCLSID rguid, LPDIRECTDRAWSURFACE surface,
273     LPDIRECT3DDEVICE2 *device)
274 {
275     ICOM_THIS(IDirect3D2Impl,iface);
276     FIXME("(%p)->(%s,%p,%p): stub\n",This,debugstr_guid(rguid),surface,device);
277     return DDERR_INVALIDPARAMS;
278 }
279
280 /* This is for checking the correctness of the prototypes/functions.
281  * Do not remove.
282  */
283 static ICOM_VTABLE(IDirect3D2) WINE_UNUSED d3d2vt =
284 {
285     ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
286     IDirect3D2Impl_QueryInterface,
287     IDirect3D2Impl_AddRef,
288     IDirect3D2Impl_Release,
289     IDirect3D2Impl_EnumDevices,
290     IDirect3D2Impl_CreateLight,
291     IDirect3D2Impl_CreateMaterial,
292     IDirect3D2Impl_CreateViewport,
293     IDirect3D2Impl_FindDevice,
294     IDirect3D2Impl_CreateDevice
295 };