adding more seh protection to the code

svn path=/trunk/; revision=27036
This commit is contained in:
Magnus Olsen 2007-06-07 08:46:33 +00:00
parent 958b55cf2c
commit 8d0428bfbd

View file

@ -10,45 +10,57 @@
#include "rosdraw.h" #include "rosdraw.h"
/* PSEH for SEH Support */
#include <pseh/pseh.h>
HRESULT WINAPI HRESULT WINAPI
Main_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface, HWND hwnd, DWORD cooplevel) Main_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface, HWND hwnd, DWORD cooplevel)
{ {
DX_WINDBG_trace();
/* /*
* Code from wine, this functions have been cut and paste from wine 0.9.35 * Code from wine, this functions have been cut and paste from wine 0.9.35
* and have been modify allot and are still in devloping so it match with * and have been modify allot and are still in devloping so it match with
* msdn document struct and flags * msdn document struct and flags
*/ */
HRESULT retVal = DD_OK;
HWND window; HWND window;
LPDDRAWI_DIRECTDRAW_INT This = (LPDDRAWI_DIRECTDRAW_INT)iface; LPDDRAWI_DIRECTDRAW_INT This = (LPDDRAWI_DIRECTDRAW_INT)iface;
/* Get the old window */ DX_WINDBG_trace();
window = (HWND) This->lpLcl->hWnd;
#if 0 // this check is totally invalid if you ask me - mbosma _SEH_TRY
if(!window)
{ {
return DDERR_NOHWND; /* Get the old window */
} window = (HWND) This->lpLcl->hWnd;
#if 0 // this check is totally invalid if you ask me - mbosma
if(!window)
{
retVal = DDERR_NOHWND;
_SEH_LEAVE;
}
#endif #endif
if(hwnd && !IsWindow(hwnd)) if(hwnd && !IsWindow(hwnd))
return DDERR_INVALIDPARAMS; {
retVal = DDERR_INVALIDPARAMS;
_SEH_LEAVE;
}
/* Tests suggest that we need one of them: */ /* Tests suggest that we need one of them: */
if(!(cooplevel & (DDSCL_SETFOCUSWINDOW | if(!(cooplevel & (DDSCL_SETFOCUSWINDOW |
DDSCL_NORMAL | DDSCL_NORMAL |
DDSCL_EXCLUSIVE ))) DDSCL_EXCLUSIVE )))
{ {
return DDERR_INVALIDPARAMS; retVal = DDERR_INVALIDPARAMS;
} _SEH_LEAVE;
}
/* Handle those levels first which set various hwnds */ /* Handle those levels first which set various hwnds */
if(cooplevel & DDSCL_SETFOCUSWINDOW) if(cooplevel & DDSCL_SETFOCUSWINDOW)
{ {
/* This isn't compatible with a lot of flags */ /* This isn't compatible with a lot of flags */
if(cooplevel & ( DDSCL_MULTITHREADED | if(cooplevel & ( DDSCL_MULTITHREADED |
DDSCL_FPUSETUP | DDSCL_FPUSETUP |
DDSCL_FPUPRESERVE | DDSCL_FPUPRESERVE |
DDSCL_ALLOWREBOOT | DDSCL_ALLOWREBOOT |
@ -57,123 +69,138 @@ Main_DirectDraw_SetCooperativeLevel (LPDIRECTDRAW7 iface, HWND hwnd, DWORD coopl
DDSCL_NORMAL | DDSCL_NORMAL |
DDSCL_EXCLUSIVE | DDSCL_EXCLUSIVE |
DDSCL_FULLSCREEN ) ) DDSCL_FULLSCREEN ) )
{ {
return DDERR_INVALIDPARAMS; retVal = DDERR_INVALIDPARAMS;
_SEH_LEAVE;
}
else if(This->lpLcl->dwLocalFlags & DDRAWILCL_SETCOOPCALLED)
{
retVal = DDERR_HWNDALREADYSET;
_SEH_LEAVE;
}
else if( (This->lpLcl->dwLocalFlags & DDRAWILCL_ISFULLSCREEN) && window)
{
retVal = DDERR_HWNDALREADYSET;
_SEH_LEAVE;
}
This->lpLcl->hFocusWnd = (ULONG_PTR) hwnd;
/* Won't use the hwnd param for anything else */
hwnd = NULL;
/* Use the focus window for drawing too */
This->lpLcl->hWnd = This->lpLcl->hFocusWnd;
} }
else if(This->lpLcl->dwLocalFlags & DDRAWILCL_SETCOOPCALLED) /* DDSCL_NORMAL or DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE */
if(cooplevel & DDSCL_NORMAL)
{ {
return DDERR_HWNDALREADYSET; /* Can't coexist with fullscreen or exclusive */
} if(cooplevel & (DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE) )
else if( (This->lpLcl->dwLocalFlags & DDRAWILCL_ISFULLSCREEN) && window) {
{ retVal = DDERR_INVALIDPARAMS;
return DDERR_HWNDALREADYSET; _SEH_LEAVE;
} }
This->lpLcl->hFocusWnd = (ULONG_PTR) hwnd; /* Switching from fullscreen? */
if(This->lpLcl->dwLocalFlags & DDRAWILCL_ISFULLSCREEN)
{
/* Restore the display mode */
Main_DirectDraw_RestoreDisplayMode(iface);
This->lpLcl->dwLocalFlags &= ~DDRAWILCL_ISFULLSCREEN;
This->lpLcl->dwLocalFlags &= ~DDRAWILCL_HASEXCLUSIVEMODE;
This->lpLcl->dwLocalFlags &= ~DDRAWILCL_ALLOWMODEX;
}
/* Won't use the hwnd param for anything else */ /* Don't override focus windows or private device windows */
hwnd = NULL; if( hwnd &&
!(This->lpLcl->hFocusWnd) &&
!(This->lpLcl->dwObsolete1) &&
(hwnd != window) )
{
This->lpLcl->hWnd = (ULONG_PTR)hwnd;
}
/* Use the focus window for drawing too */
This->lpLcl->hWnd = This->lpLcl->hFocusWnd;
}
/* DDSCL_NORMAL or DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE */
if(cooplevel & DDSCL_NORMAL)
{
/* Can't coexist with fullscreen or exclusive */
if(cooplevel & (DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE) )
return DDERR_INVALIDPARAMS;
/* Switching from fullscreen? */
if(This->lpLcl->dwLocalFlags & DDRAWILCL_ISFULLSCREEN)
{
/* Restore the display mode */
Main_DirectDraw_RestoreDisplayMode(iface);
This->lpLcl->dwLocalFlags &= ~DDRAWILCL_ISFULLSCREEN;
This->lpLcl->dwLocalFlags &= ~DDRAWILCL_HASEXCLUSIVEMODE;
This->lpLcl->dwLocalFlags &= ~DDRAWILCL_ALLOWMODEX;
}
/* Don't override focus windows or private device windows */
if( hwnd &&
!(This->lpLcl->hFocusWnd) &&
!(This->lpLcl->dwObsolete1) &&
(hwnd != window) )
{
This->lpLcl->hWnd = (ULONG_PTR)hwnd;
}
/* FIXME GL
IWineD3DDevice_SetFullscreen(This->wineD3DDevice,
FALSE);
*/
}
else if(cooplevel & DDSCL_FULLSCREEN)
{
/* Needs DDSCL_EXCLUSIVE */
if(!(cooplevel & DDSCL_EXCLUSIVE) )
return DDERR_INVALIDPARAMS;
/* Switch from normal to full screen mode? */
if (!(This->lpLcl->dwLocalFlags & DDRAWILCL_HASEXCLUSIVEMODE))
{
/* FIXME GL /* FIXME GL
IWineD3DDevice_SetFullscreen(This->wineD3DDevice, IWineD3DDevice_SetFullscreen(This->wineD3DDevice,
TRUE); FALSE);
*/ */
} }
else if(cooplevel & DDSCL_FULLSCREEN)
{
/* Needs DDSCL_EXCLUSIVE */
if(!(cooplevel & DDSCL_EXCLUSIVE) )
{
retVal = DDERR_INVALIDPARAMS;
_SEH_LEAVE;
}
/* Don't override focus windows or private device windows */ /* Switch from normal to full screen mode? */
if( hwnd && if (!(This->lpLcl->dwLocalFlags & DDRAWILCL_HASEXCLUSIVEMODE))
!(This->lpLcl->hFocusWnd) && {
!(This->lpLcl->dwObsolete1) && /* FIXME GL
(hwnd != window) ) IWineD3DDevice_SetFullscreen(This->wineD3DDevice,
{ TRUE);
This->lpLcl->hWnd = (ULONG_PTR) hwnd; */
} }
}
else if(cooplevel & DDSCL_EXCLUSIVE)
{
return DDERR_INVALIDPARAMS;
}
if(cooplevel & DDSCL_CREATEDEVICEWINDOW) /* Don't override focus windows or private device windows */
{ if( hwnd &&
/* Don't create a device window if a focus window is set */ !(This->lpLcl->hFocusWnd) &&
if( !This->lpLcl->hFocusWnd) !(This->lpLcl->dwObsolete1) &&
{ (hwnd != window) )
HWND devicewindow = CreateWindowExW(0, classname, L"DDraw device window", {
This->lpLcl->hWnd = (ULONG_PTR) hwnd;
}
}
else if(cooplevel & DDSCL_EXCLUSIVE)
{
retVal = DDERR_INVALIDPARAMS;
_SEH_LEAVE;
}
if(cooplevel & DDSCL_CREATEDEVICEWINDOW)
{
/* Don't create a device window if a focus window is set */
if( !This->lpLcl->hFocusWnd)
{
HWND devicewindow = CreateWindowExW(0, classname, L"DDraw device window",
WS_POPUP, 0, 0, WS_POPUP, 0, 0,
GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN), GetSystemMetrics(SM_CYSCREEN),
NULL, NULL, GetModuleHandleW(0), NULL); NULL, NULL, GetModuleHandleW(0), NULL);
ShowWindow(devicewindow, SW_SHOW); /* Just to be sure */ ShowWindow(devicewindow, SW_SHOW); /* Just to be sure */
This->lpLcl->dwObsolete1 = (DWORD)devicewindow; This->lpLcl->dwObsolete1 = (DWORD)devicewindow;
} }
}
if(cooplevel & DDSCL_MULTITHREADED && !(This->lpLcl->dwLocalFlags & DDRAWILCL_MULTITHREADED))
{
/* FIXME GL
* IWineD3DDevice_SetMultithreaded(This->wineD3DDevice);
*/
}
/* Store the cooperative_level */
/* FIXME GL
* This->cooperative_level |= cooplevel;
*/
} }
_SEH_HANDLE
if(cooplevel & DDSCL_MULTITHREADED && !(This->lpLcl->dwLocalFlags & DDRAWILCL_MULTITHREADED))
{ {
/* FIXME GL
* IWineD3DDevice_SetMultithreaded(This->wineD3DDevice);
*/
} }
_SEH_END;
return retVal;
/* Store the cooperative_level */
/* FIXME GL
* This->cooperative_level |= cooplevel;
*/
return DD_OK;
} }