diff --git a/dlls/ddraw/ddraw_private.h b/dlls/ddraw/ddraw_private.h index a8f384fa0d9..b50c0bc76a3 100644 --- a/dlls/ddraw/ddraw_private.h +++ b/dlls/ddraw/ddraw_private.h @@ -470,6 +470,7 @@ struct IDirect3DViewportImpl }; IDirect3DViewportImpl *unsafe_impl_from_IDirect3DViewport3(IDirect3DViewport3 *iface) DECLSPEC_HIDDEN; +IDirect3DViewportImpl *unsafe_impl_from_IDirect3DViewport(IDirect3DViewport *iface) DECLSPEC_HIDDEN; /* Helper functions */ void viewport_activate(IDirect3DViewportImpl* This, BOOL ignore_lights) DECLSPEC_HIDDEN; diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index 4ca94f63c33..a2e27acd770 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -712,7 +712,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_1_Execute(IDirect3DDevice *iface, { IDirect3DDeviceImpl *This = device_from_device1(iface); IDirect3DExecuteBufferImpl *buffer = unsafe_impl_from_IDirect3DExecuteBuffer(ExecuteBuffer); - IDirect3DViewportImpl *Direct3DViewportImpl = (IDirect3DViewportImpl *)Viewport; + IDirect3DViewportImpl *Direct3DViewportImpl = unsafe_impl_from_IDirect3DViewport(Viewport); HRESULT hr; TRACE("iface %p, buffer %p, viewport %p, flags %#x.\n", iface, ExecuteBuffer, Viewport, Flags); @@ -782,7 +782,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_1_AddViewport(IDirect3DDevice *iface, IDirect3DViewport *Direct3DViewport) { IDirect3DDeviceImpl *This = device_from_device1(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport; + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport(Direct3DViewport); TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport); @@ -843,7 +843,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_1_DeleteViewport(IDirect3DDevice *ifac IDirect3DViewport *Direct3DViewport) { IDirect3DDeviceImpl *This = device_from_device1(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Direct3DViewport; + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport(Direct3DViewport); TRACE("iface %p, viewport %p.\n", iface, Direct3DViewport); @@ -944,7 +944,7 @@ static HRESULT WINAPI IDirect3DDeviceImpl_1_NextViewport(IDirect3DDevice *iface, IDirect3DViewport *Viewport, IDirect3DViewport **lplpDirect3DViewport, DWORD Flags) { IDirect3DDeviceImpl *This = device_from_device1(iface); - IDirect3DViewportImpl *vp = (IDirect3DViewportImpl *)Viewport; + IDirect3DViewportImpl *vp = unsafe_impl_from_IDirect3DViewport(Viewport); IDirect3DViewport3 *res; HRESULT hr; diff --git a/dlls/ddraw/viewport.c b/dlls/ddraw/viewport.c index 6024aaec5e8..bbff45b5225 100644 --- a/dlls/ddraw/viewport.c +++ b/dlls/ddraw/viewport.c @@ -1127,6 +1127,14 @@ IDirect3DViewportImpl *unsafe_impl_from_IDirect3DViewport3(IDirect3DViewport3 *i return CONTAINING_RECORD(iface, IDirect3DViewportImpl, IDirect3DViewport3_iface); } +IDirect3DViewportImpl *unsafe_impl_from_IDirect3DViewport(IDirect3DViewport *iface) +{ + /* IDirect3DViewport and IDirect3DViewport3 use the same iface. */ + if (!iface) return NULL; + assert(iface->lpVtbl == (IDirect3DViewportVtbl *)&d3d_viewport_vtbl); + return CONTAINING_RECORD(iface, IDirect3DViewportImpl, IDirect3DViewport3_iface); +} + void d3d_viewport_init(IDirect3DViewportImpl *viewport, IDirectDrawImpl *ddraw) { viewport->IDirect3DViewport3_iface.lpVtbl = &d3d_viewport_vtbl;