分享

DTE(vs2012) 编程相关笔记

 ThinkTank_引擎 2014-07-08

DTE(vs2012) 编程相关笔记

仅作记录,方便以后查阅。


1. Reference related:

envdte 

envdte80

envdte90

envdte100 

Microsoft.VisualStudio.Shell.11.0 

...... 

 

2. Create DTE instance 

// way1 
EnvDTE80.DTE2 _dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.11.0"); 
 // way2
Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.11.0");
EnvDTE80.DTE2 _dte2 = Activator.CreateInstance(visualStudioType) as EnvDTE80.DTE2; 

 

 

3. Get Service from DTE

很多时候,想取shell相关的service,但是用Package.GlobalProvider.GetService(xxx)不行,但是代码在extension和Addin里面可以,所以估计Package的使用范围有限制。

所以必须想办法从DTE去绕。 

 

IVsUIShell vsUIShell = (new ServiceProvider(DTEInstance as Microsoft.VisualStudio.OLE.Interop.IServiceProvider)).GetService(typeof(SVsShell)) as IVsUIShell;

 

 

4. Some com interface not allowed used though they are public seen by refactor 

自己动手重新包一遍,比如

 

复制代码
     [ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), TypeIdentifier, Guid("0D915B59-2ED7-472A-9DE8-9161737EA1C5")]
    public interface SVsColorThemeService
    {
    }
    [ComImport, TypeIdentifier, Guid("EAB552CF-7858-4F05-8435-62DB6DF60684"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IVsColorThemeService
    {
        void _VtblGap1_4();
        IVsColorThemes Themes { [return: MarshalAs(UnmanagedType.Interface)] get; }
        object ColorNames { [return: MarshalAs(UnmanagedType.Interface)] get; }
        IVsColorTheme CurrentTheme { [return: MarshalAs(UnmanagedType.Interface)] get; }
    }
复制代码

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多