1 people like it.

Get running Visual Studio instances as DTE objects

Get running Visual Studio instances as DTE objects. Based on https://stackoverflow.com/a/14205934

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
18: 
19: 
20: 
21: 
22: 
23: 
24: 
25: 
26: 
27: 
28: 
29: 
30: 
#r "EnvDTE"
open System
open System.Runtime.InteropServices
open System.Runtime.InteropServices.ComTypes
open EnvDTE
// https://stackoverflow.com/a/14205934
module Platform =
  let [<Literal>] dllName = "ole32.dll"
  [<DllImport(dllName)>] extern int GetRunningObjectTable(int reserved, [<Out>] IRunningObjectTable& prot)
  [<DllImport(dllName)>] extern void CreateBindCtx(int reserved, [<Out>] IBindCtx& ppbc)


let getDTEInstances () =
  [
  let mutable rot : IRunningObjectTable = null
  if Platform.GetRunningObjectTable(0, &rot) = 0 then
    let mutable enumMoniker : IEnumMoniker ref = ref null
    rot.EnumRunning(enumMoniker)
    let mutable moniker : IMoniker array = Array.zeroCreate 1
    let mutable fetched = IntPtr.Zero
    while enumMoniker.Value.Next(1, moniker, fetched) = 0 do
      let mutable bindCtx : IBindCtx = null
      Platform.CreateBindCtx(0, &bindCtx)
      let mutable displayName : string ref = ref null
      moniker.[0].GetDisplayName(bindCtx, null, displayName)
      if displayName.Value.StartsWith "!VisualStudio" then
        let o : obj ref = ref null
        rot.GetObject(moniker.[0], o) |> ignore
        yield (o.Value :?> DTE)
  ]
namespace System
namespace System.Runtime
namespace System.Runtime.InteropServices
namespace System.Runtime.InteropServices.ComTypes
Multiple items
type LiteralAttribute =
  inherit Attribute
  new : unit -> LiteralAttribute

Full name: Microsoft.FSharp.Core.LiteralAttribute

--------------------
new : unit -> LiteralAttribute
val dllName : string

Full name: Script.Platform.dllName
Multiple items
type DllImportAttribute =
  inherit Attribute
  new : dllName:string -> DllImportAttribute
  val EntryPoint : string
  val CharSet : CharSet
  val SetLastError : bool
  val ExactSpelling : bool
  val PreserveSig : bool
  val CallingConvention : CallingConvention
  val BestFitMapping : bool
  val ThrowOnUnmappableChar : bool
  member Value : string

Full name: System.Runtime.InteropServices.DllImportAttribute

--------------------
DllImportAttribute(dllName: string) : unit
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
val GetRunningObjectTable : reserved:int * prot:byref<IRunningObjectTable> -> int

Full name: Script.Platform.GetRunningObjectTable
val reserved : int
Multiple items
type OutAttribute =
  inherit Attribute
  new : unit -> OutAttribute

Full name: System.Runtime.InteropServices.OutAttribute

--------------------
OutAttribute() : unit
type IRunningObjectTable =
  member EnumRunning : ppenumMoniker:IEnumMoniker -> unit
  member GetObject : pmkObjectName:IMoniker * ppunkObject:obj -> int
  member GetTimeOfLastChange : pmkObjectName:IMoniker * pfiletime:FILETIME -> int
  member IsRunning : pmkObjectName:IMoniker -> int
  member NoteChangeTime : dwRegister:int * pfiletime:FILETIME -> unit
  member Register : grfFlags:int * punkObject:obj * pmkObjectName:IMoniker -> int
  member Revoke : dwRegister:int -> unit

Full name: System.Runtime.InteropServices.ComTypes.IRunningObjectTable
val prot : byref<IRunningObjectTable>
val CreateBindCtx : reserved:int * ppbc:byref<IBindCtx> -> unit

Full name: Script.Platform.CreateBindCtx
type IBindCtx =
  member EnumObjectParam : ppenum:IEnumString -> unit
  member GetBindOptions : pbindopts:BIND_OPTS -> unit
  member GetObjectParam : pszKey:string * ppunk:obj -> unit
  member GetRunningObjectTable : pprot:IRunningObjectTable -> unit
  member RegisterObjectBound : punk:obj -> unit
  member RegisterObjectParam : pszKey:string * punk:obj -> unit
  member ReleaseBoundObjects : unit -> unit
  member RevokeObjectBound : punk:obj -> unit
  member RevokeObjectParam : pszKey:string -> int
  member SetBindOptions : pbindopts:BIND_OPTS -> unit

