|
Sure.
But how can I attach them. I can't see your mail address. If I past on the mail-body here in the forum it can be a real mess.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: void CSRFToolDlg::OnBnClickedRead()
{
char tempBuffer[256] ;
I think _UNICODE is defined your project so you are writing some wchar and trying to read some multi byte cahracters. try changing the following way
void CSRFToolDlg::OnBnClickedRead()<br />
{<br />
TCHAR tempBuffer[256] ;<br />
UINT readText = 0;<br />
readText = openFile.Read(tempBuffer, 256 ) ;<br />
SetDlgItemText(IDC_S_READ, readText) ;<br />
}
|
|
|
|
|
I think the issue is on UINT. Is says that cannot convert parameters of SetDlgItemText() from 'UINT' to 'LPCTSTR'
I appreciate your help all the time...
Eranga
|
|
|
|
|
I just noticed you are trying to set the number of bytes returned by the read() function. If you want to set the read text change the readText with tempBuffer.
SetDlgItemText(IDC_S_READ, tempBuffer) ;
|
|
|
|
|
I want to print the text which is write to the file. No need to find the number of bytes. Initially I've tried this one also. What happened is print some annoying text on the edit control. It is true, because the buffer is size of 256 which I've defined.
I appreciate your help all the time...
Eranga
|
|
|
|
|
did u try after changing the char tempBuffer to TCHAR tempBuffer ?
|
|
|
|
|
Yes I've tried it.
<br />
UINT readText = 0;<br />
readText = openFile.Read(tempBuffer, strlen(tempBuffer)) ;<br />
It's gives the error on above code. Gives an error on UINT and LPCTSTR. But I can't find any such conversions.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: UINT readText = 0;
readText = openFile.Read(tempBuffer, strlen(tempBuffer)) ;
This is not the code I suggested you earlier
void CSRFToolDlg::OnBnClickedRead()
{
TCHAR tempBuffer[256] ;
UINT readText = 0;
readText = openFile.Read(tempBuffer, 256 ) ;
SetDlgItemText(IDC_S_READ, tempBuffer ) ;
}
The readtext is having the number og bytes read by the read function. And you are trying to set that UINT value to the edit box???? the tempBuffer containes the data actaully read from the file.
|
|
|
|
|
No dear, I'm talking about the same code as you say. I check all your suggestions, as I said earlier post it print some annoying characters except the text on the file. Until it fill-up 256 characters.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: it print some annoying characters except the text on the file
ok. that makes sense.
Now can you read the text in the file you open it in notepad?
|
|
|
|
|
I think you are still not clear on my question. can write anything to a file. But I can't read it still. When I click the read button, by using your above suggestion, it print some annoying(bunch of slashes actually) characters, except the string(letters) on the file.
I appreciate your help all the time...
Eranga
|
|
|
|
|
Eranga Thennakoon wrote: it print some annoying(bunch of slashes actually) characters
Ok. But i just want to ensure that your writing to file is proper. thats why i asked whether you can read the file in the notepad.
Also by the time try setting the tempBuffer as follows. This will set the intial content of the array to 0.
TCHAR tempBuffer[256] = {0};
|
|
|
|
|
Oops, you asking that I can read the text file on my naked eyes. Sure I can, that mean my application write text properly.
At the time you know what is the funny thing. When I use an empty buffer, nothing print on the edit control.
I appreciate your help all the time...
Eranga
|
|
|
|
|
ok i think i got the problem. Update the function by calling the SeekToBegin() as follows
void CSRFToolDlg::OnBnClickedRead()<br />
{<br />
TCHAR tempBuffer[256] ;<br />
UINT readText = 0;<br />
openFile.SeekToBegin();<br />
readText = openFile.Read(tempBuffer, 256 ) ;<br />
SetDlgItemText(IDC_S_READ, tempBuffer ) ;<br />
}
|
|
|
|
|
Seems this is working fine. But one issue is there, if the string length is more than 256 characters. Can I set it to the length of the string which I've already written in the file.
Thanks
I appreciate your help all the time...
Eranga
|
|
|
|
|
ya... Either you can read the full text in one read( this will not be possible is the file is too big. because memeory allocation will fail for big length of data ) or read the text in a loop.
// For reading the complete text in single read
void CSRFToolDlg::OnBnClickedRead()<br />
{<br />
<br />
ULONGLONG nLength = openFile.GetLength();
TCHAR* ptempBuffer = new TCHAR[nLength];<br />
UINT readText = 0;<br />
openFile.SeekToBegin();<br />
readText = openFile.Read(tempBuffer, 256 ) ;<br />
SetDlgItemText(IDC_S_READ, ptempBuffer ) ;<br />
delete[] ptempBuffer;<br />
}
|
|
|
|
|
it seems that, naveen has entered the board means, the problem is solved.
good.
|
|
|
|
|
chandu004 wrote: it seems that, naveen has entered the board means, the problem is solved.
Thanks for the comment. But its not working always
|
|
|
|
|
but i like the way you tackle the problems.
really i appreciate you.
where are you locally from.
ap?
hyderabad?
|
|
|
|
|
No I am from kerala. But currently in Japan. Where r u from?
|
|
|
|
|
iam in hyderabad and working here since 2004.
my platform is vc++ 6.0,
and embedded software development in c.
these days, i have worked in communications and only communications.
|
|
|
|
|
In My Humble Opinion your basic understanding of Read() is incorrect. Read() will always read the number of characters given by the second argument or the total number of characters in the file, whichever is the smaller. What you really want is to do something like this.
CStdioFile fileOpen;
OnBnClickedOpen() can stay the same
void CSRFToolDlg::OnBnClickedWrite()
{
GetDlgItemText(IDC_S_WRITE, readString) ;
if (readString.Right(1) != _T("\n"))
readString += _T("\n");
AfxMessageBox("Data write to the file successfully", MB_OK) ;
openFile.WriteString(readString) ;
}
void CSRFToolDlg::OnBnClickedRead()
{
CString readText;
openFile.ReadString(readText) ;
SetDlgItemText(IDC_S_READ, readText) ;
}
Ohh and there is another potential problem, if you click Open, Write, Read then the result will not be what you expect because the OnBnClickedRead is not returning the filepointer to the start of the file
openFile.SeekToBegin();
you may also nead to call openFile.Flush() to ensure that buffers are flushed to disk before seeking to the begining of the file.
|
|
|
|
|
I have one thing pointed you. First one is the WriteString is not a member of CFile. So?
Actually later I've close the file. Until it is open and wont be issue, I suppose.
I appreciate your help all the time...
Eranga
|
|
|
|
|
ReadString WriteString are members of CStdioFile which is derived from CFile, hence the CStdioFile openFile;
|
|
|
|
|
I have one alternative,
if you are facing problems with CFile, then try the same with FILE *fp.
then i can guide you btter.
BTW, have you forwarded it to me?
|
|
|
|