Discussion:
How to write to HEX file binary information(any data HEX,String)
(too old to reply)
zack
2008-06-22 10:38:01 UTC
Permalink
Hi I am trying to write to hex file ,
this is my first time writing to file in windows vista,
So first i will let the user to create it by the "CFileDialog" and then
save it,
and Then i want to write to the file some data, here is the code i used:
//to save the file
CFileDialog dialog(FALSE,_T("hex"), FilePath, 0, _T("Hex File (*.hex)"),
this);
if (dialog.DoModal() == IDOK)
{
...
}
//open the file for write ,lets say the user choose zack.hex.
nFile = fopen ("C:\Users\user\Documents\IM\coding_PROJECTS\zack.hex","w");
//write to the file 5 char
numberOfBytesWrite = fwrite( sectorBuffer2,sizeof(char),5,nFile);
//close the file
fclose(nFile);

i probebly miss some information,need help
thanks
Jonathan Wood
2008-06-28 06:25:49 UTC
Permalink
The MFC way would be to use CFile instead of file.

Other than that, are there problems with the code you posted other than it
isn't quite finished? If so, what are the problems?

I wrote a commercial hex editor, but it's got all sorts of things going on,
so the way it saves data wouldn't necessarily be a good way for you.
--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
Post by zack
Hi I am trying to write to hex file ,
this is my first time writing to file in windows vista,
So first i will let the user to create it by the "CFileDialog" and then
save it,
//to save the file
CFileDialog dialog(FALSE,_T("hex"), FilePath, 0, _T("Hex File (*.hex)"),
this);
if (dialog.DoModal() == IDOK)
{
...
}
//open the file for write ,lets say the user choose zack.hex.
nFile = fopen ("C:\Users\user\Documents\IM\coding_PROJECTS\zack.hex","w");
//write to the file 5 char
numberOfBytesWrite = fwrite( sectorBuffer2,sizeof(char),5,nFile);
//close the file
fclose(nFile);
i probebly miss some information,need help
thanks
Loading...