Flashbacks to string handling in C++

Wednesday, February 11, 2004

For the last 18 months I’ve done no real development outside of C#. After 10 years of C++ I was starting to think at times I missed it. Then I downloaded the source code to Allegiance, because I just can’t resist looking at source code. I ran across this:

while (true) {
    UpdateText((char*)LPCTSTR(CString("Copying ") + CString(data.cFileName)));
    if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
        if (
               (strcmp(data.cFileName, "." ) != 0)
            && (strcmp(data.cFileName, "..") != 0)
        ) {
                (char*)LPCTSTR(CString(pchFrom) + CString("\\") + CString(data.cFileName)),
                (char*)LPCTSTR(CString(pchTo  ) + CString("\\") + CString(data.cFileName))
    } else {
        if (!
                (char*)LPCTSTR(CString(pchFrom) + CString("\\") + CString(data.cFileName)),
                (char*)LPCTSTR(CString(pchTo  ) + CString("\\") + CString(data.cFileName)),
        ) {
            Error("Error copying file.");
    if (!FindNextFile(hff, &data)) {
        if (GetLastError() == ERROR_NO_MORE_FILES) {
        Error("Error reading directory contents");

Two thoughts came to mind. First, I cherish the string class in .NET. Second, I realize now I never did like Hungarian notation.

I also had flashbacks to a code review I did about 4 years ago. Another guy and I sat down to prepare and quickly realized our coding standards were missing something important, specifically, how to deal with strings. Inside of the source file for a single COM component (not much code really) we found all of the following were present: CString, CComBSTR, _bstr_t, _T, LPCTSTR, BSTR, wchar_t, and char *. I’m not sure if I remembered them all, perhaps there was an OLECHAR mixed in there too. In any case, it's nice working with just one simple string class, with the occasional StringBuilder thrown in.

Also, I closed a support case with Microsoft recently. There is a bug in the Office 2000 version of OWC and it wouldn’t display all my cube dimensions. More details in this article.

Comments are closed.
Pluralsight Courses
What JavaScript Developers Should Know About ECMAScript 2015
The Podcast!