Friday, June 12, 2009

Wrestling with C++/CLI

I'm looking at a possible computer telephony project that might make use of Aculab's products. I used the Aculab PCI card back in 2002 to do SS7/C7 switching with the telcos when I was still in that line of business. Ah, those were the days when I lived and breathed Dialogic code.

I remember the Aculab card as a very powerful card and quite affordable for something that can do SS7. Dialogic's equivalent product (the former DataKinetics) cost considerably more especially if you factor in the cost of the software. In the case of Aculab, the software protocol stacks are free. You just buy the board. And with Linux support plus great technical support, it was a hands-down winner.

I've been studying the trial version of Prosody S, their host-based media processing (HMP) platform. The API's only support C/C++ for multi-platform portability. I was hoping they would have C# libraries but unfortunately, they did not. Their pre-sales tech guy gave me a sample in C#, but it makes direct socket calls, as opposed to, using the API function calls. So it looked really messy.

So I figured I might as well install Visual Studio's C++ and see if I can shake off my C++ cobwebs. I haven't written in C++ for probably 5 to 6 years already. And when I did write in C++, I used Borland C++Builder for Windows and the GNU C++ compiler for Linux. I never actually used Microsoft's Visual C++. I never bothered to learn the Microsoft Foundation Classes (MFC). So I figured I'm going to have a bit of an uphill climb here.

After installing VS2005's C++ support, I made it create a .NET windows app using its templates. When I saw the code, my first reaction was -- What The F***?! It looked totally alien and unlike the C++ I knew. There were new operators (the caret ^) which I'm pretty sure is not part of standard C++.

I tried copying-and-pasting some code from the Aculab examples, and the compiler gave me all sorts of error messages about converting unmanaged code to managed. The uphill climb is starting to look like an up-mountain climb. As usual, I went to Google and did some query on C++/CLI (Common Language Infrastructure). The CLI is Microsoft .NET's common managed environment for its new generation of languages. Using C# and VB.NET with CLI is really trivial. But using it with an "old", unmanaged language like C++ involves a lot of changes.

Here are some quick tutorials I found on getting up-to-date on C++/CLI:
Just converting between the old, null-terminated string (char *) in C/C++ to the managed System.String (or System::String in C++/CLI format) version involves several steps. But I guess that is really the way to go. I mean, doing Windows programming with MFC or the native Windows API calls is a worse option.

No comments: