title: How to pass a SAFEARRAY from C# to COM?
body: <p>I have an ATL COM Server, where the method for the interface is </p>
  
  <pre><code>CVivsBasic::UpdateSwitchPlan(BSTR plan_name, SAFEARRAY* plan)
  </code></pre>
  
  <p>And the IDL for this function looks like</p>
  
  <pre><code>typedef struct  
  {   
      LONG time_to_play;
      BSTR ecportid;
  } SwitchPlanItem;
  HRESULT UpdateSwitchPlan([in] BSTR plan_name, [in] SAFEARRAY(SwitchPlanItem) plan) ;    
  </code></pre>
  
  <p>I tried to call it from C# like this:</p>
  
  <pre><code>        internal void UpdateSwitch(string plan_name, string ecportid)
      {
          SwitchPlanItem sp1;
          sp1.time_to_play = 33;
          sp1.ecportid = ecportid;
  
          SwitchPlanItem sp2;
          sp2.time_to_play = 33;
          sp2.ecportid = ecportid;
  
          SwitchPlanItem[] sps = { sp1, sp2 };
  
          sdk.UpdateSwitchPlan(plan_name, sps);
      }
  </code></pre>
  
  <p>But it crash.  What is the correct way to pass a SAFEARRAY from C# to COM?</p>