// Store the data in a vector of std::strings
typedef std::vector< std::string > ContainerType;
// The collection interface exposes the data as BSTRs
typedef BSTR CollectionExposedType;
typedef IWords CollectionInterface;
// Use IEnumVARIANT as the enumerator for VB compatibility
typedef VARIANT EnumeratorExposedType;
typedef IEnumVARIANT EnumeratorInterface;
这里,您将把数据存储为 std::string 的 std::vector。std::vector 是 STL 容器类,它的行为类似托管数组。std::string 是标准 C++ 库的字符串类。这些类使字符串集合的使用很容易。
class ATL_NO_VTABLE CWords :
public CComObjectRootEx<CComSingleThreadModel>,
public CComCoClass<CWords, &CLSID_Words>,
public IDispatchImpl<CollectionType, &IID_IWords, &LIBID_ATLCOLLECTIONSLib>
{
public:
DECLARE_REGISTRY_RESOURCEID(IDR_STRINGCOLLECTION)
DECLARE_PROTECT_FINAL_CONSTRUCT()