Read and Write Files



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

.



Relevant Pages

  • Re: How to edit a large xml file (250MB)?
    ... I also have no access to editor which exported mentioned xml file. ... inserting and deleting some lines of text; writing something)" is very fast. ...
    (comp.text.xml)
  • Re: ultra newbie question (dont laugh)
    ... storing employee information in an XML file. ... but not as fun as writing the logic. ... Is OOP necessary here? ... Perhaps I should just take some kind of programming intro class! ...
    (comp.lang.python)
  • ultra newbie question (dont laugh)
    ... I've decided to make a little project for myself which involves storing employee information in an XML file. ... I also plan to make a GUI frontend with wxPython for entering the records. ... For now I've decided to focus just on writing the logic, and not worry about the GUI yet. ... Would utility functions work just as well for simply writing the information to a file? ...
    (comp.lang.python)
  • Re: Saving to files - XML - C#
    ... This link has an example of writing out an XML file. ... > I have several windows which contain settings for an embedded target. ... > created an INI type file, but now we want to do XML. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: IIS and Ldap (Linux/Novell)
    ... I think this is about as close as you can get without writing your own ISAPI ...
    (microsoft.public.inetserver.iis)

Loading