title: C#: calling C++ DLL with char** argument
body: <p>I would like to call this C++ function from my C# code:</p>
  
  <pre><code>void GetArrayOfNames(char** names, int nbOfNames);
  </code></pre>
  
  <p>To call it in C++, I just define an array of char*:<br></p>
  
  <pre><code>char* aNames[20];
  </code></pre>
  
  <p>And allocate each name in a loop:<br></p>
  
  <pre><code>for(int i-0; i&lt;20; i++)
  {
      aNames[i] = new char[50];
  }
  </code></pre>
  
  <p>Then call: <br></p>
  
  <pre><code>GetArrayOfNames(aNames, 20);
  </code></pre>
  
  <p>In my C# code, I have:<br></p>
  
  <pre><code>[DllImport("MyDLL.dll")]
  unsafe static extern void GetArrayOfNames(char** ppNames, int nbOfNames);
  </code></pre>
  
  <p>Now, how do I do the memory allocation and call GetArrayOfNames?  Also, any way of not having to declare my function as "unsafe"?</p>