다음을 통해 공유


Implementing VSPackages By Using the Visual Studio Library

The IVsPackageImpl class in the Visual Studio Library provides a minimal implementation of the IVsPackage interface. IVsPackageImpl takes care of most of the maintenance methods of IVsPackage. Other methods you might need to override to provide a meaningful implementation include:

Packages that are implemented by using the Visual Studio Library typically inherit a VSPackage class from ATL's CComObjectRootEx Class and CComCoClass Class and Visual Studio Library's IVsPackageImpl. For example, following is the VSPackage class declaration from the Reference.Package sample:

class ATL_NO_VTABLE BasicPackage : 
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<BasicPackage, &CLSID_BasicPackage>,
    public IVsPackageImpl<BasicPackage, &CLSID_BasicPackage>,
    ...

The IVsPackageImpl template parameters shown are the VSPackage class itself and a pointer to the GUID identifying the VSPackage.

Supporting QueryInterface with COM maps

To get ATL's support for QueryInterface, its COM map must list the interfaces that the class implements. For example, following is the COM map for the VSPackage class in the Reference.Package sample:

BEGIN_COM_MAP(BasicPackage)
    COM_INTERFACE_ENTRY(IVsPackage)
    ...
END_COM_MAP()

For more information about COM maps, see Implementing CComObjectRootEx and COM_INTERFACE_ENTRY Macros.

Supporting Registration with Registry Maps

Visual Studio Library uses ATL-style .RGS files to support registration of COM objects. To support token replacement in the .RGS file, Visual Studio Library uses registry maps. Registry maps list symbols to be replaced and support the use of IDs for string table resources.

For example, following is the registry map for the VSPackage class in the Reference.Package sample:

VSL_BEGIN_REGISTRY_MAP(IDR_BASICPACKAGE_RGS)
    VSL_REGISTRY_MAP_GUID_ENTRY(CLSID_BasicPackage)
    VSL_REGISTRY_RESOURCE_STRING_ENTRY(IDS_BASICPACKAGE_REGISTRY_NAME)
    ...
VSL_END_REGISTRY_MAP()

See Also

Concepts

Visual Studio Extensibility Samples