Click here to Skip to main content
15,881,803 members
Articles / Desktop Programming / MFC
Article

CvsIn Add-in for Visual Studio .NET 2002 and 2003 and Visual Studio 2005

Rate me:
Please Sign up or sign in to vote.
4.14/5 (4 votes)
22 Sep 2006CPOL3 min read 31.9K   446   14   1
CvsIn add-in for Visual Studio .NET 2002 and 2003 and Visual Studio 2005.

Sample Image - CvsInNetAddin.jpg

Introduction

I have used CvsIn by Jerzy Kaczorowski for Microsoft Visual Studio 6.0 for years. Although it is not very powerful, it is quite handy like the commit button. Microsoft Visual Studio also allows to define custom shortcut keys, such as Ctrl+D, Ctrl+U, and Ctrl+M, just like WinCvs. It is a pity that CvsIn was not updated later to support the new versions of Visual Studio. I continued the development to support MS Visual Studio .NET 2002 and 2003. However, some interface changes in Visual Studio 2005 made the old version not working. Other people might still be using this add-in, so I decided to share the code here.

Points of interest

Information output pane

A new information output pane is introduced for the CvsInNet version.

// This block of code is to create a "CvsIn" pane
// in Output window in function OnConnection.

IfFailGoCheck(m_pDTE->get_Windows(&spWindows), spWindows);
IfFailGoCheck
(
    spWindows->Item
    (
        CComVariant(CComBSTR(EnvDTE::vsWindowKindOutput)), 
        &spWindow
    ),
    spWindow
);

pDisp = NULL;
IfFailGoCheck(spWindow->get_Object(&pDisp), pDisp);

spOutputWindow = pDisp;
if (spOutputWindow == NULL)
    return E_FAIL;

IfFailGoCheck
(
    spOutputWindow->get_OutputWindowPanes(&spOutputWindowPanes),
    spOutputWindowPanes
);

hr = spOutputWindowPanes->Item
(
    CComVariant(OUTPANE_NAME), 
    &m_pOutputWindowPane
);

if (FAILED(hr))
{
    IfFailGoCheck
    (
        spOutputWindowPanes->Add
        (
            CComBSTR(OUTPANE_NAME), 
            &m_pOutputWindowPane
        ),
        m_pOutputWindowPane
    );
}

There is a function defined in the class CCommands, sometimes CConnect, in the AppWizard generated code:

void CvsInPrintToOutput(LPCTSTR lpszMessage, BOOL bPrefix = TRUE);

to show the message.

For example, this code outputs the welcome message:

strMsg.Format
(
    STR_MSG_WELCOME_FORMAT, 
    g_AICIntegrationManager.GetVersion(),
    STR_MSG_WELCOME, 
    CCvsCommandsTool::FormatTimeString()
);

CvsInPrintToOutput(strMsg, FALSE);

Here is the message:

Up and running! [2006/09/23 13:02:04.250]

Note: The AICIntetrationManager is not used in CvsInNet.

Other modules have to specify the CCommands instance to output the message.

m_pCommands->CvsInPrintToOutput(STR_MSG_RUNWINCVS_FAILED);

Custom add-in bitmaps

Please note that the transparency color has been changed since Visual Studio .NET 2002 to a special green color, RGB (0, 254, 0). The custom bitmaps embedded in the add-in DLL can still be used in VS.NET 2002 and 2003. Things have changed in VS 2005, like a resource DLL used to store the custom bitmaps. In the Eegistry, the strings SatelliteDllName and SatelliteDllPath are used for this purpose.

The interface of the command bar is also different in VS 2005, compared with VS.NET 2002 and 2003.

In VS.NET 2002 and 2003, it is the Office command bar:

CComPtr<Office::_CommandBars>   pCommandBars;
CComPtr<Office::CommandBar>     pCommandBar;
IfFailGoCheck(m_pDTE->get_Commands(&pCommands), pCommands);

and m_pDTE is defined as CComPtr<EnvDTE::_DTE> m_pDTE.

While in VS 2005, Microsoft_VisualStudio_CommandBars is used.

CComQIPtr<_CommandBars>         pCommandBars;
CComPtr<CommandBar>             pCommandBar;

and m_pDTE is defined as CComPtr<EnvDTE80::DTE2> m_pDTE.

The command information is defined on top of ConnectNet.cpp.

static CCommands::CommandInfo s_commandList[] =
{
    {L"CvsInOptions",               "", true,  false, IDB_CVS_OPTIONS, IDS_CMD_OPTIONS},
    {L"CvsInWinCvsSessionsManager", "", false,  false, 0, IDS_CMD_WINCVSSESSIONSMANAGER},
    // ...

    {L"CvsInWizard",                "", true,  false, IDB_CVS_WIZARD, IDS_CMD_CVSINWIZARD},
};

The resource number IDB_CVS_OPTIONS must have the same resource number as the one in the resource DLL, because SatelliteDll is not used in CvsIn for VS.NET 2002 and 2003.

The AddNamedCommand code for VS 2005 is:

pCommands2->AddNamedCommand2
(
    m_pAddInInstance,
    CComBSTR(commandInfo->m_name),
    CComBSTR(buttonText),
    CComBSTR(toolTip),
    VARIANT_FALSE,
    CComVariant(commandInfo->m_bitmapID),
    NULL,
    (
        EnvDTE::vsCommandStatusSupported
        +
        EnvDTE::vsCommandStatusEnabled
    ),
    EnvDTE80::vsCommandStylePict,
    EnvDTE80::vsCommandControlTypeButton,
    &pCreatedCommand
)

The fifth parameter, VARIANT_FALSE, means not to use the MS Office bitmaps.

The Registry file has satellite information:

val SatelliteDllName = s 'CvsInUI.dll'
val SatelliteDllPath = s '%MODULE_PATH%'

Among them, %MODULE_PATH% is a custom entry, which will be updated by the function UpdateRegistry in the class CCommands (from the MS Automation sample).

#if _MSC_VER < 1400
    DECLARE_REGISTRY_RESOURCEID(IDR_REGISTRY_VC7)
#else
 static HRESULT WINAPI UpdateRegistry( BOOL bRegister )
 {
  _ATL_REGMAP_ENTRY rgMap[ 2 ];
  memset( rgMap, '\0', sizeof( _ATL_REGMAP_ENTRY ) * 2 );

  TCHAR szModule[_MAX_PATH];
  GetModuleFileName(_Module.GetResourceInstance(), szModule, _MAX_PATH);
  PTCHAR pchSlash = strrchr( szModule, '\\' );
  if( pchSlash != NULL )  *pchSlash = '\0';

  USES_CONVERSION;
  rgMap[ 0 ].szKey  = OLESTR( "MODULE_PATH" );
  rgMap[ 0 ].szData = T2OLE( szModule );

  return _Module.UpdateRegistryFromResource(IDR_REGISTRY_VC8, 
                                   bRegister, rgMap );
 }
#endif

Debug the add-in

If you want to debug your add-in DLL, you may follow these steps (from VS 2005 Automation samples):

  1. In the Solution Explorer, right-click in the project and select Properties.
  2. Open Debugging, and make the following changes:
    • In "Command", enter the path to devenv.exe (e.g., c:\Program Files\Microsoft Visual Studio 8\Common7\IDE\devenv.exe).
    • Set "Command Arguments" to /resetaddin RegExplore.Connect.
    • In "Working Directory", enter the directory containing devenv.exe (e.g., c:\Program Files\Microsoft Visual Studio 8\Common7\IDE).

Some improvements

Some thread refinements to reduce the quick command button click crash.

WWhizInterface and usage

Use DllRegSrv32 to register the add-in DLLs. For VS 2005, make sure the resource DLL CvsInUI.dll is put under the directory 1033 of your add-in DLL.

If you want to use the wizard, WWhizInterface has to be installed. If you want to debug the CvsIn add-in DLL, the debug binaries of WWhizInterface are also needed. Please refer to WWhizInterface: Enhancements to the Visual C++ Automation Interface for more details.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionAddin XML Pin
alex_ng2-Mar-09 20:35
alex_ng2-Mar-09 20:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.