News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Won't correct record in GoAsm

Started by shankle, January 09, 2013, 10:51:33 PM

Previous topic - Next topic

shankle

     1-12-2013
I think the problem is solved.
Only change I made is to mov RecordOffset, -264 instead of adding
it like I did in MASM32. Kind of makes one wonder how the MASM32
program ever worked......

Hope I have included all the necessary data.
Thanks for any help.

; converting a Masm32 32-bit program to GoAsm 32-bit     
; EX: of MASM32 bit code that is working
This code corrects an already existing record by overwriting it
Record size is 264 bytes

BytesReadWritten dd       0
RecordOffset     SDWORD   0   
RecordSize       dd       264

buf3             db   100 dup (0)           
buf4             db   15 dup (0)
FileDat          db   'blahblah.dat',0       ; name of file
ReadWriteBuffer  db   264 DUP (0)

.data?
hFile       HANDLE    ?

Wndproc.....
; other code
           invoke GetFullPathName, addr FileDat, 100, addr buf3, addr buf4       
           invoke CreateFile, addr buf3, GENERIC_READ or GENERIC_WRITE,\
                                FILE_SHARE_READ or FILE_SHARE_WRITE,\
                                NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
           mov hFile, eax
           invoke SetFilePointer, hFile, NULL, NULL, FILE_BEGIN
           invoke ReadFile, hFile, addr ReadWriteBuffer, RecordSize,\
                                   addr BytesReadWritten, NULL
; other code
         add RecordOffset, -264          ;adjust to rewrite record
         invoke SetFilePointer, hFile, RecordOffset, NULL, FILE_CURRENT           
         invoke WriteFile, hFile, addr ReadWriteBuffer, RecordSize,\
                                  addr BytesReadWritten, NULL
         invoke CloseHandle, hFile
; other code         
         
;*******************************************************************         
; EX: of GoASm 32 bit code that is "NOW" working
This code should correct an already existing record by overwriting it
Record size is 264 bytes

BytesReadWritten dd       0
hFile            dd       0
RecordOffset     SDWORD   0   
RecordSize       dd       264

buf3             db   100 dup (0)           
buf4             db   15 dup (0)
FileDat          db   'blahblah.dat',0       ; name of file
ReadWriteBuffer  db   264 DUP (0)

WndProc:
        FRAME  hWnd,iMsg,wParam,lParam
; other code
          invoke GetFullPathName, addr FileDat,100,addr buf3,addr buf4       
          invoke CreateFile, addr buf3,GENERIC_READ or GENERIC_WRITE,\
                              FILE_SHARE_READ or FILE_SHARE_WRITE,\
                              NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
                             
; other code               
         mov D[RecordOffset],-264          ;adjust to rewrite record
         invoke SetFilePointer, [hFile],[RecordOffset],NULL,FILE_CURRENT                                 
         invoke WriteFile, [hFile],addr ReadWriteBuffer,[RecordSize],\
                                  addr BytesReadWritten,NULL                                         
         invoke CloseHandle, [hFile]                         
; other code         
ENDF