I try to implement a C++ DLL into my C# project. I've given the following header file:
#ifdef EBEXPORT
const long EBDECL
#else
const long EBDECL __declspec(dllimport)
#endif
const long EBCALL __stdcall
#if defined (__cplusplus)
extern "C"
{
#endif
EBDECL long EBCALL EbInitTcp(long nUnit, const char* pIP, long nIPSize);
#if defined (__cplusplus)
}
#endif
This is my code which I use to implement the DLL in C#:
using System.Runtime.InteropServices;
namespace NoName
{
class DLLImport
{
[DllImport("C:/lib/host.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern long EbInitTcp(long nUnit, string pIP, long nIPSize);
public void Init()
{
string ip = "192.168.0.1";
EbInitTcp(1, ip, ip.Length));
}
}
}
If I execute the code I get a PInvokeStackImbalance exception. Could you please help me?