|
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
|
|
|
|
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? |
|
|
|
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
|
|
|
|
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); |
|
|
|
Global Moderator H/PC Guru Posts: | 7,188 |
Location: | USA | Status: | |
| It's only Amie when he is dressing in drag |
|
|
|
Administrator H/PC Oracle Posts: | 17,976 |
Location: | United Kingdom | Status: | |
| Tuesday's and Thursday's in otherwords |
|
|
|
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. |
|
|
|
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 ) |
|
|
|
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. |
|
|
|
H/PC Newbie Posts: | 24 |
Location: | India | Status: | |
| Yes i have changed that but still file extension is not known??? |
|
|
|
H/PC Newbie Posts: | 24 |
Location: | India | Status: | |
| Still the same assertion Problem... |
|
|
|
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. |
|
|
|
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. |
|
|
|
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... |
|
|
|
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
|
|
|