Export (0) Print
Expand All

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)

int GetItemContext(
	uint itemid,
	out IServiceProvider ppSP
)

Parameters

itemid
Type: System.UInt32
[in] Identifier of the context item whose value is taken from the VSITEMID DWORD.
ppSP
Type: Microsoft.VisualStudio.OLE.Interop.IServiceProvider
[out] Pointer to the IServiceProvider interface.

Return Value

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

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 null. 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.

//---------------------------------------------------------------------
// 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;
}

Community Additions

ADD
Show:
© 2014 Microsoft