Put size check before data dereference
[vlc/asuraparaju-public.git] / projects / activex / viewobject.cpp
bloba194ff71af2d77dee01ae2eb815b230b91f85c7b
1 /*****************************************************************************
2 * viewobject.cpp: ActiveX control for VLC
3 *****************************************************************************
4 * Copyright (C) 2005 the VideoLAN team
6 * Authors: Damien Fouilleul <Damien.Fouilleul@laposte.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #include "plugin.h"
24 #include "viewobject.h"
26 #include "utils.h"
28 using namespace std;
30 STDMETHODIMP VLCViewObject::Draw(DWORD dwAspect, LONG lindex, PVOID pvAspect,
31 DVTARGETDEVICE *ptd, HDC hicTargetDev, HDC hdcDraw, LPCRECTL lprcBounds,
32 LPCRECTL lprcWBounds, BOOL(CALLBACK *pfnContinue)(DWORD), DWORD dwContinue)
34 if( dwAspect & DVASPECT_CONTENT )
36 if( NULL == lprcBounds )
37 return E_INVALIDARG;
39 BOOL releaseDC = FALSE;
40 SIZEL size = _p_instance->getExtent();
42 if( NULL == ptd )
44 hicTargetDev = CreateDevDC(NULL);
45 releaseDC = TRUE;
47 DPFromHimetric(hicTargetDev, (LPPOINT)&size, 1);
49 RECTL bounds = { 0L, 0L, size.cx, size.cy };
51 int sdc = SaveDC(hdcDraw);
52 SetMapMode(hdcDraw, MM_ANISOTROPIC);
53 SetWindowOrgEx(hdcDraw, 0, 0, NULL);
54 SetWindowExtEx(hdcDraw, size.cx, size.cy, NULL);
55 OffsetViewportOrgEx(hdcDraw, lprcBounds->left, lprcBounds->top, NULL);
56 SetViewportExtEx(hdcDraw, lprcBounds->right-lprcBounds->left,
57 lprcBounds->bottom-lprcBounds->top, NULL);
59 _p_instance->onDraw(ptd, hicTargetDev, hdcDraw, &bounds, lprcWBounds);
60 RestoreDC(hdcDraw, sdc);
62 if( releaseDC )
63 DeleteDC(hicTargetDev);
65 return S_OK;
67 return E_NOTIMPL;
70 STDMETHODIMP VLCViewObject::Freeze(DWORD dwAspect, LONG lindex,
71 PVOID pvAspect, LPDWORD pdwFreeze)
73 return E_NOTIMPL;
76 STDMETHODIMP VLCViewObject::GetAdvise(LPDWORD pdwAspect, LPDWORD padvf,
77 LPADVISESINK *ppAdviseSink)
79 if( NULL != pdwAspect )
80 *pdwAspect = _dwAspect;
82 if( NULL != padvf )
83 *padvf = _advf;
85 if( NULL != ppAdviseSink )
87 *ppAdviseSink = _pAdvSink;
88 if( NULL != _pAdvSink )
89 _pAdvSink->AddRef();
92 return S_OK;
95 STDMETHODIMP VLCViewObject::GetColorSet(DWORD dwAspect, LONG lindex,
96 PVOID pvAspect, DVTARGETDEVICE *ptd, HDC hicTargetDev, LPLOGPALETTE *ppColorSet)
98 return S_FALSE;
101 STDMETHODIMP VLCViewObject::SetAdvise(DWORD dwAspect, DWORD advf,
102 LPADVISESINK pAdvSink)
104 if( NULL != pAdvSink )
105 pAdvSink->AddRef();
107 if( NULL != _pAdvSink )
108 _pAdvSink->Release();
110 _dwAspect = dwAspect;
111 _advf = advf;
112 _pAdvSink = pAdvSink;
114 if( (dwAspect & DVASPECT_CONTENT) && (advf & ADVF_PRIMEFIRST) && (NULL != _pAdvSink) )
116 _pAdvSink->OnViewChange(DVASPECT_CONTENT, -1);
119 return S_OK;
122 STDMETHODIMP VLCViewObject::Unfreeze(DWORD dwFreeze)
124 return E_NOTIMPL;
127 STDMETHODIMP VLCViewObject::GetExtent(DWORD dwAspect, LONG lindex,
128 DVTARGETDEVICE *ptd, LPSIZEL lpSizel)
130 if( dwAspect & DVASPECT_CONTENT )
132 *lpSizel = _p_instance->getExtent();
133 return S_OK;
135 lpSizel->cx= 0L;
136 lpSizel->cy= 0L;
137 return E_NOTIMPL;