Home > DeveloperSection > Forums > Calling C function in .net.
James Smith

Total Post:48

Posted on    April-16-2011 2:32 AM

 C# C# 

 1 Reply(s)
 1549  View(s)
Rate this:

Hello everyone,

Can anyone tell me that hot to call c++ function in .net.

Awadhendra Tiwari

Total Post:126

Posted on    April-16-2011 2:57 AM

Well I think that should not be to dificult. You can use DllImport statement to call any c++ dll library or function.

For example you have following c++ function in a dll.

int Sum(int x, int y)
       return x+y;

And you want to use this function in c# application.
So you can useit like this.

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices; //For "DllImport"

namespace MyCSharp
      class Program
      [DllImport("MathFuncsDll.dll", CharSet = CharSet.Auto)]
      public static extern Int32 Sum(Int32 a, Int32 b);

            static void Main()
                  Console.WriteLine(Sum(3, 4));

Don't want to miss updates? Please click the below button!

Follow MindStick