Hi anyone,

I am trying to write to a file both in the root directory and in the Compact
Flash I get the same problem. Though the file gives me the right amount of
bytes written, only the first character shows in the file. I pasted my
complete code below.

CString fileTestname( "test2.txt" );
CString testMessage( "Coolant Temperature" );
//TCHAR pbuf[20] = _T("Coolant Temperature");

CFile fileObject;

CFileException e;

if( !fileObject.Open( fileTestname, CFile::modeCreate | CFile::modeWrite,
&e ) )
{
AfxMessageBox( TEXT( "Could not open: " )+fileTestname );
} else
{
fileObject.Write( testMessage, testMessage.GetLength() );
}

fileObject.Close();

What am I doing wrong?

Looking forward to your help!
Adolph

Re: writing to a file problem help! using MFC CFile by Michael

Michael
Sat Jan 03 07:32:51 CST 2004

You used TEXT() macro for AfxMessageBox() parameter. And _T macro for
commented out pbuf array.

And surely a compiler warning on the line where you call CFile.Open()?

Use TEXT() macro around the filename parameter. All Windows CE Win32 APIs
take UNICODE string parameters

--

Michael Salamone [eMVP]
Entrek Software, Inc.
www.entrek.com


"Adolph Seema" <ams9331a@rit.edu> wrote in message
news:%23b68L$Y0DHA.3496@TK2MSFTNGP11.phx.gbl...
> Hi anyone,
>
> I am trying to write to a file both in the root directory and in the
Compact
> Flash I get the same problem. Though the file gives me the right amount of
> bytes written, only the first character shows in the file. I pasted my
> complete code below.
>
> CString fileTestname( "test2.txt" );
> CString testMessage( "Coolant Temperature" );
> //TCHAR pbuf[20] = _T("Coolant Temperature");
>
> CFile fileObject;
>
> CFileException e;
>
> if( !fileObject.Open( fileTestname, CFile::modeCreate | CFile::modeWrite,
> &e ) )
> {
> AfxMessageBox( TEXT( "Could not open: " )+fileTestname );
> } else
> {
> fileObject.Write( testMessage, testMessage.GetLength() );
> }
>
> fileObject.Close();
>
> What am I doing wrong?
>
> Looking forward to your help!
> Adolph
>
>



Re: writing to a file problem help! using MFC CFile by Adolph

Adolph
Sat Jan 03 11:21:45 CST 2004

I have adjusted the code as you adviced and I am still having the same
problem. I have pasted the new code below:

CString fileTestname( TEXT("test2.txt") );
CString testMessage( TEXT("Coolant Temperature") );

CFile fileObject;

CFileException e;

if( !fileObject.Open( fileTestname, CFile::modeCreate | CFile::modeWrite,
&e ) )
{
AfxMessageBox( TEXT( "Could not open: " )+fileTestname );
} else
{
fileObject.Write( testMessage, testMessage.GetLength() );
}

fileObject.Close();

looking forward to your help.

Adolph.

"Michael J. Salamone" <mikesa#at#entrek#dot#com> wrote in message
news:vvdh6hjcviq64d@corp.supernews.com...
> You used TEXT() macro for AfxMessageBox() parameter. And _T macro for
> commented out pbuf array.
>
> And surely a compiler warning on the line where you call CFile.Open()?
>
> Use TEXT() macro around the filename parameter. All Windows CE Win32 APIs
> take UNICODE string parameters
>
> --
>
> Michael Salamone [eMVP]
> Entrek Software, Inc.
> www.entrek.com
>
>
> "Adolph Seema" <ams9331a@rit.edu> wrote in message
> news:%23b68L$Y0DHA.3496@TK2MSFTNGP11.phx.gbl...
> > Hi anyone,
> >
> > I am trying to write to a file both in the root directory and in the
> Compact
> > Flash I get the same problem. Though the file gives me the right amount
of
> > bytes written, only the first character shows in the file. I pasted my
> > complete code below.
> >
> > CString fileTestname( "test2.txt" );
> > CString testMessage( "Coolant Temperature" );
> > //TCHAR pbuf[20] = _T("Coolant Temperature");
> >
> > CFile fileObject;
> >
> > CFileException e;
> >
> > if( !fileObject.Open( fileTestname, CFile::modeCreate |
CFile::modeWrite,
> > &e ) )
> > {
> > AfxMessageBox( TEXT( "Could not open: " )+fileTestname );
> > } else
> > {
> > fileObject.Write( testMessage, testMessage.GetLength() );
> > }
> >
> > fileObject.Close();
> >
> > What am I doing wrong?
> >
> > Looking forward to your help!
> > Adolph
> >
> >
>
>



Re: writing to a file problem help! using MFC CFile by r_z_aret

r_z_aret
Sat Jan 03 15:22:44 CST 2004

