Partilhar via


IVsProject3.GetItemContext(UInt32, IServiceProvider) Method

Definition

Returns the context of an item.

public:
 int GetItemContext(System::UInt32 itemid, [Runtime::InteropServices::Out] Microsoft::VisualStudio::OLE::Interop::IServiceProvider ^ % ppSP);
public:
 int GetItemContext(unsigned int itemid, [Runtime::InteropServices::Out] Microsoft::VisualStudio::OLE::Interop::IServiceProvider ^ &  ppSP);
int GetItemContext(unsigned int itemid, [Runtime::InteropServices::Out] Microsoft::VisualStudio::OLE::Interop::IServiceProvider const & & ppSP);
public int GetItemContext (uint itemid, out Microsoft.VisualStudio.OLE.Interop.IServiceProvider ppSP);
abstract member GetItemContext : uint32 * IServiceProvider -> int
Public Function GetItemContext (itemid As UInteger, ByRef ppSP As IServiceProvider) As Integer

Parameters

itemid
UInt32

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

ppSP
IServiceProvider

[out] Pointer to the IServiceProvider interface.

Returns

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

Implements

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

Remarks

COM Signature

From vsshell.idl:

HRESULT IVsProject3::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.

Applies to