title: Return string from c++ dll export function called from c#
body: <p>I am trying to return a string from a c++ dll export function. I am calling this function from c#. I have seen a lot of examples on the internet and I am really confused what to do.</p>
  
  <p>My c++ code to export function:</p>
  
  <pre><code>extern "C" __declspec(dllexport)  char*  __cdecl getDataFromTable(char* tableName)
  {
      std::string st = getDataTableWise(statementObject, columnIndex);
      printf(st.c_str()); 
  
      char *cstr = new char[st.length() + 1];
      strcpy(cstr, st.c_str());
      return cstr;
  } 
  </code></pre>
  
  <p>When I try to call this function from c#:</p>
  
  <pre><code>[DllImport("\\SD Card\\ISAPI1.dll")]
  private static extern string getDataFromTable(byte[] tablename);
  static void Main(string[] args)
  {
      string str = getDataFromTable(byteArray);
      Console.writeLine(str);
  }
  </code></pre>
  
  <p>I got an error while calling it. I am creating this for WinCE 6.0 </p>
  
  <p>EDITED------------------------</p>
  
  <p>is there something like, i can pass a empty buffer to c++ from c# and c++ function will fill the data and i can reuse it in C#</p>