The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: stanley on October 26, 2009, 11:47:31 PM

Title: How write the data from the buffer
Post by: stanley on October 26, 2009, 11:47:31 PM
I have posted the code below,in which Unable to write data from the buffer  to the newly created file,so kindly help me to troubleshoot the problem.
and please explain me the mistake in the code
//------------------------------------------------------------------------------//
.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\advapi32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\advapi32.lib
.data
slog db "c:\ip1.txt",0
wbuff db "Is This visible",0
.data?
hfile dd ?
.code
start:
invoke DeleteFile,addr slog
invoke CreateFile,addr slog,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
mov hfile,eax
invoke WriteFile,addr slog,addr wbuff,500,NULL,NULL
mov hfile,eax
invoke CloseHandle,hfile
ret
end start
//------------------------------------------------------------------------------//





Title: Re: How write the data from the buffer
Post by: jj2007 on October 27, 2009, 12:01:19 AM
It would help a lot if you invested a minimal effort in reading the documentation. You will not get very far with that attitude.

start:
;invoke DeleteFile,addr slog not needed
invoke CreateFile,addr slog,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
mov hfile,eax
invoke WriteFile,eax,addr wbuff,15,offset BytesWritten,NULL  ; 15, not 500
;mov hfile,eax you are not getting a handle here...!
invoke CloseHandle,hfile
Title: Re: How write the data from the buffer
Post by: stanley on October 27, 2009, 12:42:06 AM
Quote from: jj2007 on October 27, 2009, 12:01:19 AM
It would help a lot if you invested a minimal effort in reading the documentation. You will not get very far with that attitude.

start:
;invoke DeleteFile,addr slog not needed
invoke CreateFile,addr slog,GENERIC_WRITE,FILE_SHARE_WRITE,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
mov hfile,eax
invoke WriteFile,eax,addr wbuff,15,offset BytesWritten,NULL  ; 15, not 500
;mov hfile,eax you are not getting a handle here...!
invoke CloseHandle,hfile


Thanks " jj2007 " i got it