title: Managed byte[] to unmanaged byte array using ATL/COM
body: <p>I want to pass some image data from C# code to unmanaged C++ using ATL/COM</p>
  
  <p>From C# code side i do something like this:</p>
  
  <pre><code>void SendFrame([In, MarshalAs(UnmanagedType.SafeArray, SafeArraySubType=VarEnum.VT_UI1)] ref byte[] frameData);
  </code></pre>
  
  <p>But I'm not sure how should I handle this function in my C++ code.</p>
  
  <p>For now I have something like this:</p>
  
  <pre><code>_ATL_FUNC_INFO OnSendFrameDef = { CC_STDCALL, VT_EMPTY, 1, { VT_SAFEARRAY | VT_UI1 } };
  
  void __stdcall OnSendFrame(SAFEARRAY* ppData)
  {
     BYTE* pData;
     SafeArrayAccessData(ppData, (void **) &amp;pData);
  
     // Doing some stuff with my pData
  
     SafeArrayUnaccessData(ppData);
  }
  </code></pre>
  
  <p>Can anyone give me some suggestions how I can make this thing work?</p>
  
  <p>Thanks.</p>