This documentation is archived and is not being maintained.

SContainerDispatch Interface

Passed to the QueryService method to return a reference to the IDispatch Interface.

Namespace: Microsoft.VisualStudio.OLE.Interop
Assembly: Microsoft.VisualStudio.Shell.Interop.8.0 (in microsoft.visualstudio.shell.interop.8.0.dll)

[GuidAttribute("B722BE00-4E68-101B-A2BC-00AA00404770")] 
public interface SContainerDispatch
/** @attribute GuidAttribute("B722BE00-4E68-101B-A2BC-00AA00404770") */ 
public interface SContainerDispatch
GuidAttribute("B722BE00-4E68-101B-A2BC-00AA00404770") 
public interface SContainerDispatch

The IDispatch Interface is implemented on any control or VSPackage that supports automation. However, to obtain the IDispatch interface, it is necessary to query the control or VSPackage for a service provider and ask that service provider to obtain the IDispatch interface from the SContainerDispatch service. See the example for how this can be accomplished.

This example shows how to obtain the IDispatch Interface from the SContainerDispatch service.

IDispatch GetDispatchInterface(object pUnknown)
{
    IDispatch pDispatchInterface = null;
    if (null != pUnknown)
    {
        Microsoft.VisualStudio.OLE.Interop.IServiceProvider pServiceProvider;
        pServiceProvider = pUnknown as Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
        if (null != pServiceProvider)
        {
            Guid   serviceGuid   = typeof(SContainerDispatch).GUID;
            Guid   interfaceGuid = typeof(IDispatch).GUID;
            IntPtr pInterface    = IntPtr.Zero;
            int hr = pServiceProvider.QueryService(ref serviceGuid,
                                                   ref interfaceGuid,
                                                   out pInterface);
            if (Microsoft.VisualStudio.ErrorHandler.Succeeded(hr))
            {
                 pDispatchInterface = Marshal.GetObjectForIUnknown(pInterface)
                                      as IDispatch;
            }
        }
    }
    return pDispatchInterface;
}
Show: