tags:

views:

90

answers:

3

Can I include sections of code written in Visual C++ in my C# app, or vise-versa? I know that you can do that in Objective-C, so I wanted to know if it was possible in C# (.NET 4.0).

+4  A: 

Sort of. You can't include them directly in C#, but you can use C# and C++/CLI together, and most C++ can also be compiled as C++/CLI.

Jerry Coffin
+1  A: 

Do you have C++ DLLs? If so, you can call C++ DLLs from within C#. There are a few questions on StackOverflow that discuss similar topics:

http://stackoverflow.com/questions/3579156/how-do-i-use-a-c-library-from-c-and-net

DllImport can be used to indicate the unmanaged code you want to call.

http://msdn.microsoft.com/en-us/library/aa288468%28VS.71%29.aspx

Edward Leno
A: 

Not directly. You can create a DLL from C++ code and call said code from C#, though.

See: Forum thread on related topic, and an introduction to managed C++. There's also an example of mixing C++ / C# here, although it uses the command line to build the code.

cubic1271