Syntax error declaring CString

My VC6 application is a C++ dll but is essentially just C code. I need to call a routine in another library but when I include the header file containing the prototype for the routine I get syntax errors because of CStrings declared in the header file. What do I need to do to make the compiler recognize CStrings

Thanks



Answer this question

Syntax error declaring CString

  • tsennyuen

    Due to the graces of Microsoft, VS 2005 lets you include CString as a standalone class without having to take all of MFC.    Here's an example of C++ code that uses CString.

    #include "atlstr.h"
    int _tmain(int argc, _TCHAR* argv[])
    {
       CString s(
    "boofar" );
       wprintf( s.GetString() );
       return 0;
    }

    I know that this doesn't solve your VC6 issues, however.  People have separated it from MFC.  You might want to search the net...


  • Carl Brochu MSFT

    CString is part of MFC, so the easiest route would be to build a DLL that supports MFC.  A quick search of the MFC source leads me to believe that AFX.h defines CString.  However, if you're going to use any of these classes, you need to also link against MFC.  The easiest way, IMO, is to create an MFC dll shell and copy your code across, unless it's huge.


  • Mehmet Atlihan

    It sounds to me that while you are including the header file that declares the routine that you need to use you are not including the header file that defines CString. You need to find and include this header file. Unfortunatley it is so long since I used Visual C++ 6.0 that I have forgotten which header file this is: sorry.



  • Syntax error declaring CString