home *** CD-ROM | disk | FTP | other *** search
- /*
- * OLEErr.cpp
- * $Header: /BoundsChecker/Examples/BUGBNCHX/MAINERR/OLEERR.CPP 2 10/30/96 4:08p Dave $
- *
- * Description:
- * The functions that cause the OLE Check errors.
- *
- * Notes:
- * <implementation notes go here>
- *
- ***********************************************************************
- *
- * Nu-Mega Technologies, Inc.
- * P.O. Box 7780
- * Nashua, NH 03060
- *
- * (c) Copyright 1994, 1995 NuMega Technologies, Inc.
- * ALL RIGHTS RESERVED.
- *
- ***********************************************************************
- *
- **********************************************************************/
- #include "stdafx.h"
- #include "OLEErr.h"
-
- #ifdef _UNICODE
- #define OLE_ERR_PREP() \
- CLSID clsidIFace ; \
- \
- LPTSTR lpszIfaceTestProgID = _T ( "InterfaceTest" ) ; \
- WCHAR lpszwIfaceTestProgID [ 128 ] ; \
- \
- memset ( lpszwIfaceTestProgID , 0 , ( sizeof ( WCHAR ) * 128 ) ) ; \
- \
- lstrcpy ( lpszwIfaceTestProgID , lpszIfaceTestProgID ) ; \
- \
- HRESULT hrCLSID = CLSIDFromProgID( lpszwIfaceTestProgID, &clsidIFace ) ; \
- if ( S_OK != hrCLSID ) \
- { \
- MessageBox ( NULL , \
- "Please register the IFACEDLL.DLL or re-install BoundsChecker examples." , \
- "BugBench Registration Error" , \
- MB_APPLMODAL | MB_OK ) ; \
- return ; \
- } \
- \
- HRESULT hr = CoCreateInstance ( clsidIFace , NULL , CLSCTX_INPROC_SERVER , \
- IID_IUnknown , (LPVOID*)&lpUnk ) ; \
- \
- if ( S_OK != hr ) \
- { \
- MessageBox ( NULL , \
- "Could not create the InterfaceTest Object." , \
- "BugBench Registration Error" , \
- MB_APPLMODAL | MB_OK ) ; \
- return ; \
- }
- #else
-
- #define OLE_ERR_PREP() \
- CLSID clsidIFace ; \
- \
- LPTSTR lpszIfaceTestProgID = _T ( "InterfaceTest" ) ; \
- WCHAR lpszwIfaceTestProgID [ 128 ] ; \
- \
- memset ( lpszwIfaceTestProgID , 0 , ( sizeof ( WCHAR ) * 128 ) ) ; \
- \
- mbstowcs ( lpszwIfaceTestProgID , lpszIfaceTestProgID , lstrlen ( lpszIfaceTestProgID ) ) ; \
- \
- HRESULT hrCLSID = CLSIDFromProgID( lpszwIfaceTestProgID, &clsidIFace ) ; \
- if ( S_OK != hrCLSID ) \
- { \
- MessageBox ( NULL , \
- "Please register the IFACEDLL.DLL or re-install BoundsChecker examples." , \
- "BugBench Registration Error" , \
- MB_APPLMODAL | MB_OK ) ; \
- return ; \
- } \
- \
- HRESULT hr = CoCreateInstance ( clsidIFace , NULL , CLSCTX_INPROC_SERVER , \
- IID_IUnknown , (LPVOID*)&lpUnk ) ; \
- \
- if ( S_OK != hr ) \
- { \
- MessageBox ( NULL , \
- "Could not create the InterfaceTest Object." , \
- "BugBench Registration Error" , \
- MB_APPLMODAL | MB_OK ) ; \
- return ; \
- }
-
- #endif // if-else-_UNICODE
-
- // OLECheck - Interface leak
- void OLE_Interface_Leak ( )
- {
- _TRY
- {
- CLSID clsidIFace ;
-
- LPTSTR lpszIfaceTestProgID = _T ( "InterfaceTest" ) ;
- WCHAR lpszwIfaceTestProgID [ 128 ] ;
-
- memset ( lpszwIfaceTestProgID , 0 , ( sizeof ( WCHAR ) * 128 ) ) ;
-
- #ifdef _UNICODE
- lstrcpy ( lpszwIfaceTestProgID , lpszIfaceTestProgID ) ;
- #else
- mbstowcs ( lpszwIfaceTestProgID , lpszIfaceTestProgID , lstrlen ( lpszIfaceTestProgID ) ) ;
- #endif
-
- HRESULT hrCLSID = CLSIDFromProgID( lpszwIfaceTestProgID , &clsidIFace ) ;
- if ( S_OK != hrCLSID )
- {
- MessageBox ( NULL ,
- "Please register the IFACEDLL.DLL or re-install BoundsChecker examples." ,
- "BugBench Registration Error" ,
- MB_APPLMODAL | MB_OK ) ;
- return ;
- }
-
- LPUNKNOWN lpUnk ;
- HRESULT hr = CoCreateInstance ( clsidIFace , NULL , CLSCTX_INPROC_SERVER , IID_IUnknown , (LPVOID*)&lpUnk ) ;
-
- // Thre lpUnk->Release should be called to prevent a leak, but since we want to CAUSE a leak,
- // it won't be called.
-
- }
- _CATCH
- {
- }
- }
-
- // OLECheck - Interface method failure
- void OLE_IntfFail_QueryInterface ( )
- {
- LPUNKNOWN lpUnk ;
- _TRY
- {
- // OLE_ERR_PREP allocates a local variable lpUnk, a valid LPUNKNOWN.
- OLE_ERR_PREP()
-
- // Now generate the real error.
- LPMALLOC lpMalloc ;
- HRESULT hrExpectFail = lpUnk->QueryInterface ( IID_IMalloc, (LPVOID*)&lpMalloc) ;
-
- if ( S_OK == hrExpectFail )
- {
- // This shouldn't happen, but if it works, let's release the pointer anyway.
- lpMalloc->Release ( ) ;
- }
-
- lpUnk->Release ( ) ;
- }
- _CATCH
- {
- }
- }
-
-
- // OLECheck - Interface method argument: Bad handle
- void OLE_IntfArg_BadHandle_Draw ( )
- {
- LPUNKNOWN lpUnk ;
- _TRY
- {
- // OLE_ERR_PREP allocates a local variable lpUnk, a valid LPUNKNOWN.
- OLE_ERR_PREP()
-
- LPVIEWOBJECT lpVwObj ;
- HRESULT hrExpectOk = lpUnk->QueryInterface ( IID_IViewObject , (LPVOID*)&lpVwObj ) ;
-
- if ( S_OK != hrExpectOk )
- {
- MessageBox ( NULL ,
- "The Interface Test Object should support IViewObject. Please re-install the BugBench examples." ,
- "BugBench Registration Error" ,
- MB_APPLMODAL | MB_OK ) ;
- return ;
- }
-
-
- // Now generate the error
- HDC dcRender = NULL ;
- RECTL rectBounds;
- rectBounds.left = 100 ;
- rectBounds.right = 100 ;
- rectBounds.top = 100 ;
- rectBounds.bottom = 100 ;
- lpVwObj->Draw ( DVASPECT_CONTENT , /* Device aspect */
- 0 , /* View index */
- NULL , /* Must be NULL */
- NULL , /* Target Device description */
- NULL , /* Target Device info context */
- dcRender , /* Device context to draw on */ /* This is the bug */
- &rectBounds , /* Bounding rectangle */
- NULL , /* Window bounding rect */
- NULL , /* Call-back routine */
- 0 /* Continue call-back param */ ) ;
-
- lpVwObj->Release ( ) ;
- }
- _CATCH
- {
- }
-
- lpUnk->Release () ;
- }
-
- // OLECheck - Interface method argument: General
- void OLE_IntfArg_General_QueryGetData ( )
- {
- LPUNKNOWN lpUnk ;
- _TRY
- {
- // OLE_ERR_PREP allocates a local variable lpUnk, a valid LPUNKNOWN.
- OLE_ERR_PREP()
-
- LPDATAOBJECT lpDataObj ;
- HRESULT hrExpectOk = lpUnk->QueryInterface ( IID_IDataObject , (LPVOID*)&lpDataObj ) ;
-
- if ( S_OK != hrExpectOk )
- {
- MessageBox ( NULL ,
- "The Interface Test Object should support IViewObject. Please re-install the BugBench examples." ,
- "BugBench Registration Error" ,
- MB_APPLMODAL | MB_OK ) ;
-
- return ;
- }
-
- // Now generate the error
- FORMATETC* pFormatEtc = (FORMATETC*)0x01;
- lpDataObj->QueryGetData( pFormatEtc ) ;
-
- lpDataObj->Release();
- }
- _CATCH
- {
- }
-
- lpUnk->Release () ;
- }
-
-
- // OLECheck - Interface method argument: Out of range
- void OLE_IntfArg_BadRange_Draw ( )
- {
- LPUNKNOWN lpUnk ;
- _TRY
- {
- // OLE_ERR_PREP allocates a local variable lpUnk, a valid LPUNKNOWN.
- OLE_ERR_PREP()
-
- LPVIEWOBJECT lpVwObj ;
- HRESULT hrExpectOk = lpUnk->QueryInterface ( IID_IViewObject , (LPVOID*)&lpVwObj ) ;
-
- if ( S_OK != hrExpectOk )
- {
- MessageBox ( NULL ,
- "The Interface Test Object should support IViewObject. Please re-install the BugBench examples." ,
- "BugBench Registration Error" ,
- MB_APPLMODAL | MB_OK ) ;
- return ;
- }
-
-
- // Now generate the error
- HDC dcRender = CreateDC ( _T ( "DISPLAY" ), NULL , NULL , NULL ) ;
- RECTL rectBounds;
- rectBounds.left = 100 ;
- rectBounds.right = 100 ;
- rectBounds.top = 100 ;
- rectBounds.bottom = 100 ;
- lpVwObj->Draw ( DVASPECT_CONTENT , /* Device aspect */
- 0 , /* View index */
- (LPVOID) 1 , /* Must be NULL */ /* This is the bug */
- NULL , /* Target Device description */
- NULL , /* Target Device info context */
- dcRender , /* Device context to draw on */
- &rectBounds , /* Bounding rectangle */
- NULL , /* Window bounding rect */
- NULL , /* Call-back routine */
- 0 /* Continue call-back param */ ) ;
-
- lpVwObj->Release ( ) ;
- DeleteDC ( dcRender ) ;
- }
- _CATCH
- {
- }
-
- lpUnk->Release () ;
- }
-
-
- // OLECheck - Interface method argument: Structure size field is not initialized
- void OLE_IntfArg_StructSize_Draw ( )
- {
- LPUNKNOWN lpUnk ;
- _TRY
- {
- // OLE_ERR_PREP allocates a local variable lpUnk, a valid LPUNKNOWN.
- OLE_ERR_PREP()
-
- LPVIEWOBJECT lpVwObj ;
- HRESULT hrExpectOk = lpUnk->QueryInterface ( IID_IViewObject , (LPVOID*)&lpVwObj ) ;
-
- if ( S_OK != hrExpectOk )
- {
- MessageBox ( NULL ,
- "The Interface Test Object should support IViewObject. Please re-install the BugBench examples." ,
- "BugBench Registration Error" ,
- MB_APPLMODAL | MB_OK ) ;
- return ;
- }
-
-
- // Now generate the error
- HDC dcRender = CreateDC ( _T ( "DISPLAY" ), NULL , NULL , NULL ) ;
- RECTL rectBounds;
- rectBounds.left = 100 ;
- rectBounds.right = 100 ;
- rectBounds.top = 100 ;
- rectBounds.bottom = 100 ;
- DVTARGETDEVICE dvTarget ;
-
- lpVwObj->Draw ( DVASPECT_CONTENT , /* Device aspect */
- 0 , /* View index */
- NULL , /* Must be NULL */
- &dvTarget , /* Target Device description */ /* This is the bug */
- NULL , /* Target Device info context */
- dcRender , /* Device context to draw on */
- &rectBounds , /* Bounding rectangle */
- NULL , /* Window bounding rect */
- NULL , /* Call-back routine */
- 0 /* Continue call-back param */ ) ;
-
- lpVwObj->Release ( ) ;
- }
- _CATCH
- {
- }
-
- lpUnk->Release () ;
- }
-
-
- // OLECheck - Interface method argument: Undefined or illegal flags
- void OLE_IntfArg_InvalidFlag_SetAdvise ( )
- {
- LPUNKNOWN lpUnk ;
- _TRY
- {
- // OLE_ERR_PREP allocates a local variable lpUnk, a valid LPUNKNOWN.
- OLE_ERR_PREP()
-
- LPVIEWOBJECT lpVwObj ;
- HRESULT hrExpectOk = lpUnk->QueryInterface ( IID_IViewObject , (LPVOID*)&lpVwObj ) ;
-
- if ( S_OK != hrExpectOk )
- {
- MessageBox ( NULL ,
- "The Interface Test Object should support IViewObject. Please re-install the BugBench examples." ,
- "BugBench Registration Error" ,
- MB_APPLMODAL | MB_OK ) ;
- return ;
- }
-
-
- // Now generate the error
- lpVwObj->SetAdvise ( DVASPECT_CONTENT , /* Device aspect */
- ADVF_NODATA , /* Advisory flag */ /* This is the bug */
- NULL ) ; /* the advisory sink */
-
- lpVwObj->Release ( ) ;
- }
- _CATCH
- {
- }
-
- lpUnk->Release () ;
- }
-
-
- // OLECheck - Interface method argument: Conflicting combination of flags
- void OLE_IntfArg_BadComboFlag_SetAdvise ( )
- {
- LPUNKNOWN lpUnk ;
- _TRY
- {
- // OLE_ERR_PREP allocates a local variable lpUnk, a valid LPUNKNOWN.
- OLE_ERR_PREP()
-
- LPVIEWOBJECT lpVwObj ;
- HRESULT hrExpectOk = lpUnk->QueryInterface ( IID_IViewObject , (LPVOID*)&lpVwObj ) ;
-
- if ( S_OK != hrExpectOk )
- {
- MessageBox ( NULL ,
- "The Interface Test Object should support IViewObject. Please re-install the BugBench examples." ,
- "BugBench Registration Error" ,
- MB_APPLMODAL | MB_OK ) ;
- return ;
- }
-
-
- // Now generate the error
- lpVwObj->SetAdvise ( DVASPECT_CONTENT | DVASPECT_THUMBNAIL , /* Device aspect */ /* This is the bug */
- ADVF_ONLYONCE , /* Advisory flag */
- NULL ) ; /* the advisory sink */
-
- lpVwObj->Release ( ) ;
- }
- _CATCH
- {
- }
-
- lpUnk->Release () ;
- }
-