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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
// MsDevCallerListCtrl.cpp : implementation file
//
#include "stdafx.h"
#include <atlbase.h>
#include "MsDevCallerListCtrl.h"
#include <msvc6/testrunner/TestRunner.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
// VC6 IDE Handler
// //////////////////////////////////////////////////////////////////
#if _MSC_VER == 1200 // VC++ 6
#include <msvc6/DSPlugin/TestRunnerDSPluginVC6.h>
namespace VC6IdeHandler {
static bool initialize()
{
return SUCCEEDED( CoInitialize(NULL) );
}
static void uninitialize( bool initialized )
{
if ( initialized )
CoUninitialize();
}
static void goToLineInSourceCode( CString fileName, int line )
{
CComPtr< ITestRunnerDSPlugin> pIDSPlugin;
HRESULT hr = CoCreateInstance( CLSID_DSAddIn,
NULL,
CLSCTX_LOCAL_SERVER,
IID_ITestRunnerDSPlugin,
reinterpret_cast< void**>(&pIDSPlugin) );
if ( SUCCEEDED( hr ) )
{
pIDSPlugin->goToLineInSourceCode( CComBSTR( fileName ),
line );
}
}
} // namespace VC6IdeHandler
namespace IDEHandler = VC6IdeHandler;
// VC7 IDE Handler
// //////////////////////////////////////////////////////////////////
#elif _MSC_VER >= 1300 // VC++ 7 or more
#include <initguid.h>
#include <assert.h>
#pragma warning( disable : 4278 )
#pragma warning( disable : 4146 )
#if (_MSC_VER == 1300)
#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("7.0") lcid("0") raw_interfaces_only named_guids
#elif (_MSC_VER == 1400)
#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("8.0") lcid("0") raw_interfaces_only named_guids
#else
#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("9.0") lcid("0") raw_interfaces_only named_guids
#endif
#pragma warning( default : 4146 )
#pragma warning( default : 4278 )
namespace VC7IdeHandler {
static bool initialize()
{
return true;
}
static void uninitialize( bool initialized )
{
}
static void goToLineInSourceCode( CString fileName, int line )
{
USES_CONVERSION;
CComPtr< IRunningObjectTable > pIRunningObjectTable;
HRESULT hr = ::GetRunningObjectTable( 0, &pIRunningObjectTable );
CComPtr< IEnumMoniker > pIEnumMoniker;
hr = pIRunningObjectTable->EnumRunning( &pIEnumMoniker );
CComPtr< EnvDTE::_DTE > pIEnvDTE;
while ( true )
{
ULONG celtFetched;
CComPtr< IMoniker > pIMoniker;
if ( S_OK != pIEnumMoniker->Next( 1, &pIMoniker, &celtFetched ) )
break;
CComPtr< IBindCtx > pIBindCtx;
hr = ::CreateBindCtx( NULL, &pIBindCtx );
LPOLESTR pszDisplayName;
pIMoniker->GetDisplayName( pIBindCtx, NULL, &pszDisplayName );
TRACE( "Moniker %s\n", W2A( pszDisplayName ) );
CString strDisplayName( pszDisplayName );
CComPtr< IMalloc > pIMalloc;
::CoGetMalloc( 1, &pIMalloc );
pIMalloc->Free( pszDisplayName );
if ( strDisplayName.Right( 4 ) == _T(".sln")
|| strDisplayName.Find( _T("VisualStudio.DTE") ) >= 0 )
{
CComPtr< IUnknown > pIUnknown;
pIRunningObjectTable->GetObject( pIMoniker, &pIUnknown );
pIUnknown->QueryInterface( &pIEnvDTE );
if( pIEnvDTE.p )
break;
}
}
if ( pIEnvDTE.p )
{
CComPtr< EnvDTE::Documents > pIDocuments;
HRESULT result = pIEnvDTE->get_Documents( &pIDocuments );
if ( !SUCCEEDED( result ) )
return;
assert( pIDocuments.p );
CComPtr< EnvDTE::Document > pIDocument;
CComBSTR bstrFileName( fileName );
CComVariant type=_T("Text");
CComVariant read=_T("False");
result = pIDocuments->Open( bstrFileName,
type.bstrVal,
read.bVal,
&pIDocument );
if ( !SUCCEEDED( result ) )
return;
assert( pIDocument.p );
CComPtr< IDispatch > pIDispatch;
result = pIDocument->get_Selection( &pIDispatch );
if ( !SUCCEEDED( result ) )
return;
CComPtr< EnvDTE::TextSelection > pITextSelection;
pIDispatch->QueryInterface( &pITextSelection );
assert( pITextSelection.p );
result = pITextSelection->GotoLine( line, TRUE );
if ( !SUCCEEDED( result ) )
return;
}
}
} // namespace VC7IdeHandler
namespace IDEHandler = VC7IdeHandler;
#else
#error Unsupported VC++ version.
#endif
/////////////////////////////////////////////////////////////////////////////
// MsDevCallerListCtrl
MsDevCallerListCtrl::MsDevCallerListCtrl()
: m_lineNumberSubItem( 3 )
, m_fileNameSubItem( 4 )
{
m_initialized = IDEHandler::initialize();
}
MsDevCallerListCtrl::~MsDevCallerListCtrl()
{
IDEHandler::uninitialize( m_initialized );
}
void
MsDevCallerListCtrl::setLineNumberSubItem( int subItemIndex )
{
m_lineNumberSubItem = subItemIndex;
}
void
MsDevCallerListCtrl::setFileNameSubItem( int fileNameItemIndex )
{
m_fileNameSubItem = fileNameItemIndex;
}
BEGIN_MESSAGE_MAP(MsDevCallerListCtrl, CListCtrl)
//{{AFX_MSG_MAP(MsDevCallerListCtrl)
ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// MsDevCallerListCtrl message handlers
void MsDevCallerListCtrl::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
// get index of selected item
POSITION pos = GetFirstSelectedItemPosition();
int hotItem = GetNextSelectedItem(pos);
CString lineNumber = GetItemText( hotItem, m_lineNumberSubItem);
CString fileName = GetItemText( hotItem, m_fileNameSubItem);
IDEHandler::goToLineInSourceCode( fileName, _ttoi( lineNumber) );
*pResult = 0;
}
|