A few months back I was working on a nice little project that had to be developed in VC++ to meet the customer’s requirements.

One of the goals of the project was to make extensive use of the Internet Explorer Web browser control. So with that in mine, I had to blow the dust off my ATL 3.0 programming books and jump on the way back machine to about 3+ years ago, just to the exact moment before I moved from Visual C++ development to .NET :)

Getting back up to speed on all of the intricacies of VC++ COM development was fairly straight forward. It was like I never left it :) But while I was programming away with IUnknown's and sinking events, I began to re-appreciate the pleasure it is to development in a .NET environment vs. the pre .NET days.

Take for example the humble *string*. Can anyone think of a project they have worked on where they have not used strings? Personally, I can't?   Think about it, String and String manipulation is just one of those things that occurs everywhere in software development projects.

In the pre-.NET days you had so many different string types and ways to manipulate strings; it was always a struggle to determine which was the right one to use.

Take COM for example. a string in COM is called a BSTR (aka a Binary String or a Basic String). I know the VB6 developers are going to go huh?? What?? Well......., ahhh ok.....! What VB6 developers actually used in the language was a string type and this was a BSTR under the hood.

So getting back to COM for the VC++ developer. You had a BSTR type as the COM way of representing a string. If you got paid by the lines of code you wrote:), you would use the raw Win32 API's directly and call the SysAllocString/SysFreeString sequence directly.  But if you were paid to write code quickly you would simply use a C++ class that would encapsulate some of the common house keeping chores using either some of the classes in the Microsoft supplied libraries or a library you developed/sourced from somewhere. But even if you standardized on one particular BSTR wrapper class, it was always too tempting to try one of the others? as you had (and still do) the option of ( I think I have these right!!):

  • ATL's CComBSTR
  • VC++'s _bstr_t
  • MFC's CString for "C" strings
  • The vanilla BSTR type and your own bespoke wrapper class
  • WTL hasa string class also, CString I think
  • MFC V7 and ATL V7 brought you CStringT, which did a decent job of consolidating the manipulation of the char and wchar_t types and then allocating ("AllocSysString")  a BSTR if you wanted.

And now that this VC++ project is complete, I'm happy to be back in the System.String world ;)