Managed C++ vs. C++/CLI vs. C++

When I started my latest project where I needed some basic C libraries to access the Hardware. I thought I will use a Windows Forms Application with C++. I hoped this offers me writing normal C++ code and still use the new UI code from MS. In addition it would possible to port the application since the underlying C library is platform independent and C++ if correctly separated from the UI code should compile as well.

To bad it was not as easy as I hoped it will. The next time I might just chose an MFC Application where I can write native C++ code and I don’t have to bother with some magic C++ addition.

I had quite a hard time to figure out how I need to structure my application that it will work in managed mode. After some googeling I figured out that there are two different things: Managed C++ and C++/CLI. Managed C++ was the old addition from MS. With Visual Studio 2005 they added C++/CLI which is an ECMA standard and has a similar scope as Managed C++. The keywords of C++/CLI are no more marked with two underlines in front as it was with Managed C++. At the end I found an overview that explained me the strange keywords that I found in the new generated code.

The following links give a good overview about the differences between the C++ and C++/CLI:

The result of all this is that my application will not be portable at all since all the code is infected with CLI code. It would have been possible to separate the C++ code from the CLI code in such a way that it could be reused on an other platform but since it is only a prototype and it just has to work on windows. I will leave that for an other time. To separate C++ code from C++/CLI code it is necessary to write some glue code since CLI does not support all features from C++.

Tagged , ,

4 Comments so far

  1.    Duane on April 14th, 2008

    Couldn’t agree more. I thought C# was a useless addition to software development, but C /CLI goes beyond that: a negative contribution. It’s not an advancement in software design, only in Microsoft marketing.

  2.    Alex on September 29th, 2008

    C# Useless? So Java is useless too?

  3.    Mathias Weber on December 10th, 2008

    I don’t think C# is useless. It just provides the same as Java or some other languages. It does some things better than others and it does some other worse as all others.
    But I’m sure that creating CLI was a bad decision, but at least it shows how it shouldn’t be done.

  4.    phalaris on April 19th, 2009

    C /CLI is a huge step forward compared to MFC. I’ve been using C# for a while and was forced to write a couple of DLLs using C /CLI. The learning process couldn’t have been any easier. Everything does what I expect it to do. All keywords are intuitive and make sense within the .NET context. I hardly had to use Google after the first ten minutes. My first attempts at using generics and delegates didn’t even give any compile errors, without any documentation or reference. Go figure. Could it be that Microsoft are actually trying to programming easier for us?

    If you think C# is useless, maybe .NET is useless too? So why are you even using it in the first place? Why not meet your deadlines on your Gentoo box and make your commercial grade apps with Swing? 🙂