No announcement yet.

SetFilePointer API

  • Filter
  • Time
  • Show
Clear All
new posts

  • Paul Squires
    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!


    Paul Squires
    [email protected]

    Leave a comment:

  • Steve Hutchesson

    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.
    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
    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.


    [email protected]


    Leave a comment:

  • Paul Squires
    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

    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!).


    Paul Squires
    [email protected]

    Leave a comment:

  • Semen Matusovski
    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]

    Leave a comment:

  • Michael Mattias
    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?)


    Leave a comment:

  • Paul Squires
    started a topic SetFilePointer API

    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]