locked
VS11RC, Add-Ins, C++, How do I get to the DTE object to get data from VS and to manipulate VS? RRS feed

  • Question

  • I'm using Visual Studio 11 (2012) RC. I'm trying to write my first Add-In in C++ / ATL. Using the Wizard to generate the project is smooth and easy. 

    I think that to get data from VS (such as which file has focus in the editor) and to manipulate VS (such as to position the cursor and write to the file) I need to access some object called DTE. Is this true? And if so, how do I do it?

    Intellisense lists DTE and DTE2 when I am in the Connect.cpp file but not when I am in the AddIn.cpp file. Some years have passed since I last coded in C++. I tried DTE. , DTE-> , and DTE:: . Intellisense did not give me a list.

    Through DTE or not, how do I access Visual Studio from the Add-In in C++ / ATL?


    Ron Lewis at Indinfer, Baltimore, Maryland, United States

    Wednesday, June 13, 2012 3:45 AM

Answers

  • You don't need to use DTE, it is one method of interacting with the environment. It is heavily IDispatch based and originally intended for exposing VS interfaces to scripting languages that understood COM (at least as far as IDispatch is concerned, that is about all they had to know). 

    Generally you need to get services (including DTE, which is just a service like any other VS service) via a service provider.  If you are writing an AddIn (as opposed to a package) I believe you are given an instance of DTE in CConnect::OnConnection.  You can QI that for IServiceProvider I believe, and use that to get just about any VS service you could want.

    You don't see anything in intellisense the AddIn.cpp file as that just exports the usual COM class factory methods, you aren't generally going to write code in that file.

    Ryan

    • Marked as answer by Indinfer Thursday, June 14, 2012 3:52 AM
    Wednesday, June 13, 2012 4:28 AM

All replies

  • You don't need to use DTE, it is one method of interacting with the environment. It is heavily IDispatch based and originally intended for exposing VS interfaces to scripting languages that understood COM (at least as far as IDispatch is concerned, that is about all they had to know). 

    Generally you need to get services (including DTE, which is just a service like any other VS service) via a service provider.  If you are writing an AddIn (as opposed to a package) I believe you are given an instance of DTE in CConnect::OnConnection.  You can QI that for IServiceProvider I believe, and use that to get just about any VS service you could want.

    You don't see anything in intellisense the AddIn.cpp file as that just exports the usual COM class factory methods, you aren't generally going to write code in that file.

    Ryan

    • Marked as answer by Indinfer Thursday, June 14, 2012 3:52 AM
    Wednesday, June 13, 2012 4:28 AM
  • Thank you. I think I found all the parts you mentioned (CCconnect::OnConnection, the instance of DTE2, etc.).

    Ron Lewis at Indinfer, Baltimore, Maryland United States

    Thursday, June 14, 2012 3:55 AM