The below post is from a newsgroup. I've tried to help him, but no luck yet. His source is not very informative. And now curiosity has the better of me.

------------------------------------------------------------------------------------

Hello all, I'm new to this group, and I have a question already.
Can anyone help with a problem I'm having with WriteFile?
I execute the following code, but the WriteFile fails with "Parameter
error".
The file is created on disk, 0 bytes length.
.
.
.
*setup for CreateFileA
push 0 template file (not used)
push 00000080 file_attributes_normal
push 2 create_always
push 0 security (not used)
push 0 share options (not used)
push 40000000 generic_write
push 00401130 points to "C:\TEST"00h
call creatfilea
(file handle returned)

*setup for WriteFile
push 0 overlap structure (not used)
push 00401150 points to count of bytes written
push 22 number of bytes to write
push 00401180 address of data buffer
push eax file handle (from createfilea)
call writefile

eax contains 0 on return, indicating failure.
GetLastError gives 57h - Parameter Error.

Please point out my stupid mistake
Regards, Len
Posted on 2001-09-12 14:21:44 by ThoughtCriminal
CoffeeDrinker ,

if you're sure that CreateFile return a valid handle,

just some idea, check:

:) that address of data buffer is correct
:) that address of byte written variable is correct
:) number of byte to write must be a dword, try use a register as eax to be sure of it
:) numberOfBytesWritten must be a doubleword, be sure you reserved the correct 4 bytes space in memory.

good luck

A
Posted on 2001-09-12 16:57:56 by Bit7
Thanks, I'll post this to that NG, maybe it will help him.
Posted on 2001-09-12 18:11:42 by ThoughtCriminal
Here is the FAsm version, it works just fine.
Posted on 2001-09-12 21:00:06 by eet_1024

*setup for WriteFile
push 0 overlap structure (not used)
push 00401150 points to count of bytes written
push 22 number of bytes to write
push 00401180 address of data buffer
push eax file handle (from createfilea)
call writefile


i bet the problem is in the
 push 00401150 
that is pointing to the first section, that usually is read-only.

writefile surely check the consistence of this pointer, before writing to it, and return error

ancev
Posted on 2001-09-13 12:46:26 by ancev