Two Applications Share a HostID Sample


posted by Melody
11-18-2008

Downloads: 643
File size: 921.2kB
Views: 3,291
Two Applications Share a HostID Sample
Filed under: ,

This sample demonstrates how two applications can share one host ID. 

There are two applications which share a common base type library:  Applicatoin_A and Application_B share the SharedLib library.  Application_B is based on Application_A with additional methods. 

Each application has its own entry point type, Applicatoin_A .ApplicationA and Applicatoin_B.ApplicationB, and the shared base type library has an entry point type SharedLib.SharedApplication.  Both applications have a HostItemProvider which can return the entry point for its application or the SharedLib.SharedApplication.   

There are three proxies- one for only the shared library, then one for each application including the shared library.

Each proxy exposes one entry point and is exposed to VSTA add-ins through its own template.

Template

Proxy

EntryPoint

SharedApplication_Template

ApplicationSharedProxy

SharedApplication

ApplicationA_Template

ApplicationAProxy

ApplicationA

ApplicatoinB_Template

ApplicationBProxy

ApplicationB

 

To use the sample,

1.  Extract the sample to C:\VSTA (if using a different location the registry file will need to be updated for the ProjectTemplatesLocation and add-ins will not run).
2.  Run the included registration file Application_AB HostConfig Hive.reg.
3.  Run vsta setup for Application_AB.  This will register the included templates.
4.  Open and build the Application_A.sln, Application_B.sln, and SharedLib.sln solutions.
5.  Run the Application_A and Application_B samples, both will launch macro projects.
6.  For both macro projects, add the code below to the startup method, set a breakpoint and start debugging.  Both macros will hit the break point and can continue execution.
this.AddMessage(this.MakeSharedType(100, "message from macro X"));

Application_A can load and run add-ins written for the entry points ApplicationA and SharedApplication, but not ApplicationB add-ins.
Application_B can load and run add-ins written for the entry points ApplicationB and SharedApplication, but not Application_A add-ins.

Application_A  and Application_B can both debug at the same time (using different macro projects) using the same HostID.  Application_A uses a macro project based on the ApplicationA_Template.  Application_B uses a macro project based on the ApplicationB_Template. 

 

Results:

Ø  It is possible to use the same hostID for different applications and debug them concurrently

Ø  It is possible for an application to load and run add-ins, so long as the add-in is compatible with the host (the HostItemProvider must return the entry point type of the add-in).


Modified Sample:  One Application use two HostIDs

Using the above sample where two applications share one hostID, modifications can easily be made so that each application may use its own hostID or one application can use two hostIDs.  These modifications are intended to demonstrate the flexibility of using multiple hostId’s with one or more applications. 

To use two different hostID’s for one application
1.  Complete the steps above to setup the sample.
2.  Add the hostID for Application_B- run the included registration file “Application_B HostConfig Hive.reg”.
3.  Run vsta setup for Applicatoin_B.  This will register the included templates.
4.  Change which macro project Appliation_B uses to the Application_B_HostID_B_Template project by:
                                 i.            Uncomment the below line in Application_B.Program.Main “Two applications using one hostID's section” region:
          //app.VstaDTE_HostIdB.ShowIde(true);  //HostID Application_B

                                ii.            Comment the below line in Application_B.Program.Main “One application using two hostID's section” region:
          app.VstaDTE.ShowIde(true);  //HostID Application_AB

5.  Build the Application_B_AddIn_HostID_B_1 project under SampleAddIns
6.  Build and run the Application_A and Application_B samples.


Application_B can still load and run add-ins based on the old template ApplicationB_Template and the shared template SharedApplication_Template (hostID’s do not come into play here, only entry points). 

Application_A and Application_B can both debug at the same time using different HostID’s 

Application_B can debug using macro projects for either hostID so long as the project loaded is based on a template for the HostID used in RegisterAsDebugHost and EnsureIDE.

Application_B can only debug under one hostID at a time- it cannot RegisterAsDebugHost for two HostID’s concurrently

 

Results:

Ø  It is possible to use two hostIDs for one application but only one can be registered for debugging at a time

Ø  It is not possible to open a project based on a template registered under one hostID in the IDE of another hostID, the IDE is hostID specific.

Ø  It is possible for an application to load and run add-ins for different HostIDs, so long as the add-in is compatible with the host regardless of the HostID (the HostItemProvider must return the entry point type of the add-in).

 

Copyright Summit Software Company, 2008. All rights reserved.