Announcement

Collapse
No announcement yet.

SetFilePointer API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SetFilePointer API

    I am writing an xbase/b+tree database system and I am using the
    Windows API for I/O. I need to use the SetFilePointer API to
    position the file pointer before I do the WriteFile call. The
    SetFilePointer API can take two LONG integers that specify the
    byte position.

    From reading past posts (using POFFS) I noticed that only the
    first parameter is being passed with a LONG, the second ByVal
    %NULL. This would restrict files to a size of 2,147,486,648
    bytes. How can you pass a Quad Integer to the API so file sizes
    could be enormous. The API alludes to the fact that it can
    accept values in the QUAD range, but the API parameters are such
    that you need to pass two LONGS.

    Any idea how this is done??

    Greatly appreciated for your time and trouble.




    ------------------
    Paul Squires
    [email protected]
    Paul Squires
    FireFly Visual Designer (for PowerBASIC Windows 10+)
    Version 3 now available.
    http://www.planetsquires.com

  • #2
    from MSDN:
    DWORD SetFilePointer( HANDLE hFile, LONG lDistanceToMove,
    PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod );
    Not tested with the API, but

    Distance High = QuadValue \ 2,147,483,648
    Distance Low = QuadValue MOD 2,147,483,648


    Not that you pass the Distance Low by value and the Distance High by reference.

    (Sheesh, that's weird, ain't it?)

    MCM

    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Dim pp As Quad ' <-------------- Position
      ReDim pm(1 To 2) As Long At VarPtr(pp) ' <-- For API
      pp = ...
      SetFilePointer hFile, ByVal pm(1), pm(2), %FILE_BEGIN

      Note, pm(2) is ByRef.

      ------------------
      E-MAIL: [email protected]

      Comment


      • #4
        Michael & Semen,

        Thanks for the suggestions. I will try both suggestions once I
        clear out enough room on my hard drive to test such a large
        file.

        The DIM AT function is very interesting. The more I read about
        it, the more interesting things it seems you can do with it. This is
        only my first week with PB - next week I need to learn more
        about pointers (I gave up on "C" 10 years ago because pointers
        confused me so much!).

        Thanks,

        ------------------
        Paul Squires
        [email protected]
        Paul Squires
        FireFly Visual Designer (for PowerBASIC Windows 10+)
        Version 3 now available.
        http://www.planetsquires.com

        Comment


        • #5
          Paul,

          You will have fun with pointers as it allows you to do some interesting
          things. The distinction is actually a simple one, a "pointer" to a value
          tells you WHERE it is in memory.

          Take a simple example like,

          LOCAL var as LONG
          LOCAL address as DWORD

          var = 100 ' assign a value to a variable.
          address = VarPtr(var) ' get the address in memory of the variable.

          The result of VarPtr() is a POINTER to the variable "var"

          If you look at both in a MsgBox,

          MsgBox str$(var),0,str$(address)

          You will get the value "100" and a large DWORD size number which is the
          actual address of WHERE the variable is in memory. Now if you pass that
          POINTER to a SUB or FUNCTION by value (ByVal), at the other end you get
          the same large DWORD size number that is its address. Converting it back
          to a value is easy with the POINTER operator on PowerBASIC.
          Code:
          FUNCTION TestFunc(ByVal longVar as LONG PTR) as LONG
          
              LOCAL var as LONG   ' make a variable of the right type
          
              var = @longVar      ' use the POINTER operator [ @ ] to access the value
          
              FUNCTION = var      ' return the value so you can test it
          
          END FUNCTION
          This example is very simple but you can do the same thing with an array or
          UDT so that you can pass larger and more complex data in a single address.

          You will find that pointers in basic are a lot easier to manage that in the
          older dialects of C and they are very powerful once you get the swing of them.

          Regards,

          [email protected]

          ------------------
          hutch at movsd dot com
          The MASM Forum - SLL Modules and PB Libraries

          http://www.masm32.com/board/index.php?board=69.0

          Comment


          • #6
            Thanks Steve,

            That makes things clearer. I have know how to use VarPtr and
            StrPtr since I absorbed Ethan Winer's book "BASIC Techniques
            and Utilities" a few years ago. I never realized that pointers
            were so similar. I have a few SUBS now where I use VarPtr or
            StrPtr to get the address and then I pass that address to
            the SUB via a DWORD parameter. I could do the same thing with
            a pointer and then use the @ functionality in the SUB to
            manipulate the data. Fantastic!

            They should call this "AmazingBasic" because I am blown away as
            each hour passes that I use this product! Also, the in-line
            assembler is great. Even though I am not a very good assembly
            language programmer, I have been able to "borrow" some in-line
            code from this forum and it has sped up some of my time critical
            code by leaps and bounds!

            Thanks


            ------------------
            Paul Squires
            [email protected]
            Paul Squires
            FireFly Visual Designer (for PowerBASIC Windows 10+)
            Version 3 now available.
            http://www.planetsquires.com

            Comment

            Working...
            X