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
1 Answer
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);
4 Comments
Dark Knight
hi,I cant debug the program,why the control not going into called function when step over(F11)...?
Residuum
You can't debug a C dll using the standard debug mechanisms of .Net.
NobbZ
That link to the MSDN-magazine does point to the index of all issues, not to an issue or article. Can someone provide a working link or at least issue number?
Residuum
@NobbZ I cannot find the article any more, as Microsoft does not believe in Tim Berners-Lee's dogma "cool URLs don't change". I will replace it with another tutorial that is hopefully available from that URL for longer.