title: "Set" COM object properties in batch in c++
body: <p>I have to set the properties of a COM object.</p>
  
  <p>The COM object has a <code>Set</code> function that takes a key (string) and a value (variant) as parameters. For example I can do : <code>com_object-&gt;Set("name", "John")</code>.</p>
  
  <p>I have many properties to set, but I don't know how to do it in C++. In VB.Net it would look like that:
  <code>com_object.Set "name,age", Array("M2", 1)</code></p>
  
  <p>I would like to do the same in C++ but I don't know the syntax.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here is the code I have written to access properties in batch:</p>
  
  <pre><code>  template &lt; class ComObjectType &gt;
    void read(ComObjectType com_object, std::string const&amp; fields)
    {
      COleSafeArray data_array_;
      data_array_ = com_object-&gt;GetGet((LPCSTR)fields.c_str());
      long index = 0;
      VARIANT value_temp_;
      _variant_t value_reader_;
      data_array_.GetElement(&amp;index, &amp;value_temp_);
      value_reader_.Attach(value_temp_);
      std::string str1 = (LPCSTR)((_bstr_t) value_reader_)
      ++index
      data_array_.GetElement(&amp;index, &amp;value_temp_);
      value_reader_.Attach(value_temp_);
      long long1 = value_reader_.lVal;
  
    }
  </code></pre>
  
  <p>Then I call this function (which actually does not do much but is just there for the demonstration. The IAPIOrderObj* can be anything but it is defined in the .tlh file of the API I am being provided with, and it inherits from IDispatch interface.</p>
  
  <pre><code>MYAPI::IAPIOrderObj* my_obj;
  read&lt; IAPIOrderObj* &gt;(my_obj, "StatusString,StatusCode");
  </code></pre>