x
This website is using cookies. We use cookies to ensure that we give you the best experience on our website. More info. That's Fine
HPC:Factor Logo 
 
Latest Forum Activity

Text File generation using MFC in WinCE 6.0

1 2
anurag.kela@gmail.co Page Icon Posted 2012-11-29 4:59 AM
#
Avatar image of anurag.kela@gmail.co
H/PC Newbie

Posts:
24
Location:
India
Status:
Hello Everyone,

I am working on an Application using MFC for WinCE 6.0 Platform. I want to generate a text file on a Button event. When I press button a file is generated but its not the text file. I checked the properties of the file and in attributes its archive. When I manually rename the file then all the data which i have written in the file remains unchanged.
Can anybody please suggest me that where mam I going wrong?

Edited by anurag.kela@gmail.co 2012-11-29 5:00 AM
 Top of the page
C:Amie Page Icon Posted 2012-11-29 9:30 AM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
17,976
Location:
United Kingdom
Status:
Hi Anurag, welcome to the site.

Unfortunately I am not fully understanding your problem. Can you explain it a little further (perhaps provide a source code sample).

If a file is being generated with the correct information in it, are you simply missing the .txt off of the binary writer's save path?
 Top of the page
anurag.kela@gmail.co Page Icon Posted 2012-12-01 11:42 AM
#
Avatar image of anurag.kela@gmail.co
H/PC Newbie

Posts:
24
Location:
India
Status:
Thanks Amie...

N yes, the File is created at correct Location but the file format is unknown. When i manually rename the file the data remains unaffected. the prob is with File Creation.

Here's my File creation Code.
 
void CFormRight :: OnBnClickedButtonTextfile()
{
CFile File;
char cFileAddr[100] = {"My Device\\Label.txt"};
File.Open((LPCTSTR)cFileAddr, CFile::modeCreate | CFile::typeBinary |CFile::modeWrite | CFile::shareDenyNone);
File.Close();
}

Edited by anurag.kela@gmail.co 2012-12-01 11:42 AM
 Top of the page
C:Amie Page Icon Posted 2012-12-01 12:22 PM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
17,976
Location:
United Kingdom
Status:
It's "C:Amie"

"(LPCTSTR)cFileAddr" You cannot cast from ASCII to unicode like this. Try:

wchar_t cFileAddr[100] = TEXT("My Device\\Label.txt"); 
File.Open(cFileAddr, CFile::modeCreate | CFile::typeBinary | CFile::modeWrite | CFile::shareDenyNone);
 Top of the page
Rich Hawley Page Icon Posted 2012-12-01 1:31 PM
#
Avatar image of Rich Hawley
Global Moderator
H/PC Guru

Posts:
7,188
Location:
USA
Status:
It's only Amie when he is dressing in drag
 Top of the page
C:Amie Page Icon Posted 2012-12-01 3:07 PM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
17,976
Location:
United Kingdom
Status:
Tuesday's and Thursday's in otherwords
 Top of the page
anurag.kela@gmail.co Page Icon Posted 2012-12-03 5:13 AM
#
Avatar image of anurag.kela@gmail.co
H/PC Newbie

Posts:
24
Location:
India
Status:
Amie, I tried the way u said what when i click on Generate text file button, it gives a Debug Assertion Problem in CFile::Write Function

I tried to debug and it pointed at ASSERT(m_hFile != INVALID_HANDLE_VALUE) {(in Filecore.cpp)}.
There's no compile time error.
 Top of the page
C:Amie Page Icon Posted 2012-12-03 9:46 AM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
17,976
Location:
United Kingdom
Status:
Wait a minute, your Windows CE explorer settings aren't hiding file types are they? ( #5 http://www.hpcfactor.com/support/cesd/s/0006.asp )
 Top of the page
anurag.kela@gmail.co Page Icon Posted 2012-12-03 11:17 AM
#
Avatar image of anurag.kela@gmail.co
H/PC Newbie

Posts:
24
Location:
India
Status:
Hey Amie i didn't get you. I am new to this Win CE Platform. I have never done any changes with the O.S.? Please help me out.
 Top of the page
anurag.kela@gmail.co Page Icon Posted 2012-12-03 11:22 AM
#
Avatar image of anurag.kela@gmail.co
H/PC Newbie

Posts:
24
Location:
India
Status:
Yes i have changed that but still file extension is not known???
 Top of the page
anurag.kela@gmail.co Page Icon Posted 2012-12-03 11:24 AM
#
Avatar image of anurag.kela@gmail.co
H/PC Newbie

Posts:
24
Location:
India
Status:
Still the same assertion Problem...
 Top of the page
anurag.kela@gmail.co Page Icon Posted 2012-12-04 3:56 AM
#
Avatar image of anurag.kela@gmail.co
H/PC Newbie

Posts:
24
Location:
India
Status:
Hey Amie, My problem is solved..
the wchar_t worked. i wasn't doing it correctly...
Thanks a ton for all your support.
 Top of the page
anurag.kela@gmail.co Page Icon Posted 2012-12-04 5:38 AM
#
Avatar image of anurag.kela@gmail.co
H/PC Newbie

Posts:
24
Location:
India
Status:
Hey Amie, hi its me again...
I have a edit box in my app and the data in the edit box is in CString Object and i want to copy the edit box data in a char buffer. How to do that? There's again Unicode and Multibyte prob i guess bcoz if i write the CString object directly to my txt file there's some prob in that.
 Top of the page
C:Amie Page Icon Posted 2012-12-04 8:53 AM
#
Avatar image of C:Amie
Administrator
H/PC Oracle

Posts:
17,976
Location:
United Kingdom
Status:
Anurag,

Please post back a copy of the working code so that it can help other users in the future :)

So you want to copy the contents of a multi-line text box into a char buffer? The text box should already be a wstr construct and according to the MFC API CFile::Write looks for a lpchar[]. What happens if you perform a neat cast? (char *)

If that doesn't behave try

CString theString(_T("This is a test"));
int sizeOfString = (theString.GetLength() + 1);
LPTSTR lpsz = new TCHAR[sizeOfString];
_tcscpy_s(lpsz, sizeOfString, theString);


a la http://msdn.microsoft.com/en-us/library/awkwbzyc.aspx#_core_convert...
 Top of the page
anurag.kela@gmail.co Page Icon Posted 2012-12-05 4:17 AM
#
Avatar image of anurag.kela@gmail.co
H/PC Newbie

Posts:
24
Location:
India
Status:
Thanks for your quick response Amie.....
But i solved it in a different way...

Here's my code.

 
m_TextBuffer.GetWindowTextW(szBuffer); 
wchar_t *ptr = szBuffer.GetBuffer(szBuffer.GetLength());
int nLen1 = szBuffer.GetLength();
int nLen2 = strlen(cTextBuffer);

for( j = 0; j < nLen1; j++ )
{
cTextBuffer[nLen2 + i] = *(ptr + j);
i++;
}


szBuffer is the CString Object.
m_TextBuffer is the Edit Box Variable
cTextBuffer is the Char Array in which string is to be copied.

Edited by anurag.kela@gmail.co 2012-12-05 4:24 AM
 Top of the page
1 2
Jump to forum:
Seconds to generate: 0.203 - Cached queries : 72 - Executed queries : 9