Crossing the VSIP Bridge - Part 2

I have been putting together a presentation on how to use VSIP from automation (and
vice-versa), and one bit of code that I have is how to call a VSIP interface from
a macro. To make the VSIP calls, you need to first install the VSIP Extras SDK available
from the vsipdev.com web site. Next, within
the directory you installed into, copy the interop assemblies (IAs) into the {VS Install
Directory}\Common7\IDE\PublicAssemblies folder. This is necessary to make the assemblies
available. To your macro projects. Next, open the macros IDE, choose a project, right
click the References node, and add a reference to the Microsoft.VisualStudio.* assemblies.
After doing this, you are ready to call VSIP interfaces. The following code demonstrates
this by retrieving the application name and showing it in a message box:

"urn:schemas-microsoft-com:office:office" />

 

Sub ShowAppName()

    Dim sp As Microsoft.VisualStudio.OLE.Interop.IServiceProvider

    Dim vsuishell As Microsoft.VisualStudio.Shell.Interop.IVsUIShell

    Dim guid1 As System.Guid

    Dim guid2 As System.Guid

    Dim ip As System.IntPtr

    Dim appName As String

    sp
= DTE

    guid1
= GetType(Microsoft.VisualStudio.Shell.Interop.SVsUIShell).GUID

    guid2
= GetType(Microsoft.VisualStudio.Shell.Interop.IVsUIShell).GUID

    sp.QueryService(guid1,
guid2, ip)

    vsuishell
= System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(ip)

    vsuishell.GetAppName(appName)

    MsgBox(appName)

End Sub

 

This could be more readable with a function to retrieve a service in a more generic
way, but I will leave that up to you to exercise your programming skills.

 

One word of caution: some methods and interfaces are marked local in the idl from
which the IAs were generated. While this bit of information does not transfer to the
IAs, when you try to call those methods or interfaces, they will fail. This is because
the Macros IDE runs in a separate process from VS, and making these cross-process
calls will fail because you cannot remote GDI objects (HICONs, HBITMAPs, etc.).