title: Passing Delphi PChar to C#
body: <p>I have some problems transferring data for delphi imported activeX control in c# environment.</p>
  
  <hr>
  
  <p>I have a function on delphi side, which takes and returns PChar. I can modify it or do whatever I want with it.</p>
  
  <pre><code>function TActiveFormX.DelphiFunction(S: PChar): PChar;
  begin
      ///do something with 'S'
      result:=S;
  end;
  </code></pre>
  
  <p>And on C# side of the program is a function, which calls delphi function, giving it a string parameter to chew on.</p>
  
  <pre><code>public void CSharpFunction()
  {
      string a = axActiveFormX1.DelphiFunction("sampleString");
  }
  </code></pre>
  
  <p>I've tested it and apparently everything goes well until C# receives returned PChar. Then whe whole application stops responding and exits. I tried to implement try-catch block to see the Exception message, but the app just crashes before displaying anything.</p>
  
  <p>I suppose it crashes because of variables not being of the same type. Or because of cruel software version mismatch: Delphi 5 + Visual Studio 2012. I googled this, but no luck thus far.</p>
  
  <p>Any help appreciated :)</p>