Click here to Skip to main content
15,908,111 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Magnifying image & Resetting client scrollbars? Pin
Kiran Satish26-Mar-09 6:07
Kiran Satish26-Mar-09 6:07 
QuestionHow to catch a Msg in CView? Pin
Software200727-Feb-09 9:39
Software200727-Feb-09 9:39 
AnswerRe: How to catch a Msg in CView? Pin
Stuart Dootson27-Feb-09 9:55
professionalStuart Dootson27-Feb-09 9:55 
General[Message Deleted] Pin
Software200727-Feb-09 10:06
Software200727-Feb-09 10:06 
GeneralRe: How to catch a Msg in CView? Pin
Stuart Dootson27-Feb-09 10:16
professionalStuart Dootson27-Feb-09 10:16 
GeneralRe: How to catch a Msg in CView? [modified] Pin
Software200727-Feb-09 10:19
Software200727-Feb-09 10:19 
GeneralRe: How to catch a Msg in CView? Pin
Stuart Dootson27-Feb-09 10:48
professionalStuart Dootson27-Feb-09 10:48 
QuestionEvery Alternative Character is NULL while writing to a file Pin
Neelesh K J Jain27-Feb-09 5:13
Neelesh K J Jain27-Feb-09 5:13 
Hello Everybody,
I am facing a strange problem.
Requirement: Get the length of contents of a file and modify the header present in the file to represent the length in Hexadecimal format.
Existing Code:
if( cFilePointer.Open(strFileName ,CFile::modeRead)  )
{
	strContents.Empty();
	dwRead = 0;
        // Read the contents of the file and store in the CString object.
	do
	{
		dwRead = cFilePointer.Read(cBuffer,100);
		if ( dwRead > 0)
			strContents.operator +=(cBuffer);
	}while(dwRead > 0 );

        // Retrieve the length of the string and convert to Hex decimal number
	int iTotalLength = strContents.GetLength();
	sprintf(cLengthOfString,"%4x",iTotalLength);
	for ( int iIndex = 0;iIndex<4;iIndex++)
	{
                // If the hexadecimal number is only one digit then convert the others to zero.e.g., if the length is 5, then convert to 0005
		if ( cLengthOfString[iIndex] == 32 )
			cLengthOfString[iIndex] = 48;
                // Store the length (which is in Hexa decimal format to the 6th, 7th, 8th and 9th characters of the file
		strContents.SetAt(iIndex+6,cLengthOfString[iIndex]);
	}
	cFilePointer.Close();
	int iTemp = 0;
	int iIndexOfChar = 0;
	int iFileNameLength = strFileName.GetLength();
	CString strSlash("\\");
        
        // Add the slash to escape so that strFileName will have a proper path.
	while ( iTemp < iFileNameLength)
	{
		iIndexOfChar = strFileName.Find(strSlash,iTemp);
		if ( iIndexOfChar == -1 )
			break;

		strFileName.Insert(iIndexOfChar,strSlash);
		iTemp = iIndexOfChar + 2;
	}

        //  Re-create the file with the header information modified.
	hFile = CreateFile(strFileName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
	if ( hFile )
		cFilePointer.m_hFile = hFile;
	if(cFilePointer)
	{
		cFilePointer.Write(strContents,iTotalLength);
		cFilePointer.Close();
	}
}


Problem:

When I executing the above code, the file is having every alternative character as NULL.

Please help in the above.
Thanks in advance,
Neelesh K J Jain.
AnswerRe: Every Alternative Character is NULL while writing to a file Pin
Stuart Dootson27-Feb-09 5:42
professionalStuart Dootson27-Feb-09 5:42 
GeneralRe: Every Alternative Character is NULL while writing to a file Pin
Neelesh K J Jain27-Feb-09 6:06
Neelesh K J Jain27-Feb-09 6:06 
GeneralRe: Every Alternative Character is NULL while writing to a file Pin
Iain Clarke, Warrior Programmer27-Feb-09 7:45
Iain Clarke, Warrior Programmer27-Feb-09 7:45 
GeneralRe: Every Alternative Character is NULL while writing to a file Pin
Stuart Dootson27-Feb-09 8:16
professionalStuart Dootson27-Feb-09 8:16 
Questionnumbers per line Pin
jonig1927-Feb-09 4:40
jonig1927-Feb-09 4:40 
AnswerRe: numbers per line Pin
Stuart Dootson27-Feb-09 5:40
professionalStuart Dootson27-Feb-09 5:40 
GeneralRe: numbers per line Pin
jonig1927-Feb-09 8:36
jonig1927-Feb-09 8:36 
GeneralRe: numbers per line Pin
Stuart Dootson27-Feb-09 8:51
professionalStuart Dootson27-Feb-09 8:51 
QuestionProject settings in Visual Studio 2005/2008 Pin
Eikthrynir27-Feb-09 4:38
Eikthrynir27-Feb-09 4:38 
AnswerRe: Project settings in Visual Studio 2005/2008 Pin
Stuart Dootson27-Feb-09 5:33
professionalStuart Dootson27-Feb-09 5:33 
Questionhow to use shared_ptr in VC++ 6.0 Pin
vibindia27-Feb-09 3:59
vibindia27-Feb-09 3:59 
AnswerRe: how to use shared_ptr in VC++ 6.0 Pin
Stuart Dootson27-Feb-09 4:15
professionalStuart Dootson27-Feb-09 4:15 
AnswerRe: how to use shared_ptr in VC++ 6.0 Pin
Chris Losinger27-Feb-09 4:23
professionalChris Losinger27-Feb-09 4:23 
QuestionTell linker to add cpp files Pin
dehseth27-Feb-09 3:24
dehseth27-Feb-09 3:24 
AnswerRe: Tell linker to add cpp files Pin
Stuart Dootson27-Feb-09 3:35
professionalStuart Dootson27-Feb-09 3:35 
QuestionRe: Tell linker to add cpp files Pin
dehseth27-Feb-09 3:50
dehseth27-Feb-09 3:50 
AnswerRe: Tell linker to add cpp files Pin
Stuart Dootson27-Feb-09 4:11
professionalStuart Dootson27-Feb-09 4:11 

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.