I have a C++ (MSVS 2010) DLL from the samples MS give as:
namespace MathLibrary
{
double Functions::Add(double a, double b)
{
return a + b;
}
double Functions::Multiply(double a, double b)
{
return a * b;
}
double Functions::AddMultiply(double a, double b)
{
return a + (a * b);
}
}
dumpbin
for the compiled DLL exports the following info:
1 0 00011078 ?Add@Functions@MathLibrary@@SANNN@Z = @ILT+115(?Add@Functions@MathLibrary@@SANNN@Z)
2 1 000110B9 ?AddMultiply@Functions@MathLibrary@@SANNN@Z = @ILT+180(?AddMultiply@Functions@MathLibrary@@SANNN@Z)
3 2 00011005 ?Multiply@Functions@MathLibrary@@SANNN@Z = @ILT+0(?Multiply@Functions@MathLibrary@@SANNN@Z)
So I've written C# code (.NET framework 4.5.2) to call the Add
function as:
namespace ConsoleApplication5
{
class Program
{
[DllImport(@"MathLib.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl, EntryPoint = "#1")]
public static extern int Add(Int32 a, Int32 b);
public unsafe static void Main()
{
int i = Add( 1,3 );
Console.WriteLine(i);
Console.ReadLine();
}
}
}
When I run this console application, it always outputs
-858993460
regardless of the arguments passed to the Add function. Can anyone suggest what this output represents, and how to fix my calling code?