10

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 1

13

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);
Sign up to request clarification or add additional context in comments.

4 Comments

hi,I cant debug the program,why the control not going into called function when step over(F11)...?
You can't debug a C dll using the standard debug mechanisms of .Net.
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?
@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.