On Fri, 2 Jan 2004 19:23:20 -0500, "Adolph Seema" <ams9331a@rit.edu>
wrote:

>Hi anyone,
>
>I am trying to write to a file both in the root directory and in the Compact
>Flash I get the same problem. Though the file gives me the right amount of
>bytes written, only the first character shows in the file. I pasted my
>complete code below.
>
> CString fileTestname( "test2.txt" );
> CString testMessage( "Coolant Temperature" );
> //TCHAR pbuf[20] = _T("Coolant Temperature");
>
> CFile fileObject;
>
> CFileException e;
>
> if( !fileObject.Open( fileTestname, CFile::modeCreate | CFile::modeWrite,
>&e ) )
> {
> AfxMessageBox( TEXT( "Could not open: " )+fileTestname );
> } else
> {
> fileObject.Write( testMessage, testMessage.GetLength() );

I don't use MFC, so I may be off here.

I _think_ you wrote UNICODE text to the file. You would be able to
read that with at least some programs, but only if you put the
appropriate BOM (Byte Order Marker) at the beginning of the file to
let programs know how to read the file (to indicate that it is a
UNICODE file and to indicate whether it is "big endian" or "little
endian"). So, one solution is to write the appropriate BOM to each
file when you create it. For more info you might look at my 2 Jun 03
contribution to a thread called "File formats from PPC to Windows " in
microsoft.public.pocketpc.developer. If that isn't sufficient, I
recommend google (http://groups.google.com/advanced_group_search).

I actually suggest an alternate approach: translate the text to ASCI
before writing it. This is the method I used for several years, before
I knew about the BOM. I know I've seen questions about translating
CString to ASCII asked and answered, but I don't remember the answer.
I just used google to look up
cstring ascii
in microsoft.public.pocketpc.developer and got 43 hits. I'm pretty
sure at least one of them will be helpful. If not, tweaking the search
parameters should succeed quickly.

> }
>
> fileObject.Close();
>
>What am I doing wrong?
>
>Looking forward to your help!
>Adolph
>
>

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com

Re: (SOLVED) writing to a file problem help! using MFC CFile by Adolph

Adolph
Sat Jan 03 20:39:13 CST 2004

Thanks a lot! I have used the C style of writing files and I am converting
CString to char *.

Adolph.

<r_z_aret@pen_fact.com> wrote in message
news:3ff729f0.113660495@nntp.theworld.com...
> On Fri, 2 Jan 2004 19:23:20 -0500, "Adolph Seema" <ams9331a@rit.edu>
> wrote:
>
> >Hi anyone,
> >
> >I am trying to write to a file both in the root directory and in the
CompactT
> >Flash I get the same problem. Though the file gives me the right amount
of
> >bytes written, only the first character shows in the file. I pasted my
> >complete code below.
> >
> > CString fileTestname( "test2.txt" );
> > CString testMessage( "Coolant Temperature" );
> > //TCHAR pbuf[20] = _T("Coolant Temperature");
> >
> > CFile fileObject;
> >
> > CFileException e;
> >
> > if( !fileObject.Open( fileTestname, CFile::modeCreate |
CFile::modeWrite,
> >&e ) )
> > {
> > AfxMessageBox( TEXT( "Could not open: " )+fileTestname );
> > } else
> > {
> > fileObject.Write( testMessage, testMessage.GetLength() );
>
> I don't use MFC, so I may be off here.
>
> I _think_ you wrote UNICODE text to the file. You would be able to
> read that with at least some programs, but only if you put the
> appropriate BOM (Byte Order Marker) at the beginning of the file to
> let programs know how to read the file (to indicate that it is a
> UNICODE file and to indicate whether it is "big endian" or "little
> endian"). So, one solution is to write the appropriate BOM to each
> file when you create it. For more info you might look at my 2 Jun 03
> contribution to a thread called "File formats from PPC to Windows " in
> microsoft.public.pocketpc.developer. If that isn't sufficient, I
> recommend google (http://groups.google.com/advanced_group_search).
>
> I actually suggest an alternate approach: translate the text to ASCI
> before writing it. This is the method I used for several years, before
> I knew about the BOM. I know I've seen questions about translating
> CString to ASCII asked and answered, but I don't remember the answer.
> I just used google to look up
> cstring ascii
> in microsoft.public.pocketpc.developer and got 43 hits. I'm pretty
> sure at least one of them will be helpful. If not, tweaking the search
> parameters should succeed quickly.
>
> > }
> >
> > fileObject.Close();
> >
> >What am I doing wrong?
> >
> >Looking forward to your help!
> >Adolph
> >
> >
>
> -----------------------------------------
> To reply to me, remove the underscores (_) from my email address (and
please indicate which newsgroup and message).
>
> Robert E. Zaret
> PenFact, Inc.
> 500 Harrison Ave., Suite 3R
> Boston, MA 02118
> www.penfact.com