flat assembler
Message board for the users of flat assembler.

Index > Windows > File handling??

Author
Thread Post new topic Reply to topic
logic



Joined: 21 Oct 2003
Posts: 5
logic
How can perform File operations,that file reading,file writing,file appending using FASM????
Post 01 Nov 2003, 17:50
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard
Like in every win32 program: use CreateFile, ReadFile, WriteFile.... etc. See win32.hlp for details.

regards
Post 01 Nov 2003, 17:53
View user's profile Send private message Visit poster's website Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
Code:
include '%fasminc%\WIN32AX.INC'
.data
    MyFilesNam      db "Data.txt",0
    CarRetLnFd      db 0Dh,0Ah,00h,00h
    WrittenBts      dd 0
    MyFileHWND      dd 0
    MyDataHere      dd 78563412h,0D0A0000h ;Seen as "12345678" in hex editor or "4Vxj" Smile

.code
start:
    invoke CreateFile,MyFilesNam,GENERIC_WRITE,0,0,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,0
    mov [MyFileHWND],eax
    invoke WriteFile,[MyFileHWND],[MyDataHere],8,[WrittenBts],0
    .if [WrittenBts],ne,8
       invoke  MessageBox,NULL,"Error writing file ...","Error",MB_OK + MB_ICONEXCLAMATION
    .endif
    invoke CloseHandle,[MyFileHWND]
    invoke ExitProcess,0
.end start
    

Now, this is translated from mASM, but it gives me an error. No data is written to the file, though the file IS created.
I tried messing with it, but ended up with Doctor Watson saying "access violation"
A fragment from *.log >
function:WriteFile
...
7c5862c7 33c9 xor ecx,ecx
7c5862c9 3bd9 cmp ebx,ecx
7c5862cb 7402 jz GetHandleInformation+0x38 (7c58ebcf)
FAULT ->7c5862cd 890b mov [ebx],ecx ds:00000040=????????
7c5862cf 64a118000000 mov eax,fs:[00000018] fs:00000018=????????
7c5862d5 8b4030 mov eax,[eax+0x30] ds:00bb9ec6=????????
7c5862d8 8b7d08 mov edi,[ebp+0x8] ss:00bb9e8e=????????
...
no sense in giving the whole log Razz

Hope I gave U sufficient info. If I could print just one char to my file, I could go on from there Very Happy

Thanks
Post 12 Dec 2003, 23:14
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Eoin



Joined: 16 Jun 2003
Posts: 68
Location: Ireland
Eoin
Don't put brackets around WrittenBits, its a pointer to it you need to pass, not the value in it Smile .

Code:
invoke WriteFile,[MyFileHWND],[MyDataHere],8,WrittenBts,0    
Post 13 Dec 2003, 00:46
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2140
Location: Estonia
Madis731
The code was supposed to be:
Code:
invoke WriteFile,[MyFileHWND],MyDataHere,8,WrittenBts,0
    

so no brackets around my data either but thanks for leading me to right path Wink
Post 14 Dec 2003, 18:58
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.