I have been trying to create an Add-In that reads the contents of certain C++ files, in a project. I have had success with previous add-ins in the past and I started to enjoy EnvDTE - but using VCProject - and VCCodeModel - proves a lot more challenging, nothing I try works.
I have typed the code from Microsoft sites identically... example: http://msdn.microsoft.com/en-US/library/ms228770(v=vs.100).aspx
public void test( DTE2 application)
{
try
{
VCCodeModel vcCM = null;
VCCodeElement vcCodeElement = null;
vcCM = ((VCCodeModel (application.Solution.Item(1).CodeModel));
vcCodeElement = ((VCCodeElement) (vcCM.CodeElements.Item(1)));
// AddCommentAtStart(vcCodeElement);
// AddCommentAtEnd(vcCodeElement);
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}I have tried a lot of other examples, nothing I try works - it all fails at the very beginning, at the simplest cast.
So far I have been able to iterate through the ProjectItems and get the .cpp and .h files included, and... what I really would like to do is get a list of #includes from these files. Like http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vccodemodel.vccodeinclude.aspx... Except it doesn't work...
I have started something like
public void GetIncludes(ProjectItem projectItem)
{ try
{
FileCodeModel fileCodeModel = projectItem.FileCodeModel;
CodeElement codeElem = fileCodeModel.CodeElements.Item(1);
// nothing else would work
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message + "\n" + ex.StackTrace.ToString());
}
}Please, can somebody help me get something to work ?
Thank you.