Advice Needed Regarding C# and C integration

I have a project where I am given C code and I have to implement a GUI for that code. The C code was generated on with a Linux box and gcc. My first thought was to implement the GUI in C# and pass the input parameters to the C file. I researched how to do this but I wasn't coming up with many results. I read about converting C++ files into DLL files. I also read this thread regarding converting C files into C++ DLL files with C++ Express and then using C# Express. I have been talking to my TA who said that this process might be troublesome as the converting process is not very successful. It was suggested to try using the *.exe file that is creating when using the gcc compiler. I have no idea where to begin. Should I try and use DLLs or use the *.exe Does anyone have experience with using C files in C# and can point me in the right direction

I have currently access to: C# Express, Visual Studio(at school only) and Linux.



Answer this question

Advice Needed Regarding C# and C integration

  • Mark Bower

    Thanks for the fast reply, cgraus.
    My C code does work from a CLI but the object is to use a GUI for it. I am a little confused by " uses CLI so you can call it from .NET".
    But I'll take your advice and try downloading C++ Express. Then I'll wrap the C code into a C++ DLL and I can use in in the C# program I can use p/invoke to call the methods that I need
    Does anyone have some sources I could read and look at


  • David A. Coursey

    By CLI, I meant C++/CLI, a type of C++ project in .NET 2005 which you can just import into your C# project and call, without any need for p/invoke.

    I don't know of any references off the top of my head, but you're going to create a C++/CLI dll, you'll write a managed class, and it will expose methods which internally call your C functions and return the results. You're basically writing a .NET wrapper to your C functions in C++, then calling that wrapper ( only your managed C++ classes will be visible to C# ).



  • dba72

    Thanks again.
    I play around with it and come back if I have anymore trouble.


  • Narasimha T.

    If you can run the C program with command line parameters to get the desired result, you could try that. I would definately tend towards writing a C++ dll that wraps the C code and uses CLI so you can call it from .NET, it's just a lot cleaner ( and not a hack ).

    I don't see why the converting process should be unsuccessful, it's not that far from being a trivial task.



  • Advice Needed Regarding C# and C integration