I've started recently to work on the project that involves communication between C# and native code and thus I'm trying to understand how it works. I've loaded one of the samples from msdn, tried to launch it and I see that it works in Release mode and crashes in debug mode. Does somebody know why?
// PInvokeTest.cs
using System;
using System.Runtime.InteropServices;
class PlatformInvokeTest
{
[DllImport("msvcrt.dll")]
public static extern int puts(string c);
[DllImport("msvcrt.dll")]
internal static extern int _flushall();
public static void Main()
{
puts("Test");
_flushall();
}
}
Error:
Additional information: A call to PInvoke function 'ConsoleApplication6!PlatformInvokeTest::puts' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.
This code is from following site: https://msdn.microsoft.com/en-us/library/aa288468(v=vs.71).aspx