1
// AddInMod.cpp : implementation file
7
// Turn off warnings due to long names arising out of STL use
8
#pragma warning ( disable : 4786 4503 )
10
#include "CcccDevStudioAddIn.h"
17
static char THIS_FILE[] = __FILE__;
20
// This is called when the user first loads the add-in, and on start-up
21
// of each subsequent Developer Studio session
22
STDMETHODIMP CDSAddIn::OnConnection(IApplication* pApp, VARIANT_BOOL bFirstTime,
23
long dwCookie, VARIANT_BOOL* OnConnection)
25
AFX_MANAGE_STATE(AfxGetStaticModuleState());
27
// Store info passed to us
28
IApplication* pApplication = NULL;
29
if (FAILED(pApp->QueryInterface(IID_IApplication, (void**) &pApplication))
30
|| pApplication == NULL)
32
*OnConnection = VARIANT_FALSE;
36
m_dwCookie = dwCookie;
38
// Create command dispatch, send info back to DevStudio
39
CCommandsObj::CreateInstance(&m_pCommands);
40
m_pCommands->AddRef();
42
// The QueryInterface above AddRef'd the Application object. It will
43
// be Release'd in CCommand's destructor.
44
m_pCommands->SetApplicationObject(pApplication);
46
// (see stdafx.h for the definition of VERIFY_OK)
48
VERIFY_OK(pApplication->SetAddInInfo((long) AfxGetInstanceHandle(),
49
(LPDISPATCH) m_pCommands, IDR_TOOLBAR_MEDIUM, IDR_TOOLBAR_LARGE, m_dwCookie));
51
// Inform DevStudio of the commands we implement
53
// TODO: Replace the AddCommand call below with a series of calls,
54
// one for each command your add-in will add.
56
// The command name should not be localized to other languages. The
57
// tooltip, command description, and other strings related to this
58
// command are stored in the string table (IDS_CMD_STRING) and should
60
addCommand(pApplication,
61
"runCCCCOnActiveFile","run CCCC on the active file",
63
addCommand(pApplication,
64
"runCCCCOnProjectFiles","run CCCC on all files in the active project",
66
addCommand(pApplication,
67
"runCCCCOnWorkspaceFiles","run CCCC on all files in the active workspace",
69
addCommand(pApplication,
70
"configureCCCCDevStudioAddIn","configure the add-in",
76
char userCommandName[1024], userCommandTip[1024];
77
sprintf(userCommandName,"UserCommand%d",i+1);
78
sprintf(userCommandTip,"User defined command #%d",i+1);
79
addCommand(pApplication,
80
userCommandName,userCommandTip,i+4,bFirstTime);
84
*OnConnection = VARIANT_TRUE;
88
// This is called on shut-down, and also when the user unloads the add-in
89
STDMETHODIMP CDSAddIn::OnDisconnection(VARIANT_BOOL bLastTime)
91
AFX_MANAGE_STATE(AfxGetStaticModuleState());
93
m_pCommands->Release();
96
// TODO: Perform any cleanup work here
101
void CDSAddIn::addCommand(IApplication* pApp, LPCSTR methodName, LPCSTR methodTip, long imageIndex, VARIANT_BOOL bFirstTime)
105
// We can simplify on the MS boilerplate code
106
// for this activity by deciding that the command name
107
// and the method name will always be the same.
108
CComBSTR bszMethodName(methodName);
109
CComBSTR bszCmdName(methodName);
111
// We still have to build up the command string
112
CString strMethodName(methodName);
113
CString strCmdString;
115
strMethodName + "\n" +
116
strMethodName + "\n" +
120
CComBSTR bszCmdString(strCmdString);
122
VERIFY_OK(pApp->AddCommand(bszCmdString, bszMethodName, imageIndex, m_dwCookie, &bRet));
123
if (bRet == VARIANT_FALSE)
125
AfxMessageBox("Failed to load command");
130
// Add toolbar buttons only if this is the first time the add-in
131
// is being loaded. Toolbar buttons are automatically remembered
132
// by Developer Studio from session to session, so we should only
133
// add the toolbar buttons once.
134
if (bFirstTime == VARIANT_TRUE)
137
AddCommandBarButton(dsGlyph, bszCmdName, m_dwCookie));