创建变体CMap的正确方法

Correct way to create CMap of VARIANTs

本文关键字:方法 CMap 创建      更新时间:2023-10-16

我需要使用CMap类创建一个变体的字典集合。我的字典是这样定义的:

CMap<CString, LPCTSTR, CComVariant, CComVariant> map;

然后添加如下元素:

void setKeyValue(CMap<CString, LPCTSTR, CComVariant, CComVariant>& map, CString& strKey, VARIANT& varValue)
{
    map.SetAt(strKey, varValue);
}

有人可以检查如果这是用变量填充CMap的正确方式吗?我有一段时间没有使用COM了,所以我想确保我没有造成任何内存泄漏。谢谢!

这将工作并且是正确的。

重要的是使用支持正确复制和销毁变量的CComVariant或_variant_t类型。

为什么不使用std::map

呢?