0

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!

c00000fd
  • 20,994
  • 29
  • 177
  • 400

1 Answers1

1

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

xMRi
  • 14,982
  • 3
  • 26
  • 59
  • Idk. I was in the MFC "world" so I went with CMap. Can I ask a follow-up question? Say, if I declare the map as such: `CMap` it still compiles, but what is the difference? – c00000fd May 07 '14 at 08:50
  • There is in fact no difference. But I feel more comfortable with the std::map classes and features. Even when in the MFC-world there is never a problem to use the STL-world. Never! – xMRi May 07 '14 at 09:00
  • STL does look out of place in an MFC application, so using the MFC collections is probably the best way to go. – Matthew May 08 '14 at 13:15