Converting 'ATL::CString' to 'const char *'

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I am trying to write a DLL that post debuging information to another process. A similar DLL has been written that works in Visual Studio 2003. I am using Visual Studio 2005 and the following code, exactly as is in the VS2003 version,
void CMyTrace::Trace(const char* file, const char * function, unsigned int line, const char * format,...)
{
    char buffer[1024];
    HWND hwDispatch = FindWindow(NULL,L"Tracer");
   
    va_list marker;
    va_start(marker,format);
    vsprintf(buffer,format,marker);
    va_end(marker);

    CString szText;
    szText.Format(L"%s %d %s", function,line,buffer);
   
    strcpy(buffer,szText);

    COPYDATASTRUCT MyCDS;

    MyCDS.dwData = 0;
    MyCDS.cbData = strlen(buffer);
    MyCDS.lpData = buffer;
    if (hwDispatch != NULL) {
        SendMessage(hwDispatch,WM_COPYDATA,(WPARAM)(HWND) NULL,(LPARAM) (LPVOID) &MyCDS );
    }
}
bombs out saying:
1>h:documents and settingsg02c1178.ictmy documentsmasters 2006-7new hal apiimplementationdiceiidiceiihalmytrace.cpp(26) : error C2664: strcpy : cannot convert parameter 2 from ATL::CString to const char *
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

How do I convert from ATL::CString to const char *. I know some of the functions above such as vsprintf have been declared as deprecated but I would like to solve the first problem for now


View the full article
 
Back
Top