Reference.Services Sample

This sample shows how to be a Visual Studio service provider and how to consume Visual Studio services.

4,963 times
Add to favorites
E-mail Twitter Digg Facebook

Solution explorer

C#, C++
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet href="../../../../Common/Overview.xsl" type="text/xsl"?>
    <ShortName>C++ Reference.Services</ShortName>
    <LongName>C++ Services Reference Sample</LongName>
    <Phrase>Creating, exposing, and consuming services in Visual Studio using C++.</Phrase>
      This sample shows how to be a Visual Studio service provider and how to consume Visual Studio
    <Goal>Creating and Proffering services in Visual Studio</Goal>
    <Goal>Consuming services in Visual Studio</Goal>
    <Goal>Local versus Global services</Goal>
    <Image width="400" height="400">Services.jpg</Image>
    <Doc />
      <Keyword>Local service</Keyword>
      <Keyword>Global service</Keyword>
      The sample contains three main classes.  A service provider package called ServiceProviderPackage,
      a service consumer package called ServiceConsumerPackage, and a local service provider called
      LocalServiceProvider, which belongs to the service provider package.
      ServiceProviderPackage registers its service in the Visual Studio registry so that it will be
      loaded when any package queries for the service. In this sample ServiceConsumerPackage will
      do this.  Additionally, ServiceProviderPackage offers this service to Visual Studio when it is
      loaded. Simply registering the service in the Visual Studio registry is insufficient to allow a
      client to successfully query for it.
      ServiceConsumerPackage registers its menu and provides three menu items on the Visual Studio Tools
      menu entitled:
    <Paragraph>"VSSDK C++ Execute Global Service"</Paragraph>
    <Paragraph>"VSSDK C++ Execute Local Service"</Paragraph>
    <Paragraph>"VSSDK C++ Execute Local using Global Service"</Paragraph>
      The command handlers for these menu items are provided by ServiceConsumerPackage. Each handler
      attempts to query for either the globally offered service provided by ServiceProviderPackage
      or the local service provided by ServiceProviderPackage.  Querying for the local service is
      expected to fail.  Utilizing each menu item will cause a text string to be sent to the Output
      window. (NOTE - There is a bug in the Output window. If you don't see the text, then simply restart Visual Studio).
      Open the Package.sln solution.
	  Right-click the ServicesTest project and choose <bold>Set as Startup Project</bold>.
      Press F5 to build the sample, register it in the experimental instance, and launch Visual Studio from the experimental instance.
      <Title>Visual Studio SDK Website</Title>
      Call the three command handlers of ServiceConsumerPackage after creating and siting both
      ServiceConsumerPackage and ServiceProviderPackage.
      Sample builds without errors and warnings in both Debug and Release configurations.
      Registration is appropriately entered under the experimental instance.
      After registration in the experimental Visual Studio hive by
      calling 'Devenv /rootsuffix Exp /setup', execute all 3 of the commands on the Tools menu and validate the outputs in the Output window.
      Registration is appropriately entered under the standard Visual Studio registry hive when 
      regsrv32.exe is used to register the DLL.
        Implementation for LocalServiceProvider.
        Implementation for ServiceConsumerPackage.
        Implementation for ServiceProviderPackage.
        Unit tests for this sample.
      <Description>Created this sample for the Visual Studio 2010 SDK.</Description>