problems with convertion LPCTSTR and char

Posted on 2006-04-11
Last Modified: 2008-02-01
I get problems when trying to send char* cHTML to the WriteToFile method.
char szBuffer[1024];
char* cHTML;

cHTML = (char*)szBuffer;
WriteToFile("C:\\rInfo.txt",(LPCTSTR) cHTML); //error C2664: 'WriteToFile' : cannot convert parameter 1 from 'const char [13]' to 'LPCTSTR'

void WriteToFile (LPCTSTR lpFileName, LPCTSTR msg)

     fstream f;, ios::app);

     //Save the message
     f << msg << endl;



Any idea?

Question by:m-jansen
    LVL 86

    Expert Comment

    Make that

    cHTML = (char*)szBuffer;
    LPCTSTR pszFile = "C:\\rInfo.txt";
    WriteToFile(pszFile,(LPCTSTR) cHTML);

    and that should work.

    Author Comment

    This is what that happen now

     cHTML = (char*)szBuffer;
     LPCTSTR pszFile = "C:\\rInfo.txt";  // Error      3 error C2440: 'initializing' : cannot convert from 'const char [13]' to 'LPCTSTR'
     WriteToFile(pszFile,(LPCTSTR) cHTML);
    LVL 86

    Accepted Solution

    That's odd - are you compiling with UNICODE defined? If so, try

    #include <tchar.h>

    LPCTSTR pszFile = _T("C:\\rInfo.txt");
    WriteToFile(pszFile,(LPCTSTR) cHTML);

    Author Comment

    > That's odd - are you compiling with UNICODE defined?
    It looks like that - Configuration Properties -> Characer Set -> Use Unicode Character Set (default in VC8-2005)

    Author Comment

    it compiles too. thanks alot.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
    Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
    The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now