News:

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

error reading a file

Started by Arroso, May 09, 2006, 05:08:38 PM

Previous topic - Next topic

Arroso

Hello world,
I'm reading a flat file and got an error never seen before: ERROR_NOACCESS

I use the standard ReadFile after both successfull CreateFile and SetFilePointer

May someone give me any suggestion on the possible causes? I'm running on a W2K sp4 box with Admin rights

thanks

Ian_B

hardware glitch/cable fault?

Arroso

not really, normal behaviour but this error never seen be4


invoke CreateFile,addr Src,GENERIC_READ,FILE_SHARE_READ,addr seca,OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,0
mov hfil,eax
.if !eax
invoke SendMessage,hSysout,WM_SETTEXT,0,addr err20
mov flg_err,TRUE
ret
.endif

; set the file pointer to From position
.if vFrom != 0
invoke SetFilePointer,hfil,vFrom,0,FILE_BEGIN
PrintHex eax
.if eax==0FFFFFFFFh
invoke SendMessage,hSysout,WM_SETTEXT,0,addr err21
invoke CloseHandle,hfil
mov flg_err,TRUE
ret
.endif
.endif

invoke ReadFile,hfil,hMem,hflen,addr hrw,0
.if !eax
invoke GetLastError
PrintHex eax," READ lasterror"
invoke SendMessage,hSysout,WM_SETTEXT,0,addr err23
mov flg_err,TRUE
.endif


P1

998L  ERROR_NOACCESS                        Invalid access to memory location.Memory Problems?

Regards,  P1  :8)

Mark Jones

Indeed Arroso, make sure the buffer is bigger than the data you are reading by at least 1 byte. (This is so if the data is read as ASCII, the last character is a null.) i.e.,


    invoke GobalAlloc,GPTR,(1024*n+1)
    mov hMem,eax
;... load data into mem, etc...
    invoke GlobalFree,hMem


Where N is literal number of kilobytes required. If you need to load a file of variable size, try:


    invoke GetFileSize,addr szMyFilePointer
    add eax,1
    invoke GlobalAlloc,GPTR,eax
    mov hMem,eax
;... load data into mem, etc...
    invoke GlobalFree,hMem


Where szMyFilePointer is the ASCII-terminated path and filename to return the size of. Good luck.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Arroso

P1 and Mark: the token "Memory" was the hint I needed to pinpoint my crime :D
it was indeed a too small buffer previously GlobalAlloc-ated.
Couldn't relate the "NOACCESS" term to anything, you know. A 0C04 abend would have been clearer ghghgh

thank you all