Monday, September 23, 2013

Five finger exercise -- simple cmdlet in C++/CLI

I tend to forget that there are other .net languages than F# (oh, and the one that pays my salary); in particular, after some traumatic encounters with the original Managed C++, that C++/CLI is there and isn't too bad, especially when significant native interop is required (where even F#'s P/Invoke starts to drown in attributes). But for hardcore managed stuff...?

So I've been playing with some native code again, and was thinking to surface the functionality in PowerShell, since GUI programming is pretty tedious (I've set projects aside for half a year or more when the next step is to include a tree view control). So my first thought was to do that in F#, as I did that ages ago, back when you needed snap-ins and there were glitches in how F# compiled against that particular object inheritance tree.

But then, I thought, there's no need to be so polyglot, even if C++/CLI is a bit like Geordie when compared to Standard C++'s RP. So, to practice with the somewhat distractingly different keyword placement, here's the very first example from the old (and out of print) Wrox book


and, yes, snap-ins are old-tech, but they provide examples of how to override property definitions (in the simplest form, without mapping names). This has also been tweaked to be FxCop clean, including for the MSFT powershell rules.

Of course this was the point where I discovered that C++/CLI in VS2010 will only target .net 4, and I was writing this on my old Vista laptop, without space for back-version installs, and had to use the old familiar hack. But, that aside, it all went through most gratifyingly.

Next, to port one of the real examples, to see what other joy is involved.

No comments :