Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Cfile problem with LPCTSTR

dhurlstondhurlston Member Posts: 2
I can't get past this...

With code such as this taken from MFC Help:

//example for CFile::Open
CFile f;
CFileException e;
char* pFileName = "test.dat";
if( !f.Open( pFileName, CFile::modeCreate | CFile::modeWrite, &e ) )
{
#ifdef _DEBUG
afxDump << "File could not be opened " << e.m_cause << "
";
#endif
}
The compiler chokes with the error "cannot convert parameter 1 from 'const char *' to 'LPCTSTR' "


If I change code to:

if( !f.Open( LPCTSTR (pFileName), CFile::modeCreate | CFile::modeWrite, &e ) )

then the compiler is happy but pFileName passed to CFile::Open points to junk.

I'm no MFC wiz, so excuse me if I am doing something dumb. By the way, the code used to work fine in an older version of Visual Studio. I am using the 2005 version now.



Comments

  • stoberstober Member Posts: 9,765 ✭✭✭
    One of the changes made in VC++ 2005 was to make UNICODE the default setting, so your program is probably being compiled for UNICODE. You can turn that off by selecting menu Project --> Properties --> Configuration Properties --> General. Then change Character Set value to "Not set".
    =============================================
    never lie -- the government doesn't like the competition. (Author unknown)
  • dhurlstondhurlston Member Posts: 2
    Exactly right. Thank you, thank you, thank you!
Sign In or Register to comment.