|
no problem sir, i found your ctokenizer in your source file from CDiagramEditor article a little useful function that cstring didn't have
and, after i put the content of file into cstring, replace, then parse the result,problem solved !!.. finally i can use it in my pocket pc code.
Thank you for your guide and your usefull class
|
|
|
|
|
riki_risnandar wrote:
Thank you for your guide and your usefull class
And thank you for your feedback!
|
|
|
|
|
I'm trying too use it for Pocket PC but I have the next problem:
What I'm doing bad?
I did: Project --> Add to Project --> Files
and I selected the two files: (textfile.h & textfile.cpp) that I had copied to my project's directory!
--------------------Configuration: testingsqlite - Win32 (WCE ARMV4) Release--------------------
Compiling...
TextFile.cpp
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(10) : error C2629: unexpected 'class CTextFile ('
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(10) : error C2238: unexpected token(s) preceding ';'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(16) : error C2061: syntax error : identifier 'CString'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(17) : error C2061: syntax error : identifier 'CString'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(17) : error C2535: 'int __cdecl CTextFile::ReadTextFile(void)' : member function already defined or declared
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(16) : see declaration of 'ReadTextFile'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(19) : error C2061: syntax error : identifier 'CString'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(20) : error C2061: syntax error : identifier 'CString'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(20) : error C2535: 'int __cdecl CTextFile::WriteTextFile(void)' : member function already defined or declared
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(19) : see declaration of 'WriteTextFile'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(22) : error C2061: syntax error : identifier 'CString'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(23) : error C2061: syntax error : identifier 'CString'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(23) : error C2535: 'int __cdecl CTextFile::AppendFile(void)' : member function already defined or declared
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(22) : see declaration of 'AppendFile'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(26) : error C2061: syntax error : identifier 'CString'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(27) : error C2061: syntax error : identifier 'CString'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(27) : error C2535: 'int __cdecl CTextFile::Load(void)' : member function already defined or declared
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(26) : see declaration of 'Load'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(28) : error C2061: syntax error : identifier 'CString'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(29) : error C2061: syntax error : identifier 'CString'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(29) : error C2535: 'int __cdecl CTextFile::Save(void)' : member function already defined or declared
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(28) : see declaration of 'Save'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(32) : error C2146: syntax error : missing ';' before identifier 'GetErrorMessage'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(32) : error C2501: 'CString' : missing storage-class or type specifiers
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(36) : error C2061: syntax error : identifier 'CString'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(37) : error C2146: syntax error : missing ';' before identifier 'GetExtension'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(37) : error C2501: 'CString' : missing storage-class or type specifiers
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(41) : error C2146: syntax error : missing ';' before identifier 'm_error'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(41) : error C2501: 'CString' : missing storage-class or type specifiers
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(41) : error C2501: 'm_error' : missing storage-class or type specifiers
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(42) : error C2146: syntax error : missing ';' before identifier 'm_extension'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(42) : error C2501: 'CString' : missing storage-class or type specifiers
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(42) : error C2501: 'm_extension' : missing storage-class or type specifiers
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(43) : error C2146: syntax error : missing ';' before identifier 'm_eol'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(43) : error C2501: 'CString' : missing storage-class or type specifiers
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(43) : error C2501: 'm_eol' : missing storage-class or type specifiers
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(46) : error C2061: syntax error : identifier 'CWnd'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(30) : error C2143: syntax error : missing ',' before '&'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(30) : error C2059: syntax error : '&'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(44) : error C2511: 'CTextFile::CTextFile' : overloaded member function 'void (const int)' not found in 'CTextFile'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.h(5) : see declaration of 'CTextFile'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(67) : error C2065: 'CString' : undeclared identifier
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(67) : error C2065: 'filename' : undeclared identifier
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(67) : error C2065: 'CStringArray' : undeclared identifier
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(67) : error C2065: 'contents' : undeclared identifier
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(87) : error C2448: '<unknown>' : function-style initializer appears to be a function definition
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(146) : error C2448: '<unknown>' : function-style initializer appears to be a function definition
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(190) : error C2059: syntax error : 'const'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(211) : error C2143: syntax error : missing ';' before '{'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(211) : error C2447: missing function header (old-style formal list?)
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(252) : error C2059: syntax error : 'const'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(271) : error C2143: syntax error : missing ';' before '{'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(271) : error C2447: missing function header (old-style formal list?)
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(309) : error C2059: syntax error : 'const'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(327) : error C2143: syntax error : missing ';' before '{'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(327) : error C2447: missing function header (old-style formal list?)
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(363) : error C2059: syntax error : 'const'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(381) : error C2143: syntax error : missing ';' before '{'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(381) : error C2447: missing function header (old-style formal list?)
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(425) : error C2065: 'CEdit' : undeclared identifier
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(425) : error C2065: 'edit' : undeclared identifier
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(444) : error C2448: '<unknown>' : function-style initializer appears to be a function definition
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(464) : error C2065: 'CListBox' : undeclared identifier
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(464) : error C2065: 'list' : undeclared identifier
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(482) : error C2448: '<unknown>' : function-style initializer appears to be a function definition
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(532) : error C2448: '<unknown>' : function-style initializer appears to be a function definition
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(574) : error C2448: '<unknown>' : function-style initializer appears to be a function definition
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(607) : error C2143: syntax error : missing ';' before 'tag::id'
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(607) : error C2501: 'CString' : missing storage-class or type specifiers
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\textfile.cpp(607) : fatal error C1004: unexpected end of file found
Error executing clarm.exe.
TextFile.obj - 64 error(s), 0 warning(s)
Aaron Planell
aaronpl@ya.com
|
|
|
|
|
It is only the first error that is interesting, getting rid of that will get rid of the rest
C2629 means a syntax error. Now, we know that the code *almost* works on Pocket PC (of which I have far to little knowledge, I'm sorry to say), so I would advice checking if the rest of the project compiles without these files, so as to rule out syntax errors in code outside the class.
If that works, you might want to add back the header file (and include it in some implementation file), but comment out the stuff inside the class brackets.
We are only interested in getting through the compile at this stage - never mind about linking!
Finally, start "un-commenting-out" function by function until you find the problematic declaration. If it so happens that you unveil a problem that should be fixed in the next update of the class, please post that info, so that the all and every person who might want to use this class in Pocket PC don't have to reinvent the wheel!
Note from the posts of the previous poster in this thread that you will have to do further modifications to the implementation as well.
|
|
|
|
|
well, theres a lot of differences between pocket pc and desktop, because there's some visual c++ function that do not exist in pocket pc.
i made slight modification with guide from Mr.Rosengren.
CTokenize can be found at another Mr.Rosengren article here in codeproject.
this is the modification i made to the function, the contents of file will be loaded into the 'contents' array:
BOOL CTextFile::ReadTextFile( CString& filename, CStringArray& contents, BOOL m_vbIsUnicode )
{
if(m_vbIsUnicode)
{
// OPEN UNICODE FILE
ClearError();
BOOL result = TRUE;
if( filename.IsEmpty() )
result = GetFilename( FALSE, filename );
if( result )
{
CStdioFile file;
CFileException feError;
if( file.Open( filename, CFile::modeRead, &feError ) )
{
contents.RemoveAll();
CString sBaris;
ULONGLONG dwLength = file.GetLength();
int icount=0;
TCHAR buffer[4096];
DWORD dwRead;
// looping until end of file
do
{
dwRead = file.Read(buffer, 4096);
sBaris += buffer;
} while (dwRead > 0);
sBaris.Delete(0);
sBaris.Replace(_T("\r\n"),_T("\n"));
sBaris.Replace(_T("\x1000"),_T("\x0000"));
// separate between lines then add to array
CTokenizer SmsWithToken(sBaris,_T("\n")); for( int y=0;y < SmsWithToken.GetSize(); y++ )
{
CString sToken;
SmsWithToken.GetAt(y,sToken);
sToken.TrimLeft();sToken.TrimRight();
if(sToken.GetLength() == 0) continue;
contents.Add(sToken);
}
file.Close();
} else {
TCHAR errBuff[256];
feError.GetErrorMessage( errBuff, 256 );
m_error = errBuff;
result = FALSE;
}
}
return result;
} else {
// OPEN ASCII FILE
DWORD dwBytesWritten = 0, dwFileSize;
TCHAR* pszUnicodeBuff;
CHAR* pszFileBuff = 0;
HANDLE hAsciiFile;
hAsciiFile = CreateFile( filename,
GENERIC_READ ,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
//get file length
dwFileSize = GetFileSize( hAsciiFile, NULL );
//allocate a buffer for the script file
pszFileBuff = (char*)LocalAlloc( LPTR, dwFileSize );
if( !pszFileBuff )
{
AfxMessageBox(_T("Couldn't Allocate Memory"));
}
//read the file
ReadFile( hAsciiFile,(LPVOID)pszFileBuff, dwFileSize, &dwBytesWritten, NULL);
//allocate a translation buffer
pszUnicodeBuff = (TCHAR*)LocalAlloc( LPTR,
sizeof(TCHAR)*( dwFileSize + 1 ));
//translate to unicode
mbstowcs( pszUnicodeBuff, (const char *)pszFileBuff,
(size_t)strlen(pszFileBuff) );
contents.RemoveAll();
CString sBaris = pszUnicodeBuff;
int icount=0;
sBaris.Delete(0); // delete the unicode header
sBaris.Replace(_T("\r\n"),_T("\n"));
sBaris.Replace(_T("\x1000"),_T("\x0000"));
// separate between lines
CTokenizer SmsWithToken(sBaris,_T("\n"));
for( int y=0;y < SmsWithToken.GetSize(); y++ )
{
CString sToken;
SmsWithToken.GetAt(y,sToken);
if(sToken.GetLength() == 0) continue;
contents.Add(sToken);
}
//release translation buffer
LocalFree(pszUnicodeBuff);
//release file buffer
LocalFree(pszFileBuff);
//close the file
CloseHandle(hAsciiFile);
//it's all good
return TRUE;
}
}
i'm using embedded visual c++ 4.0 with sp.3
* This is the signature *
|
|
|
|
|
Hi!
First: Johan. The project compile perfectly without the CTextFile. There's no error and i know that the sqlite database was opened correctly.
I use the Wrapper CppSQLite and there's no problem.
Linking...
Creating library ARMV4Rel/sqlite.lib and object ARMV4Rel/sqlite.exp
--------------------Configuration: testingsqlite - Win32 (WCE ARMV4) Release--------------------
Compiling resources...
Compiling...
StdAfx.cpp
Compiling...
CppSQLite3.cpp
CrearDocumentos.cpp
testingsqlite.cpp
Generating Code...
Linking...
proyecto1.exe - 0 error(s), 0 warning(s)
Downloading files
Failed downloading. // I didn't have connected the Pocket PC in this moment.
Second: Riki. I download the class CTokenizer. I included this files and...
Tachan!
c:\archivos de programa\microsoft visual studio\myprojects\testingsqlite\tokenizer.h(23) : error C2629: unexpected 'class CTokenizer ('
The same problem! (Maybe codeproject has specials downloads for me, jejeje).
Third: What I'm trying. Let me explain you!
This is a piece of my code:
//I Create a file called myFile1.txt and I write inside:
//"Hi. I'm Testing SQLite!!!"
CStdioFile myFile1;
int MaxSizeBuffer=25;
myFile1.Open(_T("\\My Documents\\Proyecto\\myFile1.txt"),
CFile::modeCreate | CFile::modeWrite);
char *buffer="Hi. I'm Testing SQLite!!!";
myFile1.Write(buffer, MaxSizeBuffer* sizeof(TCHAR));
myFile1.Close();
//The file size is 50 (25*2), and inside I found the text...
//Perfect!
//Let's do the same with CString's!!!!!!!!!!!
//I Create a file called myFile2.txt and I write inside:
//"Number of Items: 398"
int numberItems = 398;
CStdioFile myFile2;
myFile2.Open(_T("\\My Documents\\Proyecto\\myFile2.txt"),
CFile::modeCreate | CFile::modeWrite);
CString sCantidadArticulos;
sCantidadArticulos.Format(_T("Number of Items: %d\n"), numberItems);
myFile2.Write(sCantidadArticulos, sCantidadArticulos.GetLength()* sizeof(TCHAR));
myFile2.Close();
//The file size is 42 (21*2), and inside I found the text...
//Oooooops!
//I ONLY FIND A "N"!!!!!!
And that's the problem. I need to write all the string, not only the first letter.
Fourth: Thanks a lot for your attention and I apologize my level of english.
Aaron Planell
aaronpl@ya.com
|
|
|
|
|
Running UNICODE, you might want to check the thread above.
|
|
|
|
|
well, ctokenizer is a small class that doesnt exist in mobile environment and it works for me. actually this 'mobile' conversation is out of context of this article so i sent u the function to write unicode file in windowsmobile to your email its a long code
|
|
|
|
|
¡¡¡¡¡¡¡¡¡THANKS A LOT!!!!!!!!!!!!!!
I wrote it like a new function called CrearDocumentos::WriteTextFile inside my main class and now it's written with out problem!!!!
I only have two questions:
- Where can I find the method GetFilename?
- Why the Unicode don't write me end lines (I'm pretending use \n and they don't appear in my log file)
For example:
SYSTEMTIME mySystemTime;<br />
GetSystemTime(&mySystemTime);<br />
<br />
CString sLog;<br />
sLog.Format(_T("\\My Documents\\Proyecto\\log.txt")); CString sTime;<br />
sTime.Format(_T("Fecha: %d-%d-%d Hora:%d:%d:%d\n"),
mySystemTime.wDay, mySystemTime.wMonth, mySystemTime.wYear,<br />
mySystemTime.wHour, mySystemTime.wMinute, mySystemTime.wSecond); WriteTextFile(sLog, sTime, false);<br />
<br />
CString sCantidadArticulos;<br />
sCantidadArticulos.Format(_T("Cantidad de Articulos: %d\n"), CantidadArticulos);
<br />
WriteTextFile(sLog, sCantidadArticulos, true); ...etc.
When I open the file log.txt in Pocket Word I found:
Fecha: 26-11-2004 Hora:12:57:9Cantidad de Articulos: 398
But when I do the same opening it with UltraEdit in my desktop:
1) Ultraedit ask me if I want to convert the file to DOS Format.
2) When I click yes I found:
Fecha: 26-11-2004 Hora:12:57:9
Cantidad de Articulos: 398
---------------------------------->
Thanks a lot for your assistance!
I hope you don't mind that I will write that you help me in my project.
I will inscribe you in my greetings.
Aaron Planell
aaronpl@ya.com
|
|
|
|
|
Edipo wrote:
- Where can I find the method GetFilename?
It is one of the class functions in TextFile.cpp
Edipo wrote:
- Why the Unicode don't write me end lines (I'm pretending use \n and they don't appear in my log file)
There are two kinds of text files under Windows, "DOS"-style and "Unix"-style files. Each line for the DOS-type end with a carriage return and a line feed, that is "\r\n". Unix-type files end lines with just a line-feed, "\n". So, try to use "\r\n" instead of only "\n".
Edipo wrote:
I hope you don't mind that I will write that you help me in my project.
I will inscribe you in my greetings.
You don't have to
|
|
|
|
|
Thanks for the assistance!
|
|
|
|
|
It's really fantastic. I like it so much. I have trouble to read and save a text file. This class help me so much. I can use it really easy. Thanks u! 5/5
LonelyStar
|
|
|
|
|
Hye,
which is the low-level function that checks whether the file exist or not??? I don't want to open the file as it will be used frequently...
Any idea??
Jigar Mehta
(jigarmehta@gatescorp.com)
Software Developer
Gates Information Systems
|
|
|
|
|
::FindFirstFile(Ex) and friends are probably what you are looking for. You might also want to try ::GetFileAttributes and consider an error as the file not existing.
|
|
|
|
|
A bit late but thought you still might want to know:
if (PathFileExists(pszFilePath))
PathFileExists belongs to shlwapi.lib, there are severall Path* functions which are very usefull to basic files checking.
Yarp
http://www.senosoft.com/
|
|
|
|
|
I like what you've done here, it's exactly what I set out to find when I started searching, and, I would have used your class except that I just happened to stumble onto CStdioFile.
--
FireBox @ Synetech
|
|
|
|
|
If you read the source code, you'll notice that it actually uses CStdioFile. The initial reason to write this small class was the tiresom repetition of the CStdioFile declaration and read loop.
|
|
|
|
|
Yes, I noticed that it does not require using a persistent file variable. I have not needed such a thing yet but I'm sure it can be handy sometimes. It's worth putting in the class cache.
--
FireBox @ Synetech
|
|
|
|
|
You are more than welcome
|
|
|
|
|
|
As it uses CStrings and CStringArrays, this should be automatic if you create a UNICODE project. I've noticed, however, that one of the string constants (the setting of m_error in ValidParam) is not casted with _T.
|
|
|
|
|
> History
> 2004/04/22 - Initial version.
Whoa, timewarp
|
|
|
|
|
We computer people are supposed to live in the future, aren't we?
Although the gaps is reduced
|
|
|
|
|
... thanks
C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg
|
|
|
|
|
I love your sig
|
|
|
|
|