diff --git a/dlls/ddraw/ddraw.c b/dlls/ddraw/ddraw.c index 8b39147e5e3..393f4ce0dff 100644 --- a/dlls/ddraw/ddraw.c +++ b/dlls/ddraw/ddraw.c @@ -2047,12 +2047,19 @@ static HRESULT WINAPI ddraw3_GetGDISurface(IDirectDraw3 *iface, IDirectDrawSurfa { IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); IDirectDrawSurface7 *surface7; + IDirectDrawSurfaceImpl *surface_impl; HRESULT hr; TRACE("iface %p, surface %p.\n", iface, surface); hr = ddraw7_GetGDISurface(&This->IDirectDraw7_iface, &surface7); - *surface = surface7 ? (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)surface7)->IDirectDrawSurface3_iface : NULL; + if (FAILED(hr)) + { + *surface = NULL; + return hr; + } + surface_impl = (IDirectDrawSurfaceImpl *)surface7; + *surface = (IDirectDrawSurface *)&surface_impl->IDirectDrawSurface3_iface; return hr; } @@ -2061,12 +2068,19 @@ static HRESULT WINAPI ddraw2_GetGDISurface(IDirectDraw2 *iface, IDirectDrawSurfa { IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); IDirectDrawSurface7 *surface7; + IDirectDrawSurfaceImpl *surface_impl; HRESULT hr; TRACE("iface %p, surface %p.\n", iface, surface); hr = ddraw7_GetGDISurface(&This->IDirectDraw7_iface, &surface7); - *surface = surface7 ? (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)surface7)->IDirectDrawSurface3_iface : NULL; + if (FAILED(hr)) + { + *surface = NULL; + return hr; + } + surface_impl = (IDirectDrawSurfaceImpl *)surface7; + *surface = (IDirectDrawSurface *)&surface_impl->IDirectDrawSurface3_iface; return hr; } @@ -2075,12 +2089,19 @@ static HRESULT WINAPI ddraw1_GetGDISurface(IDirectDraw *iface, IDirectDrawSurfac { IDirectDrawImpl *This = impl_from_IDirectDraw(iface); IDirectDrawSurface7 *surface7; + IDirectDrawSurfaceImpl *surface_impl; HRESULT hr; TRACE("iface %p, surface %p.\n", iface, surface); hr = ddraw7_GetGDISurface(&This->IDirectDraw7_iface, &surface7); - *surface = surface7 ? (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)surface7)->IDirectDrawSurface3_iface : NULL; + if (FAILED(hr)) + { + *surface = NULL; + return hr; + } + surface_impl = (IDirectDrawSurfaceImpl *)surface7; + *surface = (IDirectDrawSurface *)&surface_impl->IDirectDrawSurface3_iface; return hr; } @@ -2438,6 +2459,7 @@ static HRESULT WINAPI ddraw4_GetSurfaceFromDC(IDirectDraw4 *iface, HDC dc, { IDirectDrawImpl *This = impl_from_IDirectDraw4(iface); IDirectDrawSurface7 *surface7; + IDirectDrawSurfaceImpl *surface_impl; HRESULT hr; TRACE("iface %p, dc %p, surface %p.\n", iface, dc, surface); @@ -2445,7 +2467,14 @@ static HRESULT WINAPI ddraw4_GetSurfaceFromDC(IDirectDraw4 *iface, HDC dc, if (!surface) return E_INVALIDARG; hr = ddraw7_GetSurfaceFromDC(&This->IDirectDraw7_iface, dc, &surface7); - *surface = surface7 ? (IDirectDrawSurface4 *)&((IDirectDrawSurfaceImpl *)surface7)->IDirectDrawSurface3_iface : NULL; + if (FAILED(hr)) + { + *surface = NULL; + return hr; + } + surface_impl = (IDirectDrawSurfaceImpl *)surface7; + /* Tests say this is true */ + *surface = (IDirectDrawSurface4 *)&surface_impl->IDirectDrawSurface3_iface; return hr; } @@ -3756,9 +3785,10 @@ struct surfacescallback_context static HRESULT CALLBACK EnumSurfacesCallbackThunk(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *surface_desc, void *context) { + IDirectDrawSurfaceImpl *surface_impl = (IDirectDrawSurfaceImpl *)surface; struct surfacescallback_context *cbcontext = context; - return cbcontext->func((IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)surface)->IDirectDrawSurface3_iface, + return cbcontext->func((IDirectDrawSurface *)&surface_impl->IDirectDrawSurface3_iface, (DDSURFACEDESC *)surface_desc, cbcontext->context); } @@ -4199,13 +4229,15 @@ static HRESULT WINAPI ddraw3_DuplicateSurface(IDirectDraw3 *iface, IDirectDrawSu IDirectDrawImpl *This = impl_from_IDirectDraw3(iface); IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface3((IDirectDrawSurface3 *)src); IDirectDrawSurface7 *dst7; + IDirectDrawSurfaceImpl *dst_impl; HRESULT hr; TRACE("iface %p, src %p, dst %p.\n", iface, src, dst); hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, (IDirectDrawSurface7 *)src_impl, &dst7); if (FAILED(hr)) return hr; - *dst = (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)dst7)->IDirectDrawSurface3_iface; + dst_impl = (IDirectDrawSurfaceImpl *)dst7; + *dst = (IDirectDrawSurface *)&dst_impl->IDirectDrawSurface3_iface; return hr; } @@ -4215,13 +4247,15 @@ static HRESULT WINAPI ddraw2_DuplicateSurface(IDirectDraw2 *iface, IDirectDrawImpl *This = impl_from_IDirectDraw2(iface); IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface3((IDirectDrawSurface3 *)src); IDirectDrawSurface7 *dst7; + IDirectDrawSurfaceImpl *dst_impl; HRESULT hr; TRACE("iface %p, src %p, dst %p.\n", iface, src, dst); hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, (IDirectDrawSurface7 *)src_impl, &dst7); if (FAILED(hr)) return hr; - *dst = (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)dst7)->IDirectDrawSurface3_iface; + dst_impl = (IDirectDrawSurfaceImpl *)dst7; + *dst = (IDirectDrawSurface *)&dst_impl->IDirectDrawSurface3_iface; return hr; } @@ -4231,13 +4265,15 @@ static HRESULT WINAPI ddraw1_DuplicateSurface(IDirectDraw *iface, IDirectDrawSur IDirectDrawImpl *This = impl_from_IDirectDraw(iface); IDirectDrawSurfaceImpl *src_impl = unsafe_impl_from_IDirectDrawSurface3((IDirectDrawSurface3 *)src); IDirectDrawSurface7 *dst7; + IDirectDrawSurfaceImpl *dst_impl; HRESULT hr; TRACE("iface %p, src %p, dst %p.\n", iface, src, dst); hr = ddraw7_DuplicateSurface(&This->IDirectDraw7_iface, (IDirectDrawSurface7 *)src_impl, &dst7); if (FAILED(hr)) return hr; - *dst = (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)dst7)->IDirectDrawSurface3_iface; + dst_impl = (IDirectDrawSurfaceImpl *)dst7; + *dst = (IDirectDrawSurface *)&dst_impl->IDirectDrawSurface3_iface; return hr; } diff --git a/dlls/ddraw/device.c b/dlls/ddraw/device.c index 7b8f975c5ca..a2eefd0068c 100644 --- a/dlls/ddraw/device.c +++ b/dlls/ddraw/device.c @@ -1960,14 +1960,15 @@ static HRESULT WINAPI IDirect3DDeviceImpl_2_GetRenderTarget(IDirect3DDevice2 *if IDirectDrawSurface **RenderTarget) { IDirect3DDeviceImpl *This = device_from_device2(iface); + IDirectDrawSurfaceImpl *RenderTargetImpl; HRESULT hr; TRACE("iface %p, target %p.\n", iface, RenderTarget); hr = IDirect3DDevice7_GetRenderTarget((IDirect3DDevice7 *)This, (IDirectDrawSurface7 **)RenderTarget); if(hr != D3D_OK) return hr; - *RenderTarget = *RenderTarget ? - (IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)*RenderTarget)->IDirectDrawSurface3_iface : NULL; + RenderTargetImpl = (IDirectDrawSurfaceImpl *)RenderTarget; + *RenderTarget = (IDirectDrawSurface *)&RenderTargetImpl->IDirectDrawSurface3_iface; return D3D_OK; } @@ -4483,12 +4484,14 @@ static HRESULT WINAPI IDirect3DDeviceImpl_3_GetTexture(IDirect3DDevice3 *iface, { HRESULT ret; IDirectDrawSurface7 *ret_val; + IDirectDrawSurfaceImpl *ret_val_impl; TRACE("iface %p, stage %u, texture %p.\n", iface, Stage, Texture2); ret = IDirect3DDevice7_GetTexture((IDirect3DDevice7 *)device_from_device3(iface), Stage, &ret_val); - *Texture2 = ret_val ? (IDirect3DTexture2 *)&((IDirectDrawSurfaceImpl *)ret_val)->IDirect3DTexture2_vtbl : NULL; + ret_val_impl = unsafe_impl_from_IDirectDrawSurface7(ret_val); + *Texture2 = ret_val_impl ? (IDirect3DTexture2 *)&ret_val_impl->IDirect3DTexture2_vtbl : NULL; TRACE("Returning texture %p.\n", *Texture2); diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c index 58743331226..8b4cfa7d083 100644 --- a/dlls/ddraw/surface.c +++ b/dlls/ddraw/surface.c @@ -553,6 +553,7 @@ static HRESULT WINAPI ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3 *ifa { IDirectDrawSurfaceImpl *This = impl_from_IDirectDrawSurface3(iface); IDirectDrawSurface7 *attachment7; + IDirectDrawSurfaceImpl *attachment_impl; DDSCAPS2 caps2; HRESULT hr; @@ -565,9 +566,13 @@ static HRESULT WINAPI ddraw_surface3_GetAttachedSurface(IDirectDrawSurface3 *ifa hr = ddraw_surface7_GetAttachedSurface((IDirectDrawSurface7 *)This, &caps2, &attachment7); - if (FAILED(hr)) *attachment = NULL; - else *attachment = attachment7 ? - &((IDirectDrawSurfaceImpl *)attachment7)->IDirectDrawSurface3_iface : NULL; + if (FAILED(hr)) + { + *attachment = NULL; + return hr; + } + attachment_impl = (IDirectDrawSurfaceImpl *)attachment7; + *attachment = &attachment_impl->IDirectDrawSurface3_iface; return hr; } @@ -1559,9 +1564,10 @@ struct callback_info static HRESULT CALLBACK EnumCallback(IDirectDrawSurface7 *surface, DDSURFACEDESC2 *surface_desc, void *context) { + IDirectDrawSurfaceImpl *surface_impl = (IDirectDrawSurfaceImpl *)surface; const struct callback_info *info = context; - return info->callback((IDirectDrawSurface *)&((IDirectDrawSurfaceImpl *)surface)->IDirectDrawSurface3_iface, + return info->callback((IDirectDrawSurface *)&surface_impl->IDirectDrawSurface3_iface, (DDSURFACEDESC *)surface_desc, info->context); }