Full name: System.Runtime.InteropServices.ComTypes.IBindCtx
val ppbc : byref<IBindCtx>
val getDTEInstances : unit -> 'a list

Full name: Script.getDTEInstances
val mutable rot : IRunningObjectTable
module Platform

from Script
val mutable enumMoniker : IEnumMoniker ref
type IEnumMoniker =
  member Clone : ppenum:IEnumMoniker -> unit
  member Next : celt:int * rgelt:IMoniker[] * pceltFetched:nativeint -> int
  member Reset : unit -> unit
  member Skip : celt:int -> int

Full name: System.Runtime.InteropServices.ComTypes.IEnumMoniker
Multiple items
val ref : value:'T -> 'T ref

Full name: Microsoft.FSharp.Core.Operators.ref

--------------------
type 'T ref = Ref<'T>

Full name: Microsoft.FSharp.Core.ref<_>
IRunningObjectTable.EnumRunning(ppenumMoniker: byref<IEnumMoniker>) : unit
val mutable moniker : IMoniker array
type IMoniker =
  member BindToObject : pbc:IBindCtx * pmkToLeft:IMoniker * riidResult:Guid * ppvResult:obj -> unit
  member BindToStorage : pbc:IBindCtx * pmkToLeft:IMoniker * riid:Guid * ppvObj:obj -> unit
  member CommonPrefixWith : pmkOther:IMoniker * ppmkPrefix:IMoniker -> unit
  member ComposeWith : pmkRight:IMoniker * fOnlyIfNotGeneric:bool * ppmkComposite:IMoniker -> unit
  member Enum : fForward:bool * ppenumMoniker:IEnumMoniker -> unit
  member GetClassID : pClassID:Guid -> unit
  member GetDisplayName : pbc:IBindCtx * pmkToLeft:IMoniker * ppszDisplayName:string -> unit
  member GetSizeMax : pcbSize:int64 -> unit
  member GetTimeOfLastChange : pbc:IBindCtx * pmkToLeft:IMoniker * pFileTime:FILETIME -> unit
  member Hash : pdwHash:int -> unit
  ...

Full name: System.Runtime.InteropServices.ComTypes.IMoniker
type 'T array = 'T []

Full name: Microsoft.FSharp.Core.array<_>
type Array =
  member Clone : unit -> obj
  member CopyTo : array:Array * index:int -> unit + 1 overload
  member GetEnumerator : unit -> IEnumerator
  member GetLength : dimension:int -> int
  member GetLongLength : dimension:int -> int64
  member GetLowerBound : dimension:int -> int
  member GetUpperBound : dimension:int -> int
  member GetValue : [<ParamArray>] indices:int[] -> obj + 7 overloads
  member Initialize : unit -> unit
  member IsFixedSize : bool
  ...

Full name: System.Array
val zeroCreate : count:int -> 'T []

Full name: Microsoft.FSharp.Collections.Array.zeroCreate
val mutable fetched : nativeint
Multiple items
type IntPtr =
  struct
    new : value:int -> nativeint + 2 overloads
    member Equals : obj:obj -> bool
    member GetHashCode : unit -> int
    member ToInt32 : unit -> int
    member ToInt64 : unit -> int64
    member ToPointer : unit -> unit
    member ToString : unit -> string + 1 overload
    static val Zero : nativeint
    static member Add : pointer:nativeint * offset:int -> nativeint
    static member Size : int
    ...
  end

Full name: System.IntPtr

--------------------
IntPtr()
IntPtr(value: int) : unit
IntPtr(value: int64) : unit
IntPtr(value: nativeptr<unit>) : unit
field nativeint.Zero
property Ref.Value: IEnumMoniker
IEnumMoniker.Next(celt: int, rgelt: IMoniker [], pceltFetched: nativeint) : int
val mutable bindCtx : IBindCtx
val mutable displayName : string ref
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
property Ref.Value: string
String.StartsWith(value: string) : bool
String.StartsWith(value: string, comparisonType: StringComparison) : bool
String.StartsWith(value: string, ignoreCase: bool, culture: Globalization.CultureInfo) : bool
val o : obj ref
type obj = Object

Full name: Microsoft.FSharp.Core.obj
IRunningObjectTable.GetObject(pmkObjectName: IMoniker, ppunkObject: byref<obj>) : int
val ignore : value:'T -> unit

Full name: Microsoft.FSharp.Core.Operators.ignore
property Ref.Value: obj
Raw view Test code New version

More information

Link:http://fssnip.net/7Um
Posted:6 years ago
Author:Gauthier Segay
Tags: com , native , visual studio , dte