Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling c function from C#

Tags:

function

c#

.net

as a simple example, i have a C function which receives an int,increment it and return incremented value.on the other side I enter the input number to textbox in C#. how can i call C function to process the number and return it back from c#?Thanks in advance

like image 292
Dark Knight Avatar asked Nov 18 '10 09:11

Dark Knight


1 Answers

You are looking for P/Invoke.

You do will need a Reference to System.Runtime.InteropServices and then do the following, if your C DLL contains a function called increase_int:

[DllImport("mylib.dll")]
private static extern int increase_int(int in_value);

and use it from your code doing

int newValue = increase_int(oldValue);
like image 138
Residuum Avatar answered Oct 20 '22 19:10

Residuum