tags:

views:

76

answers:

3

I was wondering - how much limitation is there to C++/CLI compared to classic C++ (chuckle) - I was wanting to write an application that I cannot do with c# -- I was wanting to be able to connect to the PC's audio device and detect audio (for example) - Is this something I can do with C++/CLI?

I have tried using NAudio with c#, but i have been able to do this. What other advantages would C++/CLI or C++ give me over c#?

+1  A: 

Yes. C++/CLI gives you the full power of native C++ as well as .NET, because you can mix the two as much as you want (even inside one function). So you can write the parts that need to be native in native C++ and the rest in .NET if it's easier (which it usually is).

Evgeny
I wouldn't say "it usually is" when referring to writing things in .NET *in* C++/CLI, but C++/CLI lets you interface native code with C# code where it *is* usually easier to do things...
Dean Harding
I was even hoping to just write the specific parts in VC++ and utilize the functionality via C# via PInvoke - is that a bad idea?
schmoopy
codeka - ha, you musta wrote that before i clicked 'add comment' -- Would i have to use PInvoke if i took this approach or can C# access C++/CLI just like any c#/vb.net dll ?
schmoopy
C++/CLI emits managed assemblies with full metadata that C# can use just as easily as any of the Microsoft-provided classes. In fact, I'm pretty sure that's how Microsoft builds System.dll and mscorlib (plus some secret sauce so the C++ runtime isn't required), the rest of the BCL appears to be pretty much pure C#.
Ben Voigt
+1. C++/CLI is actually best of both worlds, because it allows you to mix-and-match native code (when you need raw pointer-manipulating power, or when you need to talk to C/C++ only APIs without needing to recreate Byzantine structs in managed code) with the availability the immense .NET class library (crypto stuff, easy string manipulation, web services, ...)
Guido Domenici
+1  A: 

Disclaimer: C++ is my favorite language, so I'm a bit biased against Virtual Machines like the CLR.

What other advantages would C++/CLI or C++ give me over c#?
Personally I'd never use C++/CLI unless I needed to wrap an existing C++ codebase for use in .NET. C++/CLI seems to have all the warts of C++ and .NET combined into one hacky solution. If .NET is your primary target, I'd use C# -- it's going to make your job a whole lot easier.

Billy ONeal
But i cant do what i want with C#, thats why i'm looking into a more low-level'ability language. C# provides no direct access to hardware and there is no support for the audio functionality that i need - like determining if any sound is coming out of the audio device, or starting a recording if an audio level is above a certain threshold
schmoopy
@schmoopy: Then I'd use normal C++, not C++/CLI.
Billy ONeal
billy - are you saying that normal C++ has much more control/capability with hardware?
schmoopy
@schmoopy: No, but I see no benefit of using C++/CLI over plain C++. The only thing I use that for is a bridge between managed code land and unmanaged code land. If your needs lie in exclusively one land or the other, use the tool designed specifically for the environment you want.
Billy ONeal
If you want to use a C# GUI and call some native APIs, then C++/CLI is a great choice. You can define the managed<->native interface the way you like (non-chatty for efficiency) and call native APIs just as easily as you can from normal C++. But talking to C# is much much easier with C++/CLI.
Ben Voigt
+1  A: 

If you want to capture audio input from a C# app, then all the hard work of writing the C++/CLI wrappers have already been done for you by the good folks over at SlimDX - they've wrapped pretty much everything in DirectX for use in managed applications.

Personally, I wouldn't recommend writing anything in C++/CLI if you can possibly avoid it.

Dean Harding