Computer Science Canada

C# interfacing with other programs (C)

Author:  mirhagk [ Sun Nov 14, 2010 11:46 pm ]
Post subject:  C# interfacing with other programs (C)

I have code that is written in C (and am unable to port over to C# due to complexity as well as C libraries depended upon). However it is merely an interface kind of code, the backend for a project. I want to create the front end that takes information it gathers and displays it (it includes video data). I am not too familiar with C, and would VERY much like to create the front end thingy in C# (so that I can easily get the visuals working).

My only question is how do I do this. I need to write a C# program that calls functions from a C program.... I'm almost 100% I can do this, but how??? What's the easiest way?

Author:  TheGuardian001 [ Mon Nov 15, 2010 12:03 am ]
Post subject:  Re: C# interfacing with other programs (C)

If you compile the C program to a dll, you can use the DllImport function to specify that the next method is contained within that DLL. These methods must also be declared "static" and "extern"

code:

[DllImport("myDll.dll")]
public static extern int myMethod(string param1);


You can then call the method as normal.

Author:  mirhagk [ Mon Nov 15, 2010 8:25 am ]
Post subject:  RE:C# interfacing with other programs (C)

okay cool, not to just figure out how to get it to be a dll (pretty sure it has a project type of that, but I think mine only has the special class library one...Sad

Thank you (this actually relates to my last post, about the kinect utility program. I want to create a C# interface to it.)


: