Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual Studio SDK
Architecture
Services
 How to: Get a Service from the DTE ...

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2005/.Net Framework 2.0

Other versions are also available for the following:
Visual Studio SDK
How to: Get a Service from the DTE object (C#)
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

A service can be obtained from within any program that has access to the Visual Studio Automation DTEClass object. For example, you can access the SVsActivityLog service from within a wizard through the DTE object. You can use this service to write to the activity log. For more information, see How to: Write to the Activity Log (C#).

The DTE object implements IServiceProvider, which you can use to query for a service from managed code using GetService.

Example

The following code creates a ServiceProvider from the DTE object and calls GetService with the type of the SVsActivityLog service. The service is cast to the interface IVsActivityLog, which is used to write an entry in the activity log. For more information on writing to the activity log, see How to: Write to the Activity Log (C#).

// Start with the DTE object, for example:
// DTE dte = (DTE)GetService(typeof(DTE));
ServiceProvider sp = new ServiceProvider(dte);
IVsActivityLog log =
   GetService(typeof(SVsActivityLog)) as IVsActivityLog;
if (log == null) return;

int hr = log.LogEntry(
   (UInt32)__ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION,
   this.ToString(),
   string.Format(CultureInfo.CurrentCulture,
   "Consuming SVsActivityLog service in {0}", this.ToString())
);

See Also

Concepts

Service Essentials

Other Resources

Services

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker