CALLING C FUNCTION IN .NET.

James Smith

Total Post:48

Points:336
Posted by  James Smith
C# 
C#
 1587  View(s)
Ratings:
Rate this:

Hello everyone,

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

  1. Awadhendra Tiwari

    Post:126

    Points:882
    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));
                }
          }
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!