Re: Read and Write Files
- From: Paul Monson <paulm@xxxxxxxxxx>
- Date: Fri, 20 Jul 2007 06:52:06 -0700
For the unix vs dos format problem, I believe you need to \r\n at the end of lines in DOS files. Many editors identify files that only have \n at the end of files a unix files. Writefile doesn't fix up the line endings at all it writes the literal character.
For the ReadFile question, the TCHAR always maps to WCHAR on CE. If your files is UTF-8 or ascii, I think you want to change the TCHAR to a CHAR and use fgets instead of fgetws.
Paul Monson
Intrinsyc
Kniffel wrote:
Hi everyone.
I am writing an ISAPI extension for the Windows CE Webserver.
I use "embedded Visual C++ 4.0".
So far it works, but now I try to write and read files in the ISAPI.
And I get some problems, because of Unicode and so. But I am not
familiar enough to get it to work.
WRITE A FILE:
----------------------
I have a XML file, and I transform it with a XSL to a HTML Form inside
the ISAPI, when I send the Form I write the XML file with "WriteFile"
from the WinAPI. After writing the XML file, the XML/XSL
transformation is not possible anymore! No HTML Form is showing up on
the website...
CODE:
----------
#define MAX 2048;
HANDLE hFile;
DWORD wmWritten;
char FileData[MAX] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n
<SOMETAGS>\n </SOMETAGS>\n ";
hFile = CreateFileW(reinterpret_cast<const unsigned short *>(L"\\PATH\
\file.xml"), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
WriteFile(hFile,FileData,(DWORD)(sizeof(FileData)),&wmWritten,NULL);
CloseHandle(hFile);
When I open the new XML file on the desktop PC in a Texteditor, it
shows me that the file is in Unix Format, but it is UTF-8(Unicode)!
Perhaps there is a problem with the size of MAX, I define it great
enough, because I have to define the size at a moment I do not know
the size, because I append strings to FileData with "strncat". And the
strings have different length everytime I write.
Can I write so that it is not in Unix, but in DOS format?
Whats with the MAX definition, could it cause problems writing a file
with 2kb, only containg content around 1kb?
READ A FILE
--------------------
My second problem is to read files... I tryed to ways: ReadFile and
fgetws
FILE *stream;
TCHAR line[MAX_PATH];
if( (stream = fopen( "\\PATH\\test.xml", "r" )) != NULL )
{
if( fgetws( line, 300, stream ) == NULL)
printf( "fgets error\n" );
else
{
DWORD ReadArrayLen;
WCHAR ReadArrayValue;
ReadArrayLen = sizeof(&line) - 1;
pECB->WriteClient(pECB->ConnID,(LPVOID)line, &ReadArrayLen, 0);
}
fclose( stream );
}
OR with CreateFile
----------------------------
hFile = CreateFile(reinterpret_cast<const unsigned short *>(L"\\NOR
Flash\\http\\test.xml"), GENERIC_READ, FILE_SHARE_READ, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
bTest= ReadFile(hFile, dwBuffer, sizeof(DWORD)*256, &dwNumRead,NULL);
bTest=CloseHandle(hFile);
Both variants are showing some non-readable characters on the
websites!?
Somebody can help me getting the file to read and to write? Some
needful links or advises?
Thanks
Thomas
- References:
- Read and Write Files
- From: Kniffel
- Read and Write Files
- Prev by Date: Read and Write Files
- Next by Date: Slow heap manager in Win-CE6.0 ?
- Previous by thread: Read and Write Files
- Next by thread: Slow heap manager in Win-CE6.0 ?
- Index(es):
Relevant Pages
|