Read and Write Files
- From: Kniffel <kern@xxxxxxxxxxxxxxxx>
- Date: Fri, 20 Jul 2007 01:25:31 -0700
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
.
- Follow-Ups:
- Re: Read and Write Files
- From: Paul Monson
- Re: Read and Write Files
- Prev by Date: ras connection nitialization string
- Next by Date: Re: Read and Write Files
- Previous by thread: ras connection nitialization string
- Next by thread: Re: Read and Write Files
- Index(es):
Relevant Pages
|
Loading