The MASM Forum Archive 2004 to 2012

Project Support Forums => GoAsm Assembler and Tools => Topic started by: gofab on August 12, 2006, 02:34:35 PM

Title: Help needed about CreateFile
Post by: gofab on August 12, 2006, 02:34:35 PM
Hi to everybody,

I am new to 32-bit assembly world, so I am discovering just now how the API functions work.
I wrote the following program to create a file "pippo.txt " with GoAsm, there are no compilation errors, but when I execute "prova.exe" the file is not created, could you explain me why??

Thank you in advance

DATA SECTION

pathin db 'c:\goasm\pippo.txt',0

CODE SECTION

START:

push 0, 80h, 3
push 0, 1, 80000000h
push ADDR pathin

call CreateFilew
call ExitProcess



My command to compile are: - goasm prova.asm
                                         - golink prova.obj user32.dll kernel32.dll gdi32.dll
Title: Re: Help needed about CreateFile
Post by: donkey on August 12, 2006, 05:24:48 PM
Hi gofab,

You are using an ANSI file name with the Unicode version of the API (CreateFileW), in order to use the Unicode version use DUS instead of DB for the declaration in the DATA SECTION, this will convert the string to Unicode at compile time. Or, simply use the ANSI wrapper (CreateFileA)

Donkey
Title: Re: Help needed about CreateFile
Post by: gofab on August 12, 2006, 07:06:09 PM
Thank you for the reply, donkey

Honestly, I implemented both your suggestions, but the file 'pippo.txt' doesn't appear yet :-(

Before I tried substituting DB with DUS and using CreateFileW, then with DB using CreateFileA
There are no compilation errors, I execute the program but no file...
Title: Re: Help needed about CreateFile
Post by: wjr on August 13, 2006, 05:14:12 AM
Hi gofab,

Getting closer... for the dwCreationDisposition parameter, you are using OPEN_EXISTING=3 which will fail if the file does not exist... so change that to OPEN_ALWAYS=4 and then you should see the file, although with a size of zero.

Looking ahead, if your next step will be to write to that file, you will also need to modify the dwDesiredAccess parameter to allow a GENERIC_WRITE=40000000h.

WJR
Title: Re: Help needed about CreateFile
Post by: gofab on August 13, 2006, 08:08:20 AM
Hi wjr,

you are right, now the function works, the computer is always right too :-)

Thank you very much, now I will watch more carefully the MSDN documentation