 <p>If the Delphi function is declared as being <code>stdcall</code>, why would you declare it in C# as <code>cdecl</code>? </p> <p>This is the cause of the stack imbalance. Change your C# declaration to use the <code>stdcall</code> convention to match the Delphi declaration.</p> <pre><code>[UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate double WriteRate(object data); </code></pre>