Is there a way to call a C function in C #?

2

Let's say I have a library with a C function, which was compiled using gcc, is there any way to call this function in C #, if so what would its performance compare to the same function created in C #?

    
asked by anonymous 25.09.2016 / 18:22

1 answer

4

First you have to export the function in your C.

For example

//Exemplo.dll
extern "C" __declspec(dllexport) double funcaoExemplo (int valor)
{
   //código
}

and in your C # you should use DllImport

   [DllImport("Exemplo.dll")]
   private static extern double funcaoExemplo (int valor);

   public double Teste (int value)
   {
      return funcaoExemplo(value);
   }

In terms of performance, C has an advantage over this, since C is a compiled language, whereas C # is a semi-compiled language, depending on the framework .

    
25.09.2016 / 19:06