locked
Accessing DTE within VSPackage RRS feed

  • Question

  • 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.
    Wednesday, December 28, 2005 4:54 AM

Answers

  • 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);
    Wednesday, January 4, 2006 3:58 PM

All replies

  • 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.
    Wednesday, December 28, 2005 12:40 PM
  • 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

    Tuesday, January 3, 2006 7:46 PM
  • 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);
    Wednesday, January 4, 2006 3:58 PM
  • Note that you can use this approach to get any VS service from an add-in.
    Wednesday, January 4, 2006 3:59 PM
  • Thank you for your answer, but i am developing a VSPackage not an add-in and it is a little different approach 
    Tuesday, December 31, 2013 11:55 AM