I finally found the problem, the problem was me :)
The problem is when I call WriteFile or ReadFile the function will write on BytesRead or BytesWritten which means that I must give the effective address of the variable.
In MASM32:
PUSH 0 ; /pOverlapped = NULL
PUSH pBytesRead ; |pBytesRead = ? PUSH BytesToRead ; |BytesToRead
PUSH OFFSET Buffer ; |Buffer
PUSH hFile ; |hFile
CALL ReadFile ; \ReadFile
The correct code is:
PUSH 0 ; /pOverlapped = NULL
LEA EAX, pBytesRead
PUSH EAX ;|pBytesRead = ?
PUSH BytesToRead ; |BytesToRead
PUSH OFFSET Buffer ; |Buffer
PUSH hFile ; |hFile
CALL ReadFile ; \ReadFile
In C code:
HANDLE hFile;
LPCVOID Buffer = "Hello";
DWORD BytesWritten = 0;
hFile = CreateFile("rw.txt",FILE_APPEND_DATA, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if(!WriteFile(hFile, Buffer, 5, &BytesWritten, NULL))
MessageBox(NULL, "Can not write!", "Error", MB_OK);
CloseHandle(hFile)