title: Marshal wchar_t** from C++ to C# as an out parameter?
body: <p>I have this function in a dll in C and I cannot change it:</p>
  
  <pre><code>extern "C" SIBIO_MULTILANGUAGE_API_C DWORD getLabel(const char* const i_formName, 
                                                      const char* const i_fieldName, 
                                                      wchar_t** i_output);
  </code></pre>
  
  <p>I know that this call inside allocates the memory for the <code>wchar_t*</code> using the function <code>CoTaskMemAlloc</code>.</p>
  
  <p>In C# I wrapped this function in this way:</p>
  
  <pre><code>[DllImport("sibio_multilanguage_c.dll", EntryPoint = "getLabel", CallingConvention = CallingConvention.Cdecl)]
  private static extern UInt32 _getLabel([In] string i_formName, [In] string i_fieldName, 
                                         [MarshalAs(UnmanagedType.LPWStr)] out string i_output);
  
  static public string getLabel(string i_formName, string i_fieldName)
  {
      string str = null;
      UInt32 err = _getLabel(i_formName, i_fieldName, out str);
      if (0 != err)
      {
          throw  new System.IO.FileNotFoundException();
      }
      return str;
  }
  </code></pre>
  
  <p>I'm able to read correctly the content of the <code>wchar_t*</code> but reading in this way I don't free the memory allocated in the C function.</p>
  
  <p>How can I read the <code>wchar_t*</code> and also be able to free it? Any help is greatly appreciated!</p>