News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

File IO Library

Started by hutch--, February 16, 2022, 10:53:01 AM

Previous topic - Next topic

hutch--

This is a library of file IO functions that I have used for years, they have been super reliable and as pure Windows API code, they are easily fast enough and simple enough to use.

This is the text file to explain the functions.

    ****************************************************
    These prototypes are only for documentation purposes
    They are not needed by the application using the lib
    ****************************************************

  ' ----------------------------
  ' High level file IO functions
  ' ----------------------------
  ' FUNCTION load_file(fname$) as STRING                     - load any file into basic string memory
  ' FUNCTION save_file(fname$,src$) as DWORD                 - save any file to disk

  ' ---------------------------
  ' Low level file IO functions
  ' ---------------------------
  ' FUNCTION fcreate(fname$) as DWORD                        - create a file and return a file handle
  ' FUNCTION fopen(fname$) as DWORD                          - open a file and return a file handle
  ' FUNCTION fclose(ByVal hFile as DWORD) as DWORD           - close an open file
  ' FUNCTION fsize(ByVal hFile as DWORD) as DWORD            - return the size of an open file

  ' FUNCTION fread(ByVal hFile as DWORD,ByVal bcnt as DWORD) as STRING  - read bcnt of data and return a basic string

  ' FUNCTION fwrite(ByVal hFile as DWORD,bdat$) as DWORD     - write  basic string to an open file
  ' FUNCTION fprint(ByVal hFile as DWORD,bdat$) as DWORD     - write a line of text to an open file

  ' --------------------------------------------
  ' write zero terminated string to an open file
  ' --------------------------------------------
  ' FUNCTION fprintz(ByVal hFile as DWORD,ByVal pdat as DWORD) as DWORD

  ' ---------------
  ' fseek CONSTANTS
  ' ---------------
  ' MACRO FILE_BEGIN        = 0
  ' MACRO FILE_CURRENT      = 1
  ' MACRO FILE_END          = 2
  ' ------------------------------------------------
  ' change the file pointer location in an open file
  ' ------------------------------------------------
  ' FUNCTION fseek(ByVal hFile as DWORD,ByVal plusminus as LONG,ByVal mvmethod as DWORD) as LONG

hutch--

With apologies, there is an errata in one module. This is its replacement. Just overwrite "fcreate.bas" and run the "makelib.bat" file again and all will be well.  :biggrin:

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    #compile sll

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    DECLARE FUNCTION fcreateA LIB "KERNEL32.DLL" ALIAS "CreateFileA" ( _
                     ByVal lpFileName AS DWORD, _
                     ByVal dwDesiredAccess AS DWORD, _
                     ByVal dwShareMode AS DWORD, _
                     ByVal lpSecurityAttributes AS DWORD, _
                     ByVal dwCreationDisposition AS DWORD, _
                     ByVal dwFlagsAndAttributes AS DWORD, _
                     BYVAL hTemplateFile AS DWORD) AS DWORD

'     MACRO GENERIC_WRITE         = &H40000000&
'     MACRO CREATE_ALWAYS         = 2
'     MACRO FILE_ATTRIBUTE_NORMAL = &H00000080

' -------------------------------

FUNCTION fcreate(fname$) COMMON as DWORD

    FUNCTION = fcreateA(StrPtr(fname$),&H40000000&,0,0,2,&H00000080,0)

END FUNCTION

' ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