flat assembler
Message board for the users of flat assembler.
Index
> Windows > WriteFile |
Author |
|
UCM 01 Oct 2006, 15:44
You will have to open the file with OPEN_EXISTING, then use SetFilePointer to set the file pointer to the end of the file so you can append data.
|
|||
01 Oct 2006, 15:44 |
|
LocoDelAssembly 01 Oct 2006, 16:39
Or use OPEN_ALWAYS so the file will be created automatically if it's the first time you use it.
http://windowssdk.msdn.microsoft.com/en-us/library/ms685006.aspx |
|||
01 Oct 2006, 16:39 |
|
ly 01 Oct 2006, 16:42
Hello UCM
thanks I tried but it doesn't work. can you write sample code for SetFilePointer ? thanks ly |
|||
01 Oct 2006, 16:42 |
|
ly 01 Oct 2006, 16:50
Hello UCM
Its OK now it works.(I use OPEN_ALWAYS) thanks again |
|||
01 Oct 2006, 16:50 |
|
barmentalisk 20 Jun 2008, 10:32
Trouble with write file.
This code works correctly: Code: format PE GUI 4.0 entry start include 'win32a.inc' section '.data' data readable writeable fname db 'E:\test.txt',0 hfile dd ? pmem db '0123456789AB' lpNumberOfBytesWritten dd ? section '.code' code readable executable start: invoke CreateFile,fname,GENERIC_READ + GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0 mov [hfile],eax invoke WriteFile,[hfile],pmem,12,lpNumberOfBytesWritten,0 invoke CloseHandle,[hfile] invoke ExitProcess,0 section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL' include 'api\kernel32.inc' But this one ... : Code: format PE GUI 4.0 entry start include 'win32a.inc' section '.data' data readable writeable fname db 'E:\test.txt',0 hfile dd ? hheap dd ? pmem dd ? lpNumberOfBytesWritten dd ? section '.code' code readable executable start: invoke CreateFile,fname,GENERIC_READ + GENERIC_WRITE,0,0,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,0 mov [hfile],eax invoke GetProcessHeap mov [hheap],eax invoke HeapAlloc,[hheap],HEAP_ZERO_MEMORY,12 mov [pmem],eax mov [pmem],'0123' mov [pmem+4],'4567' mov [pmem+8],'89AB' invoke WriteFile,[hfile],pmem,12,lpNumberOfBytesWritten,0 invoke HeapFree,[hheap],0,pmem invoke CloseHandle,[hfile] invoke ExitProcess,0 section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL' include 'api\kernel32.inc' It doesn't save to file '4567'. No matter what method I use to put text to memory and no matter how long is the text, - it always have missed second dword of data in the resulting file. |
|||
20 Jun 2008, 10:32 |
|
DOS386 20 Jun 2008, 11:27
Code: invoke HeapAlloc,[hheap],HEAP_ZERO_MEMORY,12 mov [pmem],eax ; Why ??? mov [pmem],'0123' ; Overwrite ??? mov [pmem+4],'4567' mov [pmem+8],'89AB' Faulty indexing > always miss the '4567' Because it gets overwritten by the lp...blah...blah...blah _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
20 Jun 2008, 11:27 |
|
shoorick 20 Jun 2008, 11:42
try this
Code: invoke HeapAlloc,[hheap],HEAP_ZERO_MEMORY,12 mov [pmem],eax mov dword [eax],'0123' mov dword [eax+4],'4567' mov dword [eax+8],'89AB' invoke WriteFile,[hfile],eax,12,lpNumberOfBytesWritten,0 invoke HeapFree,[hheap],0,[pmem] _________________ UNICODE forever! |
|||
20 Jun 2008, 11:42 |
|
barmentalisk 20 Jun 2008, 12:09
Sorry, may be I need some sleep =)))
thank you very much !!! |
|||
20 Jun 2008, 12:09 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.