Wasa C

Can I use C in C# (I have a C source code.So I want to use C# to create its GUI. How can I do it).
Now my project is create DRM system for windows
and I interest in using C#.

Can I compile my C program into the ".dll" file and use in my C# GUI.

Thank you

Re: Visual C# General I need help

Alberto Poblacion

To the first question, "can I use C in C#", the answer in general is "no, not directly". If you really understand your C code, you may be able to modify it to work in C#. One of the main differences between C and C# is the use of pointers. You can get away with using pointers in C# by marking the section of code that uses them as unsafe{...}. However, there are still important differences between both languages, and you will have to deal with them manually.

To the second one, "Can I compile into a dll and use it from C#", the answer is "yes, if you know what you are doing". I assume that you are producing a standard dll and not a COM object. This can be used from .Net by means of what is called "Platfomr Invoke" or briefly "P/Invoke". From the point of view of C# what you do is that you write an extern declaraction, preceded by an attribute [DllImport] with various arguments indicating the characteristics of the function inside your DLL.

See http://msdn2.microsoft.com/en-us/library/aa288468(vs.71).aspx