News:

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

Help needed about CreateFile

Started by gofab, August 12, 2006, 02:34:35 PM

Previous topic - Next topic

gofab

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

donkey

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
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

gofab

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...

wjr

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

gofab

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