Click here to Skip to main content
15,899,754 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Create a gui for linux. Pin
Rajesh R Subramanian11-Mar-10 22:35
professionalRajesh R Subramanian11-Mar-10 22:35 
Answer<b>Don't use QT!</b> Pin
CPallini11-Mar-10 22:48
mveCPallini11-Mar-10 22:48 
GeneralRe: Don't use QT! Pin
Moak12-Mar-10 2:48
Moak12-Mar-10 2:48 
GeneralRe: Don't use QT! Pin
CPallini12-Mar-10 2:56
mveCPallini12-Mar-10 2:56 
AnswerRe: Create a gui for linux. Pin
Tim Craig12-Mar-10 10:32
Tim Craig12-Mar-10 10:32 
Questionloading menu dynamically Pin
Member 59031011-Mar-10 19:37
Member 59031011-Mar-10 19:37 
AnswerRe: loading menu dynamically Pin
R@jeev K R11-Mar-10 19:43
R@jeev K R11-Mar-10 19:43 
QuestionStrings revisited:CFile and CStdioFile [modified] - Sort of solved Pin
PaulowniaK11-Mar-10 18:58
PaulowniaK11-Mar-10 18:58 
So having bashed my head against the wall and having done as much reading as possible, I'm still confused.Confused | :confused:

My understanding from other posts was that char* is an array of single bytes, and that in VS2005, CString is Unicode. But I seem to have a mixture of this...

I'm doing:
void CMyClass::MyFunc()
{
	CFile myFile(L"C:\\MyFile.txt", CFile::modeRead);
	char* pchContents = new char[myFile.GetLength()];
	myFile.Read(pchContents, myFile.GetLength());
	CString myString = (char*)pchContents;
	myFile.Close();
	delete[] pchContents;
}


but myString is strangely spaced out and have odd bits added to the front and back. Does this mean the contents of pchContents got turned into wide characters?

Anyway, the problem is that after a load of other operations, I have to turn myString back into char*. But wcstombs_s fails because it encounters wide characters.

What I really don't get is the fact that this whole thing works if I don't read from file into myString but build it up using MSXML and cast the resulting BSTR into CString. I thought all CString was wide, so how come I seem to be having two different flavours?

=========================================

The long and the short of it is that I now have a working piece of code.
I'm not entirely sure what happened.

Basically, I was reading in a file (xml file) edited using Visual Studio 2005. I rewrote the thing in notepad and it works fine now.

I guess my code was right in the first place, but the file I was reading wasn't.

I'm guessing that Visual Studio added some MBCS into my file outside of what I typed and that was tripping up my wcstombs_s.

Am I right?
modified on Sunday, March 14, 2010 11:55 PM

AnswerRe: Strings revisited Pin
Cool_Dev11-Mar-10 19:32
Cool_Dev11-Mar-10 19:32 
GeneralRe: Strings revisited Pin
PaulowniaK11-Mar-10 20:14
PaulowniaK11-Mar-10 20:14 
GeneralRe: Strings revisited Pin
Cool_Dev12-Mar-10 0:06
Cool_Dev12-Mar-10 0:06 
AnswerRe: Strings revisited Pin
Eugen Podsypalnikov11-Mar-10 19:33
Eugen Podsypalnikov11-Mar-10 19:33 
AnswerRe: Strings revisited Pin
Cedric Moonen11-Mar-10 20:24
Cedric Moonen11-Mar-10 20:24 
GeneralRe: Strings revisited Pin
PaulowniaK11-Mar-10 20:46
PaulowniaK11-Mar-10 20:46 
AnswerRe: Strings revisited Pin
KingsGambit11-Mar-10 21:05
KingsGambit11-Mar-10 21:05 
GeneralRe: Strings revisited Pin
PaulowniaK11-Mar-10 21:22
PaulowniaK11-Mar-10 21:22 
GeneralRe: Strings revisited Pin
KingsGambit11-Mar-10 21:56
KingsGambit11-Mar-10 21:56 
GeneralRe: Strings revisited Pin
PaulowniaK14-Mar-10 15:11
PaulowniaK14-Mar-10 15:11 
AnswerRe: Strings revisited Pin
KarstenK11-Mar-10 21:52
mveKarstenK11-Mar-10 21:52 
GeneralRe: Strings revisited Pin
PaulowniaK11-Mar-10 22:19
PaulowniaK11-Mar-10 22:19 
GeneralRe: Strings revisited Pin
KarstenK11-Mar-10 22:21
mveKarstenK11-Mar-10 22:21 
GeneralRe: Strings revisited Pin
PaulowniaK14-Mar-10 15:04
PaulowniaK14-Mar-10 15:04 
GeneralRe: Strings revisited Pin
KarstenK14-Mar-10 21:34
mveKarstenK14-Mar-10 21:34 
AnswerRe: Strings revisited Pin
mahendra.kumar.78611-Mar-10 23:41
mahendra.kumar.78611-Mar-10 23:41 
GeneralRe: Strings revisited Pin
mahendra.kumar.78611-Mar-10 23:54
mahendra.kumar.78611-Mar-10 23:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.