News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

WriteFile... ERROR_INVALID_HADLE

Started by Telefunken, July 16, 2006, 07:28:20 AM

Previous topic - Next topic

Telefunken

hello
i'm trying to figure out the WriteFile API as part of a bigger project so I decided to try it out by making a program that just writes a string of text to a .txt file.
here's my code

    .data?
hFile dd ?
    .data
string db "Hello, im writing to a file",0
file db "./file.txt",0



    .code


start:
invoke   CreateFile,addr file,GENERIC_WRITE,FILE_SHARE_READ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULL
mov hFile, eax
invoke WriteFile,addr hFile,addr wString,sizeof string,addr openout,NULL

call ExitProcess
end start


That doesn't work. Olly says ERROR_INVALID_HANDLE. I know that measn theres something wrong with the file handle, maybe its not getting saved right. I've tried pretty much everything and I can't figure it out. I've searched here, google, MSDN but nothing I try seems to help. I know its something obvious but I just don't know what it is. Any help is appreciated.

msmith


invoke WriteFile,addr hFile,addr wString,sizeof string,addr openout,NULL


You need to remove the "addr" that proceeds hFile.

Telefunken

it works!  :U

i feel really really stupid... ha  :(

P1

You should add some error checking in this code. 

It's a pay me now or pay me later situation.  It's best to get it going early in the project. 

Regards,  P1  :8)