Click here to Skip to main content
Click here to Skip to main content
Go to top

Dependency-Grapher for C++-Projects

, 8 Jul 2002
Rate this:
Please Sign up or sign in to vote.
An add-in written in VB.NET to generate an inheritance and/or dependency graph of a c++-project. Uses the graphviz library from AT&T.
<!-- Article image -->

Sample Image - ClassDep.jpg

Description

ClassDep is an add-in which generates a JPEG or JPG image showing an inheritance and/or a dependency graph of a C++ project in visual studio. is uses the graphviz tools from http://www.research.att.com/sw/tools/graphviz/. The picture above shows the generated dependency graph of one of my projects.

Installation

Just double-click on the msi file and follow the installation instructions. All files from the graphviz library are included in the msi file.

Usage

to use the addin simply click on the ClassDep-Entry in the Tool-Menu of Visual Studio .NET. It only works for C++ projects (C# and VB are not supported). The resulting picture files are stored in the corresponding project folder with the name(s) projectdep.jpg and/or projectdep.png. Please note that the picture files may become really huge for big projects!

Implementation

for generating inheritance/dependency graphs it is usually necessary to parse the source code. but you sure have already noticed that visual studio does that in the "class-view"-window - it shows the base classes and the members of all project classes. So I wondered if and how I could use this built-in functionality of visual studio for my needs. the DTE-object was the perfect solution:

Dim applicationObject As EnvDTE.DTE
Dim project As Project

   For Each project In applicationObject.ActiveSolutionProjects()
	   '...

            'read out all c++-related object in the current project
            BuildObjectList(project.CodeModel.CodeElements, 0)		
            For Each cl In project.CodeModel.CodeElements
                If (cl.Kind = vsCMElement.vsCMElementClass) Then
                    'cl is a class
                    ScanBases(cl, 0)    'scan all base classes/structs
                    depfile.WriteLine(";")
                    If (ob.dependency.Checked) Then
                        ScanDependencies(cl)    'also scan all dependencies of the class
                    End If
                End If
            Next
            '...

I started first with a macro and then decided to switch to an add-in because of the easier installation. That's the reason why this add-in is written in VB.

one problem of an addin is that I don't know a way to get the path of where the addin-dll is installed. that is also the path where the graphviz files are installed and I need to know that to use these files. the only way I know of is by using the registry. So the installation msi writes also a registry entry with the installation path:

Dim dotdir As String
dotdir = Registry.LocalMachine.OpenSubKey( _
                "Software\Microsoft\VisualStudio\7.0\AddIns\ClassDep.Connect", _
                False).GetValue("instpath", " ")

and last the call to the graphviz tools:

If ob.outjpeg.Checked Then
	'call the graphviz tool with required params to generate the jpeg
	Shell(dotdir + "\dot.exe -Tjpg """ + dir + "dep.txt"" -o """ + dir +_
               project.Name + "dep.jpg""", AppWinStyle.MinimizedFocus, True)
End If
If ob.outpng.Checked Then
	Shell(dotdir + "\dot.exe -Tpng """ + dir + "dep.txt"" -o """ + dir +_
                project.Name + "dep.png""", AppWinStyle.MinimizedFocus, True)
End If

Conclusion

There are a lot of improvements possible like a better ordering of the dependency graph and the like. Some of you might find the colors awful - feel free to change that Smile | :)

I also included the graphviz files inside the msi-installer. As far as I understand the license of the graphviz this is allowed - mail me if I'm wrong.

If someone knows how to change that ugly smiley-icon of the menu-entry please let me know!

History

July 9 2002 - updated setup download.

July 15 2002 - fixed uncaught exception bug found by Brian D Pearson

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

SteveKing
Software Developer
Switzerland Switzerland
---

Comments and Discussions

 
GeneralVisual Studio 2005 PinmemberWex Viator17-Jan-06 14:59 
GeneralRe: Visual Studio 2005 Pinmemberandy thecoder10-Jan-08 8:21 
Generalc++ Pinmemberccolgal1-Oct-05 4:17 
GeneralNeeds to recompile Pinmemberacraft7-Dec-04 9:12 
GeneralSuggestion: Postscript output Pinmemberarmentage17-Mar-04 6:09 
QuestionDoes this tool works in Visual C++ 6.0 on C project? PinmemberTal Rosenberger14-Feb-04 10:43 
Does this tool works in Visual C++ 6.0 on C project?
Thanks,
TR
AnswerRe: Does this tool works in Visual C++ 6.0 on C project? PinmemberKevin Zhang27-Apr-04 17:43 
GeneralDoesn't know Namespaces Pinmembergschroecker16-Sep-03 23:51 
GeneralRe: Doesn't know Namespaces PinmemberSteveKing17-Sep-03 10:37 
Question.NET 2003 ? Pinmembertim_edwards25-May-03 19:58 
AnswerRe: .NET 2003 ? Pinmembera_schweitzer17-Oct-03 7:17 
GeneralRe: .NET 2003 ? PinmemberSteveKing18-Oct-03 1:42 
AnswerRe: .NET 2003 !! PinmemberS. Becker10-Aug-04 19:49 
QuestionGenerator for Nassi-Shneiderman Diagrams? PinsitebuilderUwe Keim29-Oct-02 21:28 
AnswerRe: Generator for Nassi-Shneiderman Diagrams? Pinmemberredjoy28-Jul-06 16:49 
GeneralNo graph PinmemberBrian D Pearson10-Jul-02 18:24 
GeneralRe: No graph PinmemberSteveKing10-Jul-02 22:59 
GeneralRe: No graph - almost PinmemberBrian D Pearson12-Jul-02 2:53 
GeneralRe: No graph - almost PinmemberSteveKing12-Jul-02 10:31 
GeneralRe: Graph - atlast PinmemberBrian D Pearson13-Jul-02 2:26 
GeneralRe: Graph - atlast PinmemberSteveKing14-Jul-02 1:34 
GeneralBad installation path PinmemberJohn Johansson8-Jul-02 21:53 
Generalupdate PinmemberSteveKing9-Jul-02 6:51 
GeneralError in AddIn (Class not registered) PinmemberSelux23-Apr-02 22:22 
GeneralRe: Error in AddIn (Class not registered) PinmemberSteveKing24-Apr-02 8:33 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 9 Jul 2002
Article Copyright 2002 by SteveKing
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid