How to create native DLL in Visual Studio from C# code?

c#, c++, dll, visual-studio

Solution

If you want the program to be native, and not managed, you'll need to port it to C++, instead of using C#.

That being said, you can compile it in C# into a library, and use it from C++ by using C++/CLI. This just requires that you compile the files that use the C# library with the /clr flag. This provides C++ access to the .NET framework, and lets you use libraries made in C# directly from C++.

Alternatively, you can use .NET's COM interop to expose the C# class(es) as COM objects, and then use those from native C++.

Problem

I have the source code of a C# program. I want to create a DLL out of it which I want to use in C++. Is it possible to create a native DLL in Visual Studio 2008 which can be used in C++?

Original source