0

I am basically .net developer and having zero knowledge on c. Today i got below task. There is a c program to add two numbers. C program contains method which takes two numbers to add as parameters. Now I want to access these c methods(objects) in my .net MVC or webapi2. I should call c program(object) to add two numbers and should give output in HTML using .net. I have no idea where to start this! Can someone educate me on this or someone share me usefull links to in order to understand in better way. Any help would be greatly appreciated. Thank you.

Niranjan Godbole
  • 2,135
  • 7
  • 43
  • 90
  • I think what you're looking for is COM (component object model). Or it might be Windows Communication Foundation. Or they might be asking for a simple `exec` type thing – information_interchange Dec 07 '17 at 04:09
  • Two suggestions: narrow your question down, and show a little bit of research effort. First issue I believe is: how do you [call a C library from C#?](https://www.google.com.au/search?q=call+c+library+from+c%23&oq=call+c+library+from+c%23&aqs=chrome..69i57j0l2.9680j0j7&sourceid=chrome&ie=UTF-8) What have you tried? What is not working? Show us some code. – pcdev Dec 07 '17 at 04:10
  • Thanks for suggestions and feedback. I have not tried anything. By looking above comments I understood there are two ways to do this. First one is com second one is as you said call c library from c#. So these both ways works? – Niranjan Godbole Dec 07 '17 at 04:14
  • What format is the "C program" or "c methods (objects)"? Is it an executable, or are you calling a library (I assumed library, but perhaps I'm wrong)? If you need to call an executable, [have a look at](https://msdn.microsoft.com/en-us/library/e8zac0ca.aspx) `Process.Start()` with parameters. There are a few different ways to call things outside of managed code, but it largely depends on what you are trying to call. Need more info. – pcdev Dec 07 '17 at 04:26
  • Thanks pcdev. Let's say c library I want to access. – Niranjan Godbole Dec 07 '17 at 04:29
  • Possible duplicate of [Use a C library from C# code](https://stackoverflow.com/questions/9093292/use-a-c-library-from-c-sharp-code) – ProgrammingLlama Dec 07 '17 at 04:32
  • Simplest method is to use P/Invoke and DllImport in C# to call the C methods. Your question does not make sense - C is not an OOP language, nor does it support objects. C++ added OOP to C – Ashley Pillay Dec 07 '17 at 05:02

0 Answers0