i need to write information to a file here is the code im using.
    mov hFile1, eax
    invoke SetFilePointer,hFile1,0,NULL,FILE_BEGIN
    invoke WriteFile,hFile1,addr OpenText,sizeof OpenText,addr bRead,NULL
    invoke SetEndOfFile,hFile1
the problem is that this code is process when one of my buttons is clicked and it writes to the my file if i press it once but it appears to keep overwriting the same line when pressed multiple times. so basically ive been only able to write one line of text to a file. so how do i make it so it doesnt overwrite existing text and places new text in instead? smurf
Posted on 2001-06-20 07:46:00 by smurf
hi smurf, to use flag TRUNCATE_EXISTING will always "clear" the content of your file. If you do not want that, better use OPEN_EXISTING instead. If you want to write a "log file", that is to write at the end of your existing file, use invoke SetFilePointer,hFile1,0,NULL,FILE_END And I think, the statement invoke SetEndOfFile,hFile1 is not needed japheth :)
Posted on 2001-06-20 08:01:00 by japheth
japheth i changed the code around like you said but it still didnt work. so how can i make it not overwrite the existing line but create a new one? thanks smurf
Posted on 2001-06-21 02:50:00 by smurf
Use OPEN_EXISTING instead of TRUNCATE_EXISTING. Don't forget to close the file handle after you write a line. But it's more efficient to store several lines in a buffer and write them when the buffer is full.
Posted on 2001-06-21 03:00:00 by karim
hi karim. the probelm i have now is that it doesnt goto the next line the new text is written to the same line. how do i make is make a new line to write to? here is my code:
    mov hFile1, eax
    invoke SetFilePointer,hFile1,NULL,NULL,FILE_END
    invoke WriteFile,hFile1,addr EditText,sizeof EditText,addr bRead,NULL
    invoke CloseHandle,hFile1
thanks smurf
Posted on 2001-06-21 03:56:00 by smurf
Hi smurf, if I got you right then your problem is to "simulate" the pressing of return-key in order to place the CD/LF into the file. Right? Okay, then you just need to do this:

NeueZeile               db 0Dh,0Ah

INVOKE WriteFile,hFile1,addr NeueZeile,2,addr bRead,NULL
Just do this after you wrote your line and voilá you are/should be in the next line. I hope there is nothing wrong with the code in here (the server was busy so I just hurried to write). Stefan P.S. I never really understood what this "addr bRead" is for. Can someone please explain this?
Posted on 2001-06-21 04:19:00 by Stefan Krause
thanks Stefan that worked great. smurf
Posted on 2001-06-21 04:32:00 by smurf
now on to my next problem. my file is loading into a listview and when i delete a string from my listview i need the same string to be deleted from my file. how would I go about deleting a specific string in my file? any ideas? thanks smurf This message was edited by smurf, on 6/21/2001 5:39:12 AM
Posted on 2001-06-21 05:38:00 by smurf
Hi smurf, seems to me that we are kind of working into the same direction. I created an editor for my guestbook database some days ago and it does exactly what you need. I must admit that the saving, deleting of the file is not at runtime but it saves on click. Maybe it is not the best way it is done but it works. If you want you can have a copy. I would upload it to my server but I need to redo my layout so I am not doing anything with my website at the moment. Stefan
Posted on 2001-06-21 07:48:00 by Stefan Krause
I think Stephan's approach is more efficient. It's faster to work with a buffer and store it to disk when the user is done. For example, you could allocate your lines at runtime (with HeapAlloc), and store the pointers in an array. When the user removes a line, you simply delete the pointer. Then, when the user doesn't need the listview anymore, you store the lines on a file.
Posted on 2001-06-21 08:16:00 by karim
hey Stefan im very interested in your code. please send to smurf@gci.net thanks smurf
Posted on 2001-06-21 12:36:00 by smurf
all you have to do is memorymap your file. read every line in your listbox ... use some extra space or the stack as index holder. if you want to delete a line you have to find its index - go to the memory position and copy all stuff after the line to the position before so that the line is completly deleted... update indexes and everything is fine (note that all changes are directly reflected to your file so you not have to use write or readfile functions... just make use of the setfilepointer and setfileend functions to mark the new EOF). good luck
Posted on 2001-06-21 13:49:00 by _drcmda