title: Using a C# DLL in Delphi only uses the first function parameter
body: <p>I use C# DLL Export (UnmanagedExports - <a href="https://www.nuget.org/packages/UnmanagedExports" rel="nofollow">https://www.nuget.org/packages/UnmanagedExports</a>)  to make my managed C# DLL Accessible to unmanged Code like Delphi. My problem is that only first function parameter is transfered from delphi to the C# dll: </p>
  
  <p>The C# DLL Part </p>
  
  <pre><code>   [DllExport("SomeCall", CallingConvention.StdCall)]
     public static String SomeCall([MarshalAs(UnmanagedType.LPWStr)] String data1, [MarshalAs(UnmanagedType.LPWStr)] String data2)
      { 
               //Data1 is never filled with some string data. 
               String result = WorkWithData(data1);                   
               //Data2 is filled with some string data.
               result += WorkWithData(data2) 
               return result;
      }
  </code></pre>
  
  <p>The Delphi Part (Calling part):</p>
  
  <pre><code>SomeCall: function(data1: PWideChar; data2: PWideChar;): String StdCall;
  
  procedure DoSomeDLLWork(data1: PWideChar; data2: PWideChar);
  var 
   dllCallResult: String;
  begin
    dllCallResult := SomeCall(data1,data2);
  end
  </code></pre>
  
  <p>The problem in this case is that only data2 is filled. data1 is never filled. I already tried StdCall and Cdecl. </p>
  
  <p><strong>Edit:</strong></p>
  
  <p>The following thing works (data1 and data2 ist transfered correctly) - return value changed from string to boolean:</p>
  
  <p>C# (DLL Part):</p>
  
  <pre><code>   [DllExport("SomeCall", CallingConvention.StdCall)]
     public static bool SomeCall([MarshalAs(UnmanagedType.LPWStr)] String data1, [MarshalAs(UnmanagedType.LPWStr)] String data2)
  </code></pre>
  
  <p>Delphi (Caller):</p>
  
  <pre><code> SomeCall: function(data1: PWideChar; data2: PWideChar;): boolean StdCall;
  </code></pre>
  
  <p>Now I have to think about a return value or a a buffer to return the result string back to delphi. </p>
  
  <p><strong>Edit2:</strong></p>
  
  <p>I went with David Heffernan's suggestion of using an out parameter:</p>
  
  <p>Delphi:</p>
  
  <pre><code>SomeCall: procedure(data1: PWideChar; data2: PWideChar; var result: PWideChar)StdCall;
  </code></pre>
  
  <p>C#</p>
  
  <pre><code>   [DllExport("SomeCall", CallingConvention.StdCall)]
     public static bool SomeCall([MarshalAs(UnmanagedType.LPWStr)] String data1, [MarshalAs(UnmanagedType.LPWStr)] String data2, [MarshalAs(UnmanagedType.LPWStr)] out String result)
  </code></pre>