This will work and is correct.
Important is the use of a CComVariant or _variant_t type that supports correct copying and destruction of Variants.
But why don't you use std::map
Question
I need to create a dictionary collection of VARIANTs using CMap class. My dictionary is defined as such:
CMap<CString, LPCTSTR, CComVariant, CComVariant> map;
I then add elements as such:
void setKeyValue(CMap<CString, LPCTSTR, CComVariant, CComVariant>& map, CString& strKey, VARIANT& varValue)
{
map.SetAt(strKey, varValue);
}
Can someone check if this is the proper way of populating CMap with VARIANTs? I haven't done COM for a while so I want to make sure that I'm not causing any memory leaks. Thanks!
Solution
This will work and is correct.
Important is the use of a CComVariant or _variant_t type that supports correct copying and destruction of Variants.
But why don't you use std::map