I am having trouble getting createfile to work properly.


FileName db "test.txt",0
mov esi,FileName
invoke CreateFile,esi,GENERIC_READ,0,0,OPEN_EXISTING,0,0

always returns:


where test.asm is an existing file.

I also tried "c:\fasm\test.txt" which is the full pathname.
Posted on 2003-01-04 12:56:03 by msmith
Try using

lea esi, FileName

instead of

mov esi, FileName
Posted on 2003-01-04 13:15:17 by Gunner
I tried the lea, but it gives a compile time error.
Posted on 2003-01-04 13:26:31 by msmith
It appears that the crux of my problem is the validity of what the function considers a good file name. The syntax of the failing line turns out to be identical to code in the fasm package itself.
Posted on 2003-01-04 13:30:07 by msmith
Very strange, the following works perfectly for me in a current project:
outFile db 'New.txt',0

hdlFile dd 0
mov [hdlFile],eax

Unless its the double quotes?
Posted on 2003-01-04 17:42:38 by Eóin
You can't just mov esi to the filename variable, you have to use lstrcpy (a windows API instruction) or make your own proc to copy one string to another.
Posted on 2003-01-04 18:17:00 by CyberGuy
In Fasm the origionally posted code should work, problem must be elsewhere. Are you sure the file itself exists? Otherwise you'll need to post more code.
Posted on 2003-01-04 19:16:29 by Eóin
Thank all of you for your help.

The problem turned out be code not shown in the snippet.

mov byte [_CRLF+12],13; CR
mov byte [_CRLF+13],10; LF
mov byte [_CRLF+14],0; NULL
mov byte [_Prompt+12],63; ?
mov byte [_Prompt+13],0; NULL

This piece of code needed the byte prefix added (as shown). It was mov dword by default which was clobbering the first part of my string.
Posted on 2003-01-04 20:27:20 by msmith