LPCWSTR Variable Corrupted
Hello,
I posted this question elsewhere. Im hoing I will get more feedback
here.
I have a MFC class derived from CStdioFile declared as follows
// Datafile.h
class CDataFile : public CStdioFile
{
public:
CDataFile(void);
~CDataFile(void);
int OpenFile(LPCWSTR FileName);
}
After my OpenFile function is called the FileName variable is being
corrupted.
int CDataFile::OpenFile(LPCWSTR FileName)
{
m_OpenFlags = CFile::modeNoTruncate | CFile::modeReadWrite;
// Before open. FileName = "c:\afile.txt"
if (!Open(FileName, m_OpenFlags, NULL))
{
// open always fails as filename corrupted
return GetLastError();
}
//After open. FileName =
""=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=
=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=
=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=
=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=
=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=
=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=EF=BB=AE=DE=88=C4=9A=E1=
=97=B8=C3=B7=E1=98=B8=C3=B7=E3=BC =E7=A2=9E =AD"
// other stuff
}
}
But if I change the FileName to
WCHAR FileName[] = _T("c:\\afile.txt");
Before opening the File the variable Filename remains untouched. I
have seen this behaviour before with the MFC/Winapi and always worked
around it be by using character arrays instead of LPCWSTR or CString.
Why does this happen? and what is the best way to track down problems
such as this with the VS Debugger. The corruption appears to happen
here in the MFC file Filecore.cpp
if (!CFile::Open(lpszFileName, (nOpenFlags & ~typeText), pException))
return FALSE;
Thanks....