Blog


Welcome to our blog. We hope that these pages provide an insight into us, our products and how we develop them. Please feel free to write to us if you have anything to add to any of the posts here.

   Current Entries | Archives   RSS

 


Visual Lint 1.0.2.43 has been released

Wednesday 18th January, 2006


We are pleased to announce that Visual Lint 1.0.2.43 is now available.

This version primarily addresses issues we have enountered with the RTM version of Visual Studio 2005 (we received our copies just before Christmas) which is proving to be significantly more picky and difficult to interface to than its predecessors.

There is still more to do (notably support for additional platforms and compatibility testing with other extensibility products with newly released VS2005 compatible versions) so there will be further releases in due course, but we are confident that the most significant issues have now been addressed.

The following changes are included in this version:

As an aside, Visual Lint is now built with WTL 7.5 final (7.5.5333.0). I can't emphasise how much easier the availability of a lightweight, well supported UI framework has helped us during the development of this product - in the past I've written similar projects using MFC, but this is by far more customisable and lightweight.

If you haven't looked at WTL yet, I'd strongly recommend you do so. It's certainly changed the way we look at new designs.

Posted by Anna at 9:33pm | Get Permalink


Why on earth can't they just leave interfaces alone?

Tuesday 17th January, 2006


...or: "why is it so difficult to figure out how to read the Visual C++ Include Folder configuration in VS2005?"

The answer is of course that the interfaces have been changed. I don't know why, but I do know that the method recommended by Microsoft no longer works.

In VS2002 and VS2003 expose interfaces to a collection of VCPlatform objects via DTE's properties collection, indexed by the name of the platform. Once you have a VCPlatform interface pointer, reading the include folder configuration is simplicity itself:

CString GetVcIncludeFolders(EnvDTE::_DTE* pDTE, const CString& sPlatform /*= _T("Win32")*/ )
{
    CString sIncludeFolders;

    try
    {
        EnvDTE::_DTEPtr ptrDTE;
        pDTE->QueryInterface(&ptrDTE);

        EnvDTE::PropertiesPtr ptrProperties = ptrDTE->GetProperties(L"Projects", L"VCDirectories");

        VCProjectEngineLibrary::IVCCollectionPtr ptrPlatforms = ptrProperties->Item(L"Platforms")->GetObject();
        ATLASSERT(ptrPlatforms != NULL);

        if (ptrPlatforms != NULL)
        {
            VCProjectEngineLibrary::VCPlatformPtr ptrPlatform = ptrPlatforms->Item(_bstr_t(sPlatform) );

            _bstr_t bsFolders = ptrPlatform->GetIncludeDirectories();

            sIncludeFolders = COLE2CT( ptrPlatform->Evaluate(bsFolders) );
        }
    }
    catch (const _com_error& e)
    {
#ifdef _DEBUG
         CString sMsg;
        sMsg.Format(_T("Unexpected exception 0x%X (%s) in %s()\n"),
                    e.Error(),
                     e.ErrorMessage(),
                    CA2CT( __FUNCTION__ ) );

        ATLTRACE(sMsg);
        ATLASSERT(false);
#endif
    }
    return sIncludeFolders;
}

Unfortunately, the available properties have changed in VS2005, and the "Platforms" collection is no longer exposed in this way, as a glance at the properties shown by the Extensibility Browser will show:

VCDirectories properties in VS2003
VCDirectories properties in Visual Studio .NET 2003.
VCDirectories properties in VS2005
VCDirectories properties in Visual Studio 2005.

When we realised this our first thought was to try to obtain a VCProjectEngine interface somehow - from there the Platforms collection is directly accessible. Unfortunately all the examples in MSDN and elsewhere show VCProjectEngine interfaces being obtained from an EnvDTE::Project object, as follows (apologies for the VB!), and we can't use this method if there is no solution open:

' add reference to Microsoft.VisualStudio.VCProjectEngine

Imports EnvDTE
Imports Microsoft.VisualStudio.VCProjectEngine

Public Module Module1
    Sub Test()
        Dim prj As VCProject
        Dim cfgs, tools As IVCCollection
        Dim cfg As VCConfiguration
        Dim p As VCPlatform
        Dim x As String
        prj = DTE.Solution.Projects.Item(1).Object
        p = prj.Platforms(1)
        x = p.IncludeDirectories
        p.IncludeDirectories = x + ";something"
        MsgBox(p.IncludeDirectories)
    End Sub
End Module

The key was finding a way to obtain a VCProjectEngine interface pointer without going through a Project. Although Microsoft suggest you can create an instance of this object directly like this:

    VCProjectEngineLibrary::VCProjectEnginePtr ptrEngine;

    ptrEngine.CreateInstance( __uuidof(VCProjectEngineLibrary::VCProjectEngineObject),
                              NULL,
                              CLSCTX_INPROC_SERVER);

this is not a safe operation to perform within the IDE, certainly under VS2005. We saw some sorts of strange and unpleasant side effects when we explored this route!

Thankfully there is another way, albeit an undocumented one. The VCProjects collection (accessible via a property of DTE itself) can be used to obtain a VCProjectEngine interface pointer, and thereafter it is straightforward:

CString GetVcIncludeFolders(EnvDTE::_DTE* pDTE, const CString& sPlatform /*= _T("Win32")*/)
{
    CString sIncludeFolders;

    if (pDTE != NULL)
    {
        try
        {
            EnvDTE::_DTEPtr ptrDTE;
            pDTE->QueryInterface(&ptrDTE);

            EnvDTE::ProjectsPtr ptrProjects = pDTE->GetObject(L"VCProjects");

            VCProjectEngineLibrary::VCProjectEnginePtr ptrProjectEngine =
                ptrProjects->GetProperties()->Item(L"VCProjectEngine")->GetObject();

            if (ptrProjectEngine != NULL)
            {
                VCProjectEngineLibrary::IVCCollectionPtr ptrVcPlatforms =
                    ptrVCProjectEngine->GetPlatforms();

                VCProjectEngineLibrary::VCPlatformPtr ptrPlatform = ptrVcPlatforms->Item( _bstr_t(sPlatform) );

                sIncludeFolders = COLE2CT( ptrPlatform->Evaluate( ptrPlatform->GetIncludeDirectories() ) );
            }
        }
        catch (const _com_error& e)
        {
#ifdef _DEBUG
            CString sMsg;
            sMsg.Format(_T("Unexpected exception 0x%X (%s) in %s()\n"),
            e.Error(),
            e.ErrorMessage(),
            CA2CT( __FUNCTION__() ) );

            ATLTRACE(sMsg);
            ATLASSERT(false);
#endif
        }
    }
    ATLASSERT(!sIncludeFolders.IsEmpty() );

    return sIncludeFolders;
}

Fortunately, the same code also works in VS2002 and VS2003.

Posted by Anna at 11:49pm | Get Permalink