Advertise with us

Calling C function in .net.

Posted by  James Smith
 2109  View(s)
Rate this:

Hello everyone,

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

  1. Re: Calling C function in .net.

    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));

      Modified On Mar-29-2018 04:04:07 AM