S
sovarschi_zsuzsa
Hello everybody!
I've written a simple C++ dll:
//Simple.dll
#include <stdio.h>
extern "C" {
__declspec(dllexport) long __cdecl Add(long a, long b) {
return (a+b);
}
__declspec(dllexport) long __cdecl Multiple(long a, long b) {
return (a*b);
}
}
This DLL file ready work if I call the functions from C++, but I've
tried to call these functions from a C# project:
using System;
using System.Runtime.InteropServices;
namespace Class1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
[DllImport("Simple.dll")]
//CallingConvention=CallingConvention.Cdecl)]
public static extern long Add(long a, long b);
[DllImport("Simple.dll")]
//CallingConvention=CallingConvention.Cdecl)]
public static extern long Multiple(long a, long b);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
long number1 = 30;
long number2 = 4;
//long number3 = Multiple(number1, number2);
Console.WriteLine ( "Add: " + Add(number1, number2) );
Console.ReadLine();
}
}
}
The result on the screen is: Add: 17179869214
Could somebody help what the problem is? 30 + 4 = 34 not
17179869214.....Is there some problems with parameters?
More thank, Zsuzsa.
I've written a simple C++ dll:
//Simple.dll
#include <stdio.h>
extern "C" {
__declspec(dllexport) long __cdecl Add(long a, long b) {
return (a+b);
}
__declspec(dllexport) long __cdecl Multiple(long a, long b) {
return (a*b);
}
}
This DLL file ready work if I call the functions from C++, but I've
tried to call these functions from a C# project:
using System;
using System.Runtime.InteropServices;
namespace Class1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
[DllImport("Simple.dll")]
//CallingConvention=CallingConvention.Cdecl)]
public static extern long Add(long a, long b);
[DllImport("Simple.dll")]
//CallingConvention=CallingConvention.Cdecl)]
public static extern long Multiple(long a, long b);
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
long number1 = 30;
long number2 = 4;
//long number3 = Multiple(number1, number2);
Console.WriteLine ( "Add: " + Add(number1, number2) );
Console.ReadLine();
}
}
}
The result on the screen is: Add: 17179869214
Could somebody help what the problem is? 30 + 4 = 34 not
17179869214.....Is there some problems with parameters?
More thank, Zsuzsa.