Accessing DTE within VSPackage

Hi,

Is there anyway i can access DTE interface within a VSPackage I need this since i want to use a third party addin component, within a VSPackage, that is dependent on DTE.
In addition is there anyway to access the IVsTextView (or some other interface which can indirectly lead me to the aforementioned object) pointer within an addin using the EnvDTE::Window object (or some other EnvDTE::<*> object) Infact is there anyway to access the VSPackage specific interfaces within a regular addin (i.e. not a VSPackage) using any of the interfaces in the EnvDTE namespace

Any help will be highly appreciated.



Answer this question

Accessing DTE within VSPackage

  • phensahw

    Note that you can use this approach to get any VS service from an add-in.

  • Umapathy

    Here is a C# code sample for how to access the IVsTextManager interface from an add-in:

    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
         DTE2 applicationObject = (
    DTE2)application; 
        AddIn addInInstance = (AddIn)addInInst;
        IOleServiceProvider serviceProvider = (IOleServiceProvider)applicationObject;
        Guid SID = typeof(SVsTextManager).GUID;
        Guid IID = typeof(IVsTextManager).GUID;
        IntPtr output;
        serviceProvider.QueryService(
    ref SID, ref IID, out output); 
        IVsTextManager textManager = (
    IVsTextManager)Marshal.GetObjectForIUnknown(output);

  • Christian B

    There is no way to go back and forth between any extensibility interface and an interface that begins with IVs* simply by performing a QI. Just because they have similar names does not cause the interfaces to be implemented on the same object, in fact, usually they are specifically not implemented on the same object. You will need to find another way to get the IVsTextView interface, such as IVsTextManager, etc.

    Craig



  • Sreejith K

    Okay, i have found out how to access DTE within a VSPackage. However, i still need information on accessing IVsTextView (or any other interfaces that might lead to it) interface within a regular plugin (using EnvDTE)
    Shouldn't EnvDTE::Window be the same thing as an IVsCodeWindow I tried querying for it but returns NULL. Can someone help

    Thanks in advance.


  • Accessing DTE within VSPackage