[Solved] What is the main difference between C++ vs C++.NET? [duplicate]

Possible Duplicate:
What is the difference between Managed C++ and C++/CLI?
What is CLI/C++ exactly? How does it differ to ‘normal’ c++?

I am in doubt of distinguishing between C++ and C++.NET.

Is that right C++ is unmanaged code and C++.NET is managed code?

I need to program for a project in C++. For better building the GUI, I would prefer to use C++.NET.

I also have another plain C++ library (unmanaged C++ DLL file), will it be possible to use it as a normal DLL library in the C++.NET project?

Enquirer: olidev

||

Solution #1:

Is that right C++ is unmanaged code and C++.NET is managed code.

There’s no such thing as “C++.NET”. There’s C++/CLI, which is basically C++ with Microsoft extensions that allow you to write code targeting the .NET framework. C++/CLI code compiles to CLR bytecode, and runs on a virtual machine just like C#. I’ll assume you’re actually talking about C++/CLI.

With respect to that, one can say standard C++ is unmanaged and C++/CLI is managed, but that’s very much Microsoft terminology. You’ll never see the term “unmanaged” used this way when talking about standard C++ unless in comparison with C++/CLI.

Both standard C++ and C++/CLI can be compiled by the same Visual C++ compiler. The former is the default on VC++ compilers, while a compiler switch is needed to make it compile in latter mode.

I need to program for a project in C++. For better building the GUI, I
would prefer to use C++.NET.

You can build GUI programs in C++ just as well as C++/CLI. It’s just harder because there isn’t a standard library in standard C++ for building GUI like the .NET framework has, but there are lots of projects out there like Qt and wxWidgets which provide a C++ GUI framework.

I also have another plain C++ library (unmanaged C++ dll), will it be
possible to use it as a normal dll library in the C++.NET project?

Yes. It might take some extra work to deal with the different standard C++ data types and .NET data types, but you can certainly make it work.

Respondent: In silico

Solution #2:

Managed C++ is a now deprecated Microsoft set of deviations from C++, including grammatical and syntactic extensions, keywords and attributes, to bring the C++ syntax and language to the .NET Framework. These extensions allowed C++ code to be targeted to the Common Language Runtime (CLR) in the form of managed code as well as continue to interoperate with native code. Managed C++ was not a complete standalone, or full-fledged programming language.

Managed C++

#using <mscorlib.dll>
using namespace System;

int main()  {
  Console::WriteLine("Hello, world!");
  return 0;
}

Vanilla C++

#include <iostream>
using namespace std;

int main()
{
  cout << "Hello, world!";
 return 0;
}
Respondent: Software_Designer

Solution #3:

Well… C++ .NET is kind of a misnomer.
You can program in C++ using visual studio .NET. Well that’s what it was called along time ago. Now a days folks just call it Visual Studio, with the dot NET moniker. Well, at least the splash screen doesn’t have a big ol .NET in the logo anymore.

It is kind of understood that using Visual Studio (VS), you can program in managed and unmanaged languages (Lots of choices there btw).

If you want to program in C++ using Visual Studio you have two choices:

  1. Unmanaged or native C/C++. This is the old (or new I guess too) C++
    that you have always known, and you program with unmanaged memory.

  2. Managed C++. They call this C++/CLI. That is read C++ over CLI, not
    C++ divided by CLI! This is C++ that has extra keywords, and a few
    extra syntax elements than the native C++. This allows you to
    utilize the .NET Foundation Class Library and do other fun things in
    the .NET framework. This of course uses the garbage collector for
    memory for managed types.

Personally my favorite language is C#, but if you need to interop between C++ and .NET than definitely use Managed C++. It is very easy to do, and I think is easier than that other P/Invoke stuff.

If you are going to some project, I would suggest you do your UI in C# and take advantage of all that it has to offer. Then have that reference a mixed mode managed library that contains your C++ code. I think that will be a lot easier for you.

The answer to your last question is yes, you can definitely use that in your app.

Here is how the dependencies would work:

[C# App/GUI] depends on [Managed C++ assembly] depends on [Native C++ Lib]

Respondent: C Johnson

Solution #4:

  • Yes, C++ is unmanaged code and C++/CLI is managed.
  • Yes, you can use your unmanaged C++ DLL in your C++/CLI project. But you have to write a wrapper for that. That means you have to define the unmanaged methods you want to access in your C++/CLI project.

Example:

using System.Runtime.InteropServices;

[DllImport("YourDLLName")]
public static extern void UnmanagedMethodName(string parameter1);
Respondent: juergen d

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.