Beispiel #1
0
BOOL GRenderWinG::Init( BOOL FirstTime )
{
	if (!FirstTime)
	{
		// only a screen mode change so don't redo DLL etc, just get new DC
		if (WinGDLL)
		{
			// kill old one
			if (OffScreenDC)
				DeleteDC( OffScreenDC );

			// go get new one
			OffScreenDC = pWinGCreateDC();
			if (OffScreenDC)
				return TRUE;
		}
		return FALSE;
	}

#if WIN32
	// lets see if the DLL is there

	// on NT 3.1 the DLL init code fails the load and produces an ugly dialog, so we don't
	// bother
	if (IsWin32NT())
	{
		const WORD Ver = LOWORD( GetVersion() );
		if (
			(LOBYTE(Ver) == 3) &&					// NT 3.5 is minimum requirement
			(HIBYTE(Ver) < 50)
		   )
			return FALSE;
	}

	// try the DLL now
	WinGDLL = LoadLibrary("WING32.DLL");
	if (WinGDLL)
	{
		// (ordinal values extracted from DLL using DUMPBIN -export)

		pWinGCreateDC =		(WING_CREATEDC)		GetProcAddress( WinGDLL, MAKEINTRESOURCE(0x3e9) );
		pWinGCreateBitmap =	(WING_CREATEBITMAP)	GetProcAddress( WinGDLL, MAKEINTRESOURCE(0x3eb) );
		pWinGBitBlt =		(WING_BITBLT)		GetProcAddress( WinGDLL, MAKEINTRESOURCE(0x3f2) );
		pWinGRecommendedDIBFormat =
							(WING_RECOMMENDED)	GetProcAddress( WinGDLL, MAKEINTRESOURCE( 0x3ea ) );

		if (
			(pWinGCreateDC == NULL)		||
			(pWinGCreateBitmap == NULL)	||
			(pWinGBitBlt == NULL) 		||
			(pWinGRecommendedDIBFormat==NULL)
		   )
		{
			TRACE( _T("WinG32 DLL entrypoints missing!\n"));
			FreeLibrary( WinGDLL );
			WinGDLL = NULL;
			return FALSE;
		}
	}
	else
	{
		TRACE( _T("WinG DLL not found (error %d)\n"), GetLastError() );
		return FALSE;
	}

	// remember the DLL handle so it gets cleaned up for us always on exit
	ExtraDLLs[ WinG_DLL ] = WinGDLL;

	RecommendedDIB.biSize = sizeof(BITMAPINFOHEADER);

	// excuse the seemingly rampant cast but I think the official prototype is wrong
	const BOOL ok = pWinGRecommendedDIBFormat( (LPBITMAPINFO)&RecommendedDIB );
		
	if (IsUserName("Andy"))
	{
		TRACE( _T("Recommended bitmap:\n"));
		if (ok)
		{
			TRACE( _T("%dx%d height=%d comp=%d\n"),
					(INT32)RecommendedDIB.biPlanes,
					(INT32)RecommendedDIB.biBitCount,
					(INT32)RecommendedDIB.biHeight,
					(INT32)RecommendedDIB.biCompression
				);
		}
		else
			TRACE( _T("ERROR - isnt one\n"));
	}

	OffScreenDC = pWinGCreateDC();
	if (OffScreenDC)
		return TRUE;

#endif

	// if we get here it means we failed
	return FALSE;
}
Beispiel #2
0
static void InternalAssert(const TCHAR * AssertDescription, const char * lpszFileName, INT32 nLine, BOOL UseMFC)
{
	if (!UseMFC)
#if defined(__WXMSW__)
		MessageBeep(MB_ICONASTERISK);
#else
		::wxBell();
#endif


#ifdef _ENSURES

	TCHAR				sz[256];
	static TCHAR BASED_CODE szTitle[] = wxT("Ensure Failed!");

	// In Unicode we need to convert the filename to TCHAR
#if 0 != wxUSE_UNICODE
	TCHAR szRealFile[256];
	size_t count = camMbstowcs(szRealFile, lpszFileName, 255);
	if (count == (size_t)-1)
		count = 0;
	szRealFile[count] = (TCHAR)0;
	const TCHAR* lpszRealFile = szRealFile;
#else
	const TCHAR* lpszRealFile = lpszFileName;
#endif

	static TCHAR BASED_CODE szMessage[] = wxT("%s, File %s, Line %d");
	static TCHAR BASED_CODE szMessageNoReason[] = wxT("Error %d@%s");			// note number first

	// get app name or NULL if unknown (don't call assert)
//	const TCHAR		   *pszAppName = wxGetApp().GetAppName();

	if (AssertDescription != NULL)
	{
		camSnprintf(sz, 255,
			szMessage,                       
			AssertDescription, 
			lpszRealFile, 
			nLine);    
	}
	else   
	{
		camSnprintf(sz, 255,
			szMessageNoReason,
			nLine,
			lpszRealFile);
	}
	
#ifdef _DEBUG
//PORTNOTE("other","Remove afxTraceEnabled")
//#ifndef EXCLUDE_FROM_XARALX
//	if (afxTraceEnabled)
#if defined(__WXMSW__)
	{
		// assume the debugger or auxiliary port
		#ifndef _MAC
		::OutputDebugString(sz);
		::OutputDebugString(_T(", "));
		::OutputDebugString(szTitle);
		::OutputDebugString(_T("\n\r"));
		#else
		// Mac version needs them all together
		camStrcat(sz, _T(", "));
		camStrcat(sz,szTitle);
		camStrcat(sz,_T("\n\r"));
		::OutputDebugString(sz);
		#endif
	}
#endif
#endif


	if (AssertBusy > 0)
	{
		// getting assertion while inside an assertion
		//  - it has already been traced, but 
		// break into the debugger (or Dr Watson log)
		DEBUGBREAK;									// else Win32s might die (just beeps)
		return;
	}

	AssertBusy++;

	if ( Error::IsInRenderThread() )
	{
		TRACE( wxT("In RenderThread so clearing up system") );
		Error::RenderThreadReset();
													// Commented out - no problem using wx for render errors
//		UseMFC = FALSE;								// mustn't use MFC for render errors 
	}

	INT32					result;

	TCHAR				RealErrorMsg[256];

	if (UseMFC)
	{
		// use our error handler to report ensures as it is more robust instead of MessageBox
		// The arrangement of buttons is the same as the exception handler dialog, not the same
		// as the original Ensure dialog (which was Abort/Retry/Ignore)
		ErrorInfo Info;

		// try to preserve original error message
		camStrcpy( RealErrorMsg, Error::GetErrorString() );

		Error::SetErrorSerious( sz );			// set error msg (vaping any previous one)
		Info.ErrorMsg = 0;
		Info.Button[0] = _R(IDS_CONTINUE);
		Info.Button[1] = _R(IDS_QUIT);
#ifndef EXCLUDE_FROM_XARALX
		if (IsWin32NT())
		{
#endif
			// only NT can cope with an Abort button
			Info.Button[2] = _R(IDS_ABORT);
			Info.Button[3] = _R(IDS_DEBUG);
#ifndef EXCLUDE_FROM_XARALX
		}
		else
		{
			Info.Button[2] = _R(IDS_DEBUG);
		}
#endif
													// no default button (or Help)
		Info.Cancel = 1;							// Esc = Continue

		result = InformGeneral( ERRORTYPE_ENSURE, &Info );
	}
	else

	{
		CamResource::DoneInit();
		CCamApp::DisableSystem();

		// e.g. if this an MFC assert, don't use our lovely error handler becuase that itself
		// uses MFC. Instead we use good old MessageBox

#if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
		wxWindow	   *pParent = AfxGetApp().GetTopWindow(); 
PORTNOTE("other","Use CInformErrorDialog::GetSafeParent() when implemented")
#ifndef EXCLUDE_FROM_XARALX
		CInformErrorDialog::GetSafeParent();
#endif
#else
		wxWindow	   *pParent = NULL;
#endif

		wxMessageDialog	Dialog( pParent, sz, szTitle, wxICON_HAND | wxYES_NO | wxCANCEL );
		INT32 nCode = Dialog.ShowModal();

		CCamApp::EnableSystem();

		// convert MessageBox return value into a sane button ID
		switch (nCode)
		{
			case wxID_NO:
				result = _R(IDS_ABORT);
				break;
			case wxID_YES:
				result = _R(IDS_DEBUG);
				break;
			case wxID_CANCEL:
			default:
				result = _R(IDS_CONTINUE);
				break;
		}
	}

	AssertBusy--;

	if ((ResourceID)result == _R(IDS_DEBUG))
	{
		DEBUGBREAK;
	}
	// no action on _R(IDS_CONTINUE))
	else if ((ResourceID)result == _R(IDS_QUIT))
	{
		// quit in a slightly nice way
		wxWindow *MainWnd = AfxGetApp().GetTopWindow();
		if( MainWnd && MainWnd->IsShown() )
		{
			MainWnd->Destroy();
		}
	} // drop through
	if (((ResourceID)result == _R(IDS_ABORT)) || ((ResourceID)result == _R(IDS_QUIT)))
	{
		// if no window, try nasty exit
		AfxAbort();
		return; // how did we get here?
	}

	// if we ever get here we just carry on as if nothing happened

PORTNOTE("other","We can never use MFC again")
#ifndef EXCLUDE_FROM_XARALX
	if (UseMFC)
	{
		if (RealErrorMsg[0])
			Error::SetErrorSerious( RealErrorMsg );		// restore previous error msg
		else
			Error::ClearError();
	} 
#endif
#else
	// parameters not used if non-debug
	(void)lpszFileName;
	(void)nLine;
#endif // _ENSURES

}