Update of /cvsroot/cpptool/rfta/src/rftavc7addin
In directory sc8-pr-cvs1:/tmp/cvs-serv15790/src/rftavc7addin
Modified Files:
CommandGroup.cpp CommandGroup.h Connect.cpp stdafx.h
TextDocumentHelper.cpp TextSelectionHelper.cpp
VC7TextDocument.cpp
Log Message:
* added error check on all COM call,with error detail message in debug build.
Index: CommandGroup.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftavc7addin/CommandGroup.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CommandGroup.cpp 15 May 2003 07:31:43 -0000 1.1
--- CommandGroup.cpp 18 May 2003 09:19:10 -0000 1.2
***************
*** 4,15 ****
CommandGroup::CommandGroup( const CString &commandName,
CComPtr<EnvDTE::_DTE> application )
{
! application->get_UndoContext( &undoContext_ );
VARIANT_BOOL wasOpen;
! undoContext_->get_IsOpen( &wasOpen );
wasOpen_ = wasOpen != 0;
if ( !wasOpen_ )
! undoContext_->Open( CComBSTR( commandName ), VARIANT_FALSE );
}
--- 4,16 ----
CommandGroup::CommandGroup( const CString &commandName,
CComPtr<EnvDTE::_DTE> application )
+ : validated_( false )
{
! VERIFY_COM( application->get_UndoContext( &undoContext_ ) );
VARIANT_BOOL wasOpen;
! VERIFY_COM( undoContext_->get_IsOpen( &wasOpen ) );
wasOpen_ = wasOpen != 0;
if ( !wasOpen_ )
! VERIFY_COM( undoContext_->Open( CComBSTR( commandName ), VARIANT_FALSE ) );
}
***************
*** 17,21 ****
CommandGroup::~CommandGroup()
{
! cancel();
}
--- 18,23 ----
CommandGroup::~CommandGroup()
{
! if ( !validated_ )
! cancel();
}
***************
*** 24,29 ****
CommandGroup::validate()
{
if ( !wasOpen_ )
! undoContext_->Close();
wasOpen_ = false;
}
--- 26,33 ----
CommandGroup::validate()
{
+ validated_ = true;
+
if ( !wasOpen_ )
! VERIFY_COM( undoContext_->Close() );
wasOpen_ = false;
}
***************
*** 33,36 ****
CommandGroup::cancel()
{
! undoContext_->SetAborted();
}
--- 37,40 ----
CommandGroup::cancel()
{
! VERIFY_COM( undoContext_->SetAborted() );
}
Index: CommandGroup.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftavc7addin/CommandGroup.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CommandGroup.h 15 May 2003 07:31:43 -0000 1.1
--- CommandGroup.h 18 May 2003 09:19:10 -0000 1.2
***************
*** 16,19 ****
--- 16,20 ----
CComPtr<EnvDTE::UndoContext> undoContext_;
bool wasOpen_;
+ bool validated_;
};
Index: Connect.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftavc7addin/Connect.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Connect.cpp 15 May 2003 19:14:12 -0000 1.7
--- Connect.cpp 18 May 2003 09:19:10 -0000 1.8
***************
*** 24,73 ****
// by right clicking the project in the Solution Explorer, then choosing install.
- #include <stdexcept>
-
- class IDTCallError : public std::runtime_error
- {
- public:
- IDTCallError( HRESULT hr )
- : std::runtime_error( "IDT call failed" )
- , hresult_( hr )
- {
- }
! HRESULT hresult_;
! };
!
!
! /*
!
!
! void GetLastErrorDescription(CComBSTR& bstr)
{
CComPtr<IErrorInfo> pErrorInfo;
! if (GetErrorInfo(0, &pErrorInfo) == S_OK)
! pErrorInfo->GetDescription(&bstr);
! }
!
! #define VERIFY_OK(f) \
! { \
! HRESULT hr = (f); \
! if (hr != S_OK) \
! { \
! if (FAILED(hr)) \
! { \
! CComBSTR bstr; \
! GetLastErrorDescription(bstr); \
! _RPTF2(_CRT_ASSERT, "Object call returned %lx\n\n%S", hr, (BSTR) bstr); \
! } \
! else \
! _RPTF1(_CRT_ASSERT, "Object call returned %lx", hr); \
! } \
! }
! */
!
! inline void checkIDTCall( HRESULT hresult )
! {
! if ( !SUCCEEDED( hresult ) )
! throw IDTCallError( hresult );
}
--- 24,35 ----
// by right clicking the project in the Solution Explorer, then choosing install.
! CComBSTR GetLastCOMErrorDescription()
{
+ CComBSTR decription;
CComPtr<IErrorInfo> pErrorInfo;
! if ( GetErrorInfo(0, &pErrorInfo) == S_OK )
! pErrorInfo->GetDescription( &decription );
! return decription;
}
***************
*** 81,85 ****
HRESULT hr = commands.Item( CComVariant( fullCommandName ), 0, &pExistingCommand );
if ( SUCCEEDED(hr) && pExistingCommand )
! pExistingCommand->Delete();
}
--- 43,47 ----
HRESULT hr = commands.Item( CComVariant( fullCommandName ), 0, &pExistingCommand );
if ( SUCCEEDED(hr) && pExistingCommand )
! VERIFY_COM( pExistingCommand->Delete() );
}
***************
*** 89,98 ****
AFX_MANAGE_STATE(AfxGetStaticModuleState());
! // _asm int 3; // comment this out to force an assertion when loading the add-in.
HRESULT hr = S_OK;
pApplication->QueryInterface(__uuidof(EnvDTE::_DTE), (LPVOID*)&m_pDTE);
pAddInInst->QueryInterface(__uuidof(EnvDTE::AddIn), (LPVOID*)&m_pAddInInstance);
! if(ConnectMode != 5) //5 == AddInDesignerObjects::ext_cm_UISetup)
return S_OK;
--- 51,60 ----
AFX_MANAGE_STATE(AfxGetStaticModuleState());
! _asm int 3; // comment this out to force an assertion when loading the add-in.
HRESULT hr = S_OK;
pApplication->QueryInterface(__uuidof(EnvDTE::_DTE), (LPVOID*)&m_pDTE);
pAddInInst->QueryInterface(__uuidof(EnvDTE::AddIn), (LPVOID*)&m_pAddInInstance);
! if( ConnectMode != 5 ) //5 == AddInDesignerObjects::ext_cm_UISetup)
return S_OK;
***************
*** 101,105 ****
CComPtr<EnvDTE::Commands> pCommands;
CComPtr<EnvDTE::Command> pCreatedCommand;
! checkIDTCall( m_pDTE->get_Commands( &pCommands ) );
// Removes existing command (so we can add some as the add-in is updated).
--- 63,67 ----
CComPtr<EnvDTE::Commands> pCommands;
CComPtr<EnvDTE::Command> pCreatedCommand;
! VERIFY_COM( m_pDTE->get_Commands( &pCommands ) );
// Removes existing command (so we can add some as the add-in is updated).
***************
*** 173,185 ****
{
CComPtr<EnvDTE::Command> pCreatedCommand;
! checkIDTCall( commands.AddNamedCommand( m_pAddInInstance,
! commandName,
! commandButtonText,
! commandToolTip,
! VARIANT_FALSE,
! commandBitmapID,
! NULL,
! EnvDTE::vsCommandStatusSupported + EnvDTE::vsCommandStatusEnabled,
! &pCreatedCommand ) );
return pCreatedCommand;
}
--- 135,147 ----
{
CComPtr<EnvDTE::Command> pCreatedCommand;
! VERIFY_COM( commands.AddNamedCommand( m_pAddInInstance,
! commandName,
! commandButtonText,
! commandToolTip,
! VARIANT_FALSE,
! commandBitmapID,
! NULL,
! EnvDTE::vsCommandStatusSupported + EnvDTE::vsCommandStatusEnabled,
! &pCreatedCommand ) );
return pCreatedCommand;
}
***************
*** 193,197 ****
CComQIPtr<Office::CommandBar> pToolbar;
CComPtr<Office::_CommandBars> pCommandBars;
! checkIDTCall( m_pDTE->get_CommandBars( &pCommandBars ) );
HRESULT hr = pCommandBars->get_Item( CComVariant( toolBarName ), &pToolbar );
if ( SUCCEEDED(hr) ) // the toolbar already exist, make it visible
--- 155,159 ----
CComQIPtr<Office::CommandBar> pToolbar;
CComPtr<Office::_CommandBars> pCommandBars;
! VERIFY_COM( m_pDTE->get_CommandBars( &pCommandBars ) );
HRESULT hr = pCommandBars->get_Item( CComVariant( toolBarName ), &pToolbar );
if ( SUCCEEDED(hr) ) // the toolbar already exist, make it visible
***************
*** 201,208 ****
CComPtr<Office::CommandBar> pMenubar;
if ( commandBarType == EnvDTE::vsCommandBarTypeMenu ) // get top level menu bar
! checkIDTCall( pCommandBars->get_Item( CComVariant( "MenuBar" ), &pMenubar ) );
CComPtr<IDispatch> pDisp;
! checkIDTCall( commands.AddCommandBar( (LPWSTR)toolBarName,
commandBarType,
pMenubar,
--- 163,170 ----
CComPtr<Office::CommandBar> pMenubar;
if ( commandBarType == EnvDTE::vsCommandBarTypeMenu ) // get top level menu bar
! VERIFY_COM( pCommandBars->get_Item( CComVariant( "MenuBar" ), &pMenubar ) );
CComPtr<IDispatch> pDisp;
! VERIFY_COM( commands.AddCommandBar( (LPWSTR)toolBarName,
commandBarType,
pMenubar,
***************
*** 232,236 ****
CComQIPtr<Office::_CommandBarButton> pButton( pCommandBarControl );
if ( pButton )
! pButton->put_Style( Office::msoButtonIcon );
}
}
--- 194,198 ----
CComQIPtr<Office::_CommandBarButton> pButton( pCommandBarControl );
if ( pButton )
! VERIFY_COM( pButton->put_Style( Office::msoButtonIcon ) );
}
}
***************
*** 238,242 ****
{
CComPtr<Office::CommandBarControl> pCommandBarControl;
! pCommand->AddControl( pMenuBar, index, &pCommandBarControl );
}
}
--- 200,204 ----
{
CComPtr<Office::CommandBarControl> pCommandBarControl;
! VERIFY_COM( pCommand->AddControl( pMenuBar, index, &pCommandBarControl ) );
}
}
***************
*** 306,315 ****
CComPtr<EnvDTE::Document> activeDocument;
! m_pDTE->get_ActiveDocument( &activeDocument );
if ( !activeDocument )
return S_OK;
CComPtr<IDispatch> textDocumentBase;
! activeDocument->Object( CComBSTR(L"TextDocument"), &textDocumentBase );
CComQIPtr<EnvDTE::TextDocument> textDocument = textDocumentBase;
if ( !textDocument )
--- 268,277 ----
CComPtr<EnvDTE::Document> activeDocument;
! VERIFY_COM( m_pDTE->get_ActiveDocument( &activeDocument ) );
if ( !activeDocument )
return S_OK;
CComPtr<IDispatch> textDocumentBase;
! VERIFY_COM( activeDocument->Object( CComBSTR(L"TextDocument"), &textDocumentBase ) );
CComQIPtr<EnvDTE::TextDocument> textDocument = textDocumentBase;
if ( !textDocument )
***************
*** 317,321 ****
CComPtr<EnvDTE::TextSelection> selection;
! textDocument->get_Selection( &selection );
TextSelectionHelper selectionHelper( selection );
int selectionStart = selectionHelper.selectionStartCharOffset();
--- 279,283 ----
CComPtr<EnvDTE::TextSelection> selection;
! VERIFY_COM( textDocument->get_Selection( &selection ) );
TextSelectionHelper selectionHelper( selection );
int selectionStart = selectionHelper.selectionStartCharOffset();
Index: stdafx.h
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftavc7addin/stdafx.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** stdafx.h 14 May 2003 18:55:50 -0000 1.3
--- stdafx.h 18 May 2003 09:19:10 -0000 1.4
***************
*** 96,98 ****
};
! extern CAddInModule _AtlModule;
\ No newline at end of file
--- 96,142 ----
};
! extern CAddInModule _AtlModule;
!
!
!
! // Will need to clean this...
! #include <stdexcept>
!
! class IDTCallError : public std::runtime_error
! {
! public:
! IDTCallError( HRESULT hr )
! : std::runtime_error( "IDT call failed" )
! , hresult_( hr )
! {
! }
!
! HRESULT hresult_;
! };
!
! inline void checkIDTCall( HRESULT hresult )
! {
! if ( !SUCCEEDED( hresult ) )
! throw IDTCallError( hresult );
! }
!
! CComBSTR GetLastCOMErrorDescription();
!
! #ifdef NDEBUG
! # define VERIFY_COM( expression ) \
! checkIDTCall( expression );
! #else
! # define VERIFY_COM( expression ) \
! { \
! HRESULT hr = (expression); \
! if ( FAILED(hr) ) \
! { \
! CComBSTR decription = GetLastCOMErrorDescription(); \
! _RPTF3( _CRT_ASSERT, \
! "COM call returned %lx\nExpression: %s\n%S", \
! hr, \
! #expression, \
! (BSTR)decription ); \
! } \
! }
! #endif
Index: TextDocumentHelper.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftavc7addin/TextDocumentHelper.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TextDocumentHelper.cpp 15 May 2003 19:29:33 -0000 1.2
--- TextDocumentHelper.cpp 18 May 2003 09:19:10 -0000 1.3
***************
*** 31,35 ****
{
CComPtr<EnvDTE::TextSelection> selectionInterface;
! _document->get_Selection( &selectionInterface );
return TextSelectionHelper( selectionInterface );
}
--- 31,35 ----
{
CComPtr<EnvDTE::TextSelection> selectionInterface;
! VERIFY_COM( _document->get_Selection( &selectionInterface ) );
return TextSelectionHelper( selectionInterface );
}
***************
*** 40,44 ****
{
long tabSize;
! _document->get_TabSize( &tabSize );
return tabSize;
}
--- 40,44 ----
{
long tabSize;
! VERIFY_COM( _document->get_TabSize( &tabSize ) );
return tabSize;
}
Index: TextSelectionHelper.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftavc7addin/TextSelectionHelper.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TextSelectionHelper.cpp 15 May 2003 19:29:33 -0000 1.2
--- TextSelectionHelper.cpp 18 May 2003 09:19:10 -0000 1.3
***************
*** 31,38 ****
{
CComPtr<EnvDTE::VirtualPoint> point;
! _selection->get_TopPoint( &point );
long startIndex = -1;
! point->get_AbsoluteCharOffset( &startIndex );
return startIndex -1;
}
--- 31,38 ----
{
CComPtr<EnvDTE::VirtualPoint> point;
! VERIFY_COM( _selection->get_TopPoint( &point ) );
long startIndex = -1;
! VERIFY_COM( point->get_AbsoluteCharOffset( &startIndex ) );
return startIndex -1;
}
***************
*** 43,52 ****
{
CComPtr<EnvDTE::VirtualPoint> point;
! _selection->get_BottomPoint( &point );
long endIndex = -1;
! point->get_AbsoluteCharOffset( &endIndex );
return endIndex -1;
}
-
-
--- 43,50 ----
{
CComPtr<EnvDTE::VirtualPoint> point;
! VERIFY_COM( _selection->get_BottomPoint( &point ) );
long endIndex = -1;
! VERIFY_COM( point->get_AbsoluteCharOffset( &endIndex ) );
return endIndex -1;
}
Index: VC7TextDocument.cpp
===================================================================
RCS file: /cvsroot/cpptool/rfta/src/rftavc7addin/VC7TextDocument.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** VC7TextDocument.cpp 16 May 2003 21:13:56 -0000 1.4
--- VC7TextDocument.cpp 18 May 2003 09:19:10 -0000 1.5
***************
*** 19,31 ****
{
CComPtr<EnvDTE::TextPoint> startPoint;
! document_->get_StartPoint( &startPoint );
CComPtr<EnvDTE::TextPoint> endPoint;
! document_->get_EndPoint( &endPoint );
CComPtr<EnvDTE::EditPoint> editPoint;
! startPoint->CreateEditPoint( &editPoint );
CComBSTR text;
! editPoint->GetText( CComVariant( &*endPoint), &text );
CString ctext( text );
--- 19,31 ----
{
CComPtr<EnvDTE::TextPoint> startPoint;
! VERIFY_COM( document_->get_StartPoint( &startPoint ) );
CComPtr<EnvDTE::TextPoint> endPoint;
! VERIFY_COM( document_->get_EndPoint( &endPoint ) );
CComPtr<EnvDTE::EditPoint> editPoint;
! VERIFY_COM( startPoint->CreateEditPoint( &editPoint ) );
CComBSTR text;
! VERIFY_COM( editPoint->GetText( CComVariant( &*endPoint), &text ) );
CString ctext( text );
***************
*** 40,44 ****
CComBSTR text;
! startPoint_->GetText( CComVariant( &*endPoint_), &text );
CString ctext( text );
--- 40,44 ----
CComBSTR text;
! VERIFY_COM( startPoint_->GetText( CComVariant( &*endPoint_), &text ) );
CString ctext( text );
***************
*** 51,58 ****
const std::string &text )
{
! setEditedRange( range );
! startPoint_->Delete( CComVariant( &*endPoint_) );
! startPoint_->Insert( CComBSTR( text.c_str() ) );
}
--- 51,58 ----
const std::string &text )
{
! setEditedRange( range );
! VERIFY_COM( startPoint_->Delete( CComVariant( &*endPoint_) ) );
! VERIFY_COM( startPoint_->Insert( CComBSTR( text.c_str() ) ) );
}
***************
*** 64,74 ****
{
CComPtr<EnvDTE::TextPoint> textPoint;
! document_->get_StartPoint( &textPoint );
! textPoint->CreateEditPoint( &startPoint_ );
! textPoint->CreateEditPoint( &endPoint_ );
}
! startPoint_->MoveToAbsoluteOffset( selection.getStartIndex()+1 );
! endPoint_->MoveToAbsoluteOffset( selection.getEndIndex()+1 );
}
--- 64,74 ----
{
CComPtr<EnvDTE::TextPoint> textPoint;
! VERIFY_COM( document_->get_StartPoint( &textPoint ) );
! VERIFY_COM( textPoint->CreateEditPoint( &startPoint_ ) );
! VERIFY_COM( textPoint->CreateEditPoint( &endPoint_ ) );
}
! VERIFY_COM( startPoint_->MoveToAbsoluteOffset( selection.getStartIndex()+1 ) );
! VERIFY_COM( endPoint_->MoveToAbsoluteOffset( selection.getEndIndex()+1 ) );
}
|