Freigeben über


IVsProject.GetItemContext Method

Returns the context of an item.

Namespace:  Microsoft.VisualStudio.Shell.Interop
Assembly:  Microsoft.VisualStudio.Shell.Interop (in Microsoft.VisualStudio.Shell.Interop.dll)

Syntax

'Declaration
Function GetItemContext ( _
    itemid As UInteger, _
    <OutAttribute> ByRef ppSP As IServiceProvider _
) As Integer
int GetItemContext(
    uint itemid,
    out IServiceProvider ppSP
)
int GetItemContext(
    [InAttribute] unsigned int itemid, 
    [OutAttribute] IServiceProvider^% ppSP
)
abstract GetItemContext : 
        itemid:uint32 * 
        ppSP:IServiceProvider byref -> int
function GetItemContext(
    itemid : uint, 
    ppSP : IServiceProvider
) : int

Parameters

  • itemid
    Type: UInt32

    [in] Identifier of the context item whose value is taken from the VSITEMIDDWORD.

Return Value

Type: Int32
If the method succeeds, it returns S_OK. If it fails, it returns an error code.

Remarks

COM Signature

From vsshell.idl:

HRESULT IVsProject::GetItemContext(
   [in] VSITEMID itemid,
   [out] IServiceProvider **ppSP
);

This method allows a project to provide project context services to a document editor. If the project does not need to provide special services to its items, then it should return nulla null reference (Nothing in Visual Basic). Under no circumstances should you return the IServiceProvider pointer that was passed to the package from the environment through SetSite. The global services will automatically be made available to editors.

The following example gives more detail on the project context services provided by GetItemContext method.

Examples

//---------------------------------------------------------------------
// interface: IServiceProvider
//---------------------------------------------------------------------
STDMETHODIMP CLangFileNode::QueryService(REFIID guidService, REFIID riid, void** ppv)
{
   if (ppv == NULL)
      return E_INVALIDARG;

   *ppv = NULL;

   HRESULT hr = E_NOINTERFACE;
   if (IsEqualIID(guidService, SID_SVSMDCodeDomProvider))
   {
      CComPtr<IVSMDCodeDomCreator> srpCodeDomCreator;
      hr = _VxModule.QueryService(SID_SVSMDDesignerService,            IID_IVSMDCodeDomCreator, (LPVOID*) &srpCodeDomCreator);
      if (SUCCEEDED(hr))
      {
         CComPtr<IVSMDCodeDomProvider> srpCodeDomProvider;
         hr = srpCodeDomCreator->CreateCodeDomProvider(GetCVsHierarchy()->GetIVsHierarchy(),GetVsItemID(),&srpCodeDomProvider);
         if (SUCCEEDED(hr))
            hr = srpCodeDomProvider->QueryInterface(riid, ppv);
      }
   }
   else if (IsEqualIID(guidService, VxDTE::SID_SVSProjectItem))
   {
      CComPtr<VxDTE::ProjectItem> srpProjectItem;
      hr = GetDTEItem(&srpProjectItem);
      if (SUCCEEDED(hr))
         hr = srpProjectItem->QueryInterface(riid, ppv);
   }
   else if (IsEqualIID(guidService,             SID_SVSWebReferenceDynamicProperties))
   {
   // We only support this service if our parent folder is a web reference folder
      CLangFolderNode* pFolder = GetFolderParent();
      if(pFolder && pFolder->IsWebReferenceFolder())
      {
         CComPtr<IVSWebReferenceDynamicProperties> srpWebRef;
         hr = pFolder->GetIVsWebRefDynamicProperties(&srpWebRef);
         if(SUCCEEDED(hr))
            hr = srpWebRef->QueryInterface(riid, ppv);
      }
   }
   else if (IsEqualIID(guidService, IID_IVsHierarchy))
   {
   // Access to our hierarchy.
      hr = GetProject()->GetHierarchy()->QueryInterface(riid, ppv);
   }
   return hr;
}

.NET Framework Security

See Also

Reference

IVsProject Interface

Microsoft.VisualStudio.Shell.Interop Namespace