Click here to Skip to main content
14,029,591 members
Click here to Skip to main content
Add your own
alternative version


53 bookmarked
Posted 17 Apr 2002

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


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 The picture above shows the generated dependency graph of one of my projects.


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


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!


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
                    If (ob.dependency.Checked) Then
                        ScanDependencies(cl)    'also scan all dependencies of the class
                    End If
                End If

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


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 :-)

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!


July 9 2002 - updated setup download.

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


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


About the Author

Software Developer
Switzerland Switzerland

You may also be interested in...

Comments and Discussions

GeneralVisual Studio 2005 Pin
Wex Viator17-Jan-06 14:59
memberWex Viator17-Jan-06 14:59 
GeneralRe: Visual Studio 2005 Pin
andy thecoder10-Jan-08 8:21
memberandy thecoder10-Jan-08 8:21 
Generalc++ Pin
ccolgal1-Oct-05 4:17
memberccolgal1-Oct-05 4:17 
GeneralNeeds to recompile Pin
acraft7-Dec-04 9:12
memberacraft7-Dec-04 9:12 
GeneralSuggestion: Postscript output Pin
armentage17-Mar-04 6:09
memberarmentage17-Mar-04 6:09 
QuestionDoes this tool works in Visual C++ 6.0 on C project? Pin
Tal Rosenberger14-Feb-04 10:43
memberTal Rosenberger14-Feb-04 10:43 
AnswerRe: Does this tool works in Visual C++ 6.0 on C project? Pin
Kevin Zhang27-Apr-04 17:43
memberKevin Zhang27-Apr-04 17:43 
GeneralDoesn't know Namespaces Pin
gschroecker16-Sep-03 23:51
membergschroecker16-Sep-03 23:51 
GeneralRe: Doesn't know Namespaces Pin
SteveKing17-Sep-03 10:37
memberSteveKing17-Sep-03 10:37 
Question.NET 2003 ? Pin
tim_edwards25-May-03 19:58
membertim_edwards25-May-03 19:58 
AnswerRe: .NET 2003 ? Pin
a_schweitzer17-Oct-03 7:17
membera_schweitzer17-Oct-03 7:17 
GeneralRe: .NET 2003 ? Pin
SteveKing18-Oct-03 1:42
memberSteveKing18-Oct-03 1:42 
AnswerRe: .NET 2003 !! Pin
S. Becker10-Aug-04 19:49
memberS. Becker10-Aug-04 19:49 
QuestionGenerator for Nassi-Shneiderman Diagrams? Pin
Uwe Keim29-Oct-02 21:28
sitebuilderUwe Keim29-Oct-02 21:28 
AnswerRe: Generator for Nassi-Shneiderman Diagrams? Pin
redjoy28-Jul-06 16:49
memberredjoy28-Jul-06 16:49 
GeneralNo graph Pin
Brian D Pearson10-Jul-02 18:24
memberBrian D Pearson10-Jul-02 18:24 
GeneralRe: No graph Pin
SteveKing10-Jul-02 22:59
memberSteveKing10-Jul-02 22:59 
GeneralRe: No graph - almost Pin
Brian D Pearson12-Jul-02 2:53
memberBrian D Pearson12-Jul-02 2:53 
GeneralRe: No graph - almost Pin
SteveKing12-Jul-02 10:31
memberSteveKing12-Jul-02 10:31 
GeneralRe: Graph - atlast Pin
Brian D Pearson13-Jul-02 2:26
memberBrian D Pearson13-Jul-02 2:26 
GeneralRe: Graph - atlast Pin
SteveKing14-Jul-02 1:34
memberSteveKing14-Jul-02 1:34 
GeneralBad installation path Pin
John Johansson8-Jul-02 21:53
memberJohn Johansson8-Jul-02 21:53 
Generalupdate Pin
SteveKing9-Jul-02 6:51
memberSteveKing9-Jul-02 6:51 
GeneralError in AddIn (Class not registered) Pin
23-Apr-02 22:22
suss23-Apr-02 22:22 
GeneralRe: Error in AddIn (Class not registered) Pin
SteveKing24-Apr-02 8:33
memberSteveKing24-Apr-02 8:33 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190419.4 | Last Updated 9 Jul 2002
Article Copyright 2002 by SteveKing
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid