|
You need to read the entire file into memory and manipulate it there. Then you have all the values. You can store the file as a BYTE array, that seems to be what you're after.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Could you give me an example of how you do this. I tried to write it byte by byte, but i never get the same result as the original file. And is it possible using CFile.
|
|
|
|
|
What are you trying ? I'm sure CFile can do it, but I have no idea how, I don't use it, ever. I use standard C++ where-ever possible ( so, I use fstreams )
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I think maybe i know why it never worked, I never managed to put it in a byte, only an unsigned char. What should i do to put it in a byte directly?
Also, I used CFile only because i never managed to copy japanese correctly with fstreams.
|
|
|
|
|
samkook wrote: What should i do to put it in a byte directly?
BYTE is a typedef for unsigned char, so, makes no difference.
samkook wrote: Also, I used CFile only because i never managed to copy japanese correctly with fstreams.
OK, well, sounds like you weren't using fstream properly either. A stream should not care if the bytes are japanese text, or a picture of the pope.
I think you need to post code, and wait for someone who uses CFile to step in.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
It would look something like this. It's only a test i made to read the first 10 bytes and them write it.
This code in particular doesn't work, because the second Cfile doesn't want to open and i really don't know why, but it's close enough to what i would do to write it.
private: System::Void mnuSave2_Click(System::Object * sender, System::EventArgs * e)
{
CFile fVampFile;
CFile fVampFileSav;
CString csFilename;
CString csFilenameSav;
unsigned char cByteBuff[1];
int iByteMove = 1;
unsigned char cByteArray[10];
if(odOuvrir->ShowDialog() == DialogResult::OK)
{
csFilename = odOuvrir->FileName;
if( !fVampFile.Open(csFilename, CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary) )
{
MessageBox::Show(S"File probably in use");
}
try
{
fVampFile.SeekToBegin();
for (int iCtr = 0; iCtr < 10; iCtr++)
{
fVampFile.Read(cByteBuff,iByteMove);
cByteArray[iCtr] = *cByteBuff;
}
fVampFile.Close();
if(odSave->ShowDialog() == DialogResult::OK)
{
csFilenameSav = odSave->FileName;
}
if(fVampFileSav.Open(csFilenameSav,CFile::modeWrite | CFile::shareDenyNone | CFile::typeBinary ) )
{
fVampFileSav.Write(cByteArray,10);
}
}catch(...)
{
MessageBox::Show(S"Erreur lors de la lecture du fichier");
}__finally
{
fVampFileSav.Close();
eTexte->Text = "Done!";
}
}
}
};
|
|
|
|
|
You're using managed C++ AND MFC together ?
So long as you're using managed code, have you tried using a filestream ? If this is .NET 2.0, System.IO.File has static methods that will read and write an entire file in one line of code.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Yeah, i'm using both because i wanted to learn .net, but i'm too used to the good old ways.
And i also tried using a filestream(it was the first thing i tried), but i ended with the same result as the fstream.
|
|
|
|
|
samkook wrote: Yeah, i'm using both because i wanted to learn .net, but i'm too used to the good old ways.
IMO the end result is a disaster. Don't worry about the 'new ways', I don't think there's a real future for .NET in C++, certainly not mixed with MFC.
samkook wrote: And i also tried using a filestream(it was the first thing i tried), but i ended with the same result as the fstream.
if(fVampFileSav.Open(csFilenameSav, CFile::modeCreate|CFile::modeWrite | CFile::shareDenyNone | CFile::typeBinary ) )
I had a hard time making your code compile ( it relies on objects that were not there ) but adding CFile::modeCreate caused it to work for me. Otherwise, the file open for write failed altogether.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
samkook wrote: if( !fVampFile.Open(csFilename, CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary) )
Your code is not wrong, but CFile objects open in binary mode by default.
samkook wrote: fVampFile.SeekToBegin();
This is redundant as the file pointer is already positioned at the beginning.
samkook wrote: for (int iCtr = 0; iCtr < 10; iCtr++)
{
fVampFile.Read(cByteBuff,iByteMove);
cByteArray[iCtr] = *cByteBuff;
}
Reading one byte at a time, disk I/O is going to be your enemy here. Try:
int nLength = fVampFile.GetLength();
LPBYTE pBuffer = new BYTE[nLength];
fVampFile.Read(pBuffer, nLength);
fVampFile.Close();
fVampFileSav.Write(pBuffer, nLength);
fVampFileSav.Close();
delete [] pBuffer; Once you get this working correctly, then you can add the code that inserts the new text;
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
hmmm, looks like it's working. I don't know what I was doing wrong before.
Thanks for your help guys.
-- modified at 12:52 Friday 13th October, 2006
Oh and btw, I don't have a choice(maybe i do, but it's easyer that way i think) to read it byte by byte because I need to identify some tags in the file.
-- modified at 12:54 Friday 13th October, 2006
|
|
|
|
|
samkook wrote: I don't have a choice(maybe i do, but it's easyer that way i think) to read it byte by byte because I need to identify some tags in the file.
This makes no sense. Using the code snippet I showed, you can look at each byte of lpBuffer . RAM is a whole lot faster than the disk.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Now that i think of it, your right. I shoudn't reply to message that need thinking when I wake up, it doesn't get good results.
|
|
|
|
|
|
|
Yeah, that'll work! Thanks!
Windows Calculator told me I will die at 28.
|
|
|
|
|
I have 2 dialog,
first dialog I have a checkbox. If you click on that dialog box a new dialog is show and I have a button there and when that button is pressed on I need to end the dialog and the checkbox on the first dialog should not be checked.
So how can I do that? Sorry for the bad english.
|
|
|
|
|
Which part do you have so far and which part are you having trouble with?
Mark
|
|
|
|
|
Larsson wrote: ...when that button is pressed on I need to end the dialog...
Just call EndDialog() like would happen if you clicked the OK button.
Larsson wrote: ...and the checkbox on the first dialog should not be checked.
Just uncheck it with SetCheck() .
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
|
what problems with david crow answer
|
|
|
|
|
ok. I think that you are ok with the first part.
in the second part, you have two approaches:
in the 2nd dlg button write code that looks like this:
void CDialog2::OnButton()
{
(CDialog1 pDlg*)=GetParent();
pDlg->m_ctlCheck1.SetCheck(FALSE);
CDialog::OnOK();
}
or after exiting the 2nd dialog set a flag and check it in the first diaog
regards,
Mohammad Gdeisat
|
|
|
|
|
|
Well this is what I get on (CDialog1 pDlg*)=GetParent();
error C2146: syntax error : missing ')' before identifier 'pDlg'
|
|
|
|
|
Larsson wrote: Well this is what I get on (CDialog1 pDlg*)=GetParent();
Come on ! what you are trying to do ?
I think, CDialog1* pDlg=(CDialog1*)GetParent();
|
|
|
|