summaryrefslogtreecommitdiff
path: root/src/msvc6/DSPlugIn/DSAddIn.cpp
blob: ab8180ee71e49f26e7ab4f93ac2a6b46dbfdbb5a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// AddInMod.cpp : implementation file
//

#include "stdafx.h"

#include "DSPlugIn.h"
#include "COMHelper.h"
#include "DSAddIn.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif


COMUtility::COMExceptionThrower CDSAddIn::cex_;

CDSAddIn::~CDSAddIn( void)
{
}

// This is called when the user first loads the add-in, and on start-up
//  of each subsequent Developer Studio session
STDMETHODIMP CDSAddIn::OnConnection(IApplication* pApp, VARIANT_BOOL bFirstTime,
		long dwCookie, VARIANT_BOOL* OnConnection)
{
  HRESULT result = S_OK;

  try
  {
    CComPtr< IUnknown> pIUnk;

	  AFX_MANAGE_STATE(AfxGetStaticModuleState());

    cex_ = _Module.GetClassObject( GetObjectCLSID(), IID_IUnknown, reinterpret_cast<void**>(&pIUnk));

    cex_ = CoRegisterClassObject( 
      GetObjectCLSID(),
      pIUnk,
      CLSCTX_LOCAL_SERVER,
      REGCLS_MULTIPLEUSE,
      &classRegistrationId_
      );

    pIApp_ = pApp;

    m_dwCookie = dwCookie;
    *OnConnection = VARIANT_TRUE;
  }
  catch( const std::bad_cast&)
  {
    *OnConnection = VARIANT_FALSE;
  }
  catch( const _com_error&)
  {
    *OnConnection = VARIANT_FALSE;
  }

  return result;
}

// This is called on shut-down, and also when the user unloads the add-in
STDMETHODIMP CDSAddIn::OnDisconnection(VARIANT_BOOL bLastTime)
{
  pIApp_.Release();
  CoRevokeClassObject( classRegistrationId_);

	return S_OK;
}


// ITestRunnerDSPlugin
STDMETHODIMP CDSAddIn::goToLineInSourceCode( BSTR fileName, int lineNumber)
{
  HRESULT result = S_OK;

	AFX_MANAGE_STATE(AfxGetStaticModuleState());

  try
  {
    CComPtr< IDispatch> tmp;
    CComPtr< IDocuments> pIDocuments;
    CComPtr< ITextDocument> pITextDocu;
    CComPtr< ITextSelection> pITextSel;

    cex_ = pIApp_->get_Documents( &tmp);
    pIDocuments.Attach( COMUtility::interface_cast<IDocuments>( tmp.p));
    tmp.Release();
    cex_ = pIDocuments->Open( fileName,
                             CComVariant(),
                             CComVariant(),
                             &tmp);
    pITextDocu.Attach( COMUtility::interface_cast< ITextDocument>( tmp.p));
    tmp.Release();
    cex_ = pITextDocu->get_Selection( &tmp);
    pITextSel.Attach( COMUtility::interface_cast< ITextSelection>( tmp.p));
    cex_ = pITextSel->GoToLine( lineNumber, CComVariant( 1));
  }
  catch( const std::bad_cast&)
  {
    result = E_FAIL;
  }
  catch( const _com_error&)
  {
    result = E_FAIL;
  }
  
  return result;
}