Loading ...
Sorry, an error occurred while loading the content.

Re: [libertybasic] Struct, Variable, Long, Boolean - Coin Toss?

Expand Messages
  • Brad and Anna Moore
    ... [snip] I ve even ... Kieth - what you really need is a good book. Back in the LB2 days we used the Waite Groups Windows API Bible. It covered mostly 16
    Message 1 of 6 , Feb 28, 2003
    • 0 Attachment
      Keith wrote:

      > Oh boy, it's me again, still asking those crazy dll questions.
      [snip] I've even
      > searched the win32api guide, but for me, there's still some missing
      > puzzle pieces. I wonder if someone out there knowledgeable about
      > this could explain some of these questions?

      Kieth - what you really need is a good book. Back in the LB2 days we used
      the Waite Groups Windows API Bible. It covered mostly 16 bit calls. I know
      Alyce has worn the covers off of her copy. Now in the 32 bit days there are
      several books to choose from. Because I come from the Basic world more than
      from the C++ or C world - I like Ziff-Davis Press's Visual Basic 5.0
      Programmers Guide to the Win32 API by Dan Appleman.

      I would love to see an
      > article on this particular subject.

      I know I have written an article on the subject of the API and Alyce
      followed this up with one on converting from VB API calls to LB API calls.
      It is hard to cover every possible API in a newsletter. Afterall every one
      of my API books are at least 1500 pages long - some longer.

      I hope Alyce doesn't mind, but
      > as an example, I'd like to use one of the functions that she showed
      > me earlier.
      >
      > CallDLL #kernel32, "GetComputerNameA",_
      > lpBuffer$ as ptr, _
      > SIZE as struct, _
      > result As Boolean
      >
      > I understand that the following call requires a pointer to the
      > string, and a variable that contains the size of that pointer, but
      > how would I know to create a struct to contain that info?

      The trick is to understand the call. Here is what my reference says:

      lpBuffer - String - A string buffer to load with the comuter name
      nSize - Long - The length of the buffer. This variable is loaded with the
      actual length of the computer name on return.
      return value as Long, TRUE (non-zero) as success.

      So the API call must change the LONG's value that we pass to it. This is
      not possible if we pass a actual LONG. We need to pass a pointer so that
      the value is passed by reference (to the variables memory location) and not
      by value (the LB default for LONG). To do this we create a struct with a
      single element, a long and then pass the pointer to the struct.

      So somewhere above the calldll command there is a line that says:

      struct SIZE, size as long

      After the call has returned the actual size of the string value (its length)
      will be in struct.SIZE.size.


      > Why
      > wouldn't the variable SIZE = Len(lpBuffer$) work? And in the
      > call itself couldn't I define SIZE as long? I noticed that VB uses a
      > Windows Constant here.

      If you see a VB call using a constant for nSize the the VB call is in error.

      >Can this be a clue as to how I would prepare
      > for the call in LB? And does this have anything to do with result
      > being defined as Boolean?

      You really could use ither Boolean or Long as the return value. It should
      work either way.

      > There has been a lot of good info written
      > about making api calls, as well as creating arrays, structs, etc.,
      > but as far as I know, theres not much concerning the preperation of
      > the variables that takes place beforehand, or perhaps I should say,
      > the types of variable. That is, those that are used in the api
      > calls.

      What you really need is a good book - see above. You mention NL102 below,
      take a look at NL101. It has another article you might like to read about
      the API. It also goes into depth in some of the areas of variables and the
      like.

      I know there is some, such as NL102, but I've a feeling
      > there's still a lot missing. There's got to be a simple secret that
      > I'm overlooking, isn't there? Gee, I hope so! :-(

      Did I mention you might want to get a good book?

      Brad
    • Keith Nance <fuego@firehousemail.com>
      Oh boy, it s me again, still asking those crazy dll questions. I ve been studying just about everything I can get my hands on, and although I ve found a lot of
      Message 2 of 6 , Feb 28, 2003
      • 0 Attachment
        Oh boy, it's me again, still asking those crazy dll questions.
        I've been studying just about everything I can get my hands on, and
        although I've found a lot of good resources, I just can't
        find exactly what I'm looking for. I've compared several dll
        examples but many have their own unique characteristics. I've even
        searched the win32api guide, but for me, there's still some missing
        puzzle pieces. I wonder if someone out there knowledgeable about
        this could explain some of these questions? I would love to see an
        article on this particular subject. I hope Alyce doesn't mind, but
        as an example, I'd like to use one of the functions that she showed
        me earlier.

        CallDLL #kernel32, "GetComputerNameA",_
        lpBuffer$ as ptr, _
        SIZE as struct, _
        result As Boolean

        I understand that the following call requires a pointer to the
        string, and a variable that contains the size of that pointer, but
        how would I know to create a struct to contain that info? Why
        wouldn't the variable SIZE = Len(lpBuffer$) work? And in the
        call itself couldn't I define SIZE as long? I noticed that VB uses a
        Windows Constant here. Can this be a clue as to how I would prepare
        for the call in LB? And does this have anything to do with result
        being defined as Boolean? There has been a lot of good info written
        about making api calls, as well as creating arrays, structs, etc.,
        but as far as I know, theres not much concerning the preperation of
        the variables that takes place beforehand, or perhaps I should say,
        the types of variable. That is, those that are used in the api
        calls. I know there is some, such as NL102, but I've a feeling
        there's still a lot missing. There's got to be a simple secret that
        I'm overlooking, isn't there? Gee, I hope so! :-(

        Keith
      • Alyce Watson
        ... Hi Keith, Of course I don t mind! The messages that discussed this are here: http://libertybasic.conforums.com/ It is a good idea to continue
        Message 3 of 6 , Mar 1, 2003
        • 0 Attachment
          At 07:45 AM 3/1/2003 +0000, you wrote:
          > I hope Alyce doesn't mind, but
          >as an example, I'd like to use one of the functions that she showed
          >me earlier.


          Hi Keith,

          Of course I don't mind! The messages that discussed this are
          here: http://libertybasic.conforums.com/ It is a good idea to continue
          discussions in the forum where they began, just to make it easier to find
          all of the messages.

          Brad has done an outstanding job of anwering you, so there is nothing I can
          add!

          Alyce
        • Brad and Anna Moore
          The ISBN is 1-878739-15-8 It is for 16bit windows though. Not a lot of use these days in 32 bit LB. The Wait Group put out a 32bit update called Windows 95
          Message 4 of 6 , Mar 1, 2003
          • 0 Attachment
            The ISBN is 1-878739-15-8

            It is for 16bit windows though. Not a lot of use these days in 32 bit LB.

            The Wait Group put out a 32bit update called Windows 95 WIN32 Programming
            API Bible. Its ISBN is 1-57169-009-3. It is probably out of print too by
            now. It is targeted at C users, so a bit cryptic at times.

            For anyone who really wants to dig into the Windows OS and get to know how
            things really work I can recommend the book Programming Windows, 5th edition
            by Charles Petzold. I don't have the ISBN, but it is still in print - look
            it up on Amazon.com. It is also targeted at the C programmer, but if you
            visit the Powerbasic website (www.powerbasic.com)you can get all the example
            programs from their download section in PB code. Of course that is not a
            whole lot better, but it is a little bit better.

            I know the subject of the API can fill volumes. I also know that 2 articles
            are not enough. I would sure love to see Brent or Dennis write a follow-on
            article to the work that has already been written.

            Chin Up.

            Brad
            ----- Original Message -----
            From: <fuego@...>
            To: <libertybasic@yahoogroups.com>
            Sent: Saturday, March 01, 2003 4:45 PM
            Subject: [libertybasic] Re: Struct, Variable, Long, Boolean - Coin Toss?


            --- In libertybasic@yahoogroups.com, "Brad and Anna Moore"
            <bjaz.moore@v...> wrote:

            > Kieth - what you really need is a good book. - I like Ziff-Davis
            Press's Visual Basic 5.0 Programmers Guide to the Win32 API by Dan
            Appleman.

            Brad, I purchased the book several months ago, but I'm not very
            familiar with VB syntax. That's why I thought a constant was used
            for this call. s$ = String$(MAX_COMPUTERNAME_LENGTH+1, Ø)
            I'm not sure what's up with all this. I actually had read your
            article in NL101 also, and it was very informative, but it's a
            relatively short article for such a big subject.

            I'm not going to carry on here, because I did actually start this
            conversation elsewhere as Alyce mentioned, but I would like to know
            if you could give me the ID number of the old book you have for 16
            bit. Perhaps I could still order one if they're in print.

            Meanwhile, I will be hashing over some of what you explained to me
            in your reply. Thanks!

            Keith





            To unsubscribe from this group, send an email to:
            libertybasic-unsubscribe@egroups.com



            Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
          • Keith Nance <fuego@firehousemail.com>
            ... Press s Visual Basic 5.0 Programmers Guide to the Win32 API by Dan Appleman. Brad, I purchased the book several months ago, but I m not very familiar with
            Message 5 of 6 , Mar 1, 2003
            • 0 Attachment
              --- In libertybasic@yahoogroups.com, "Brad and Anna Moore"
              <bjaz.moore@v...> wrote:

              > Kieth - what you really need is a good book. - I like Ziff-Davis
              Press's Visual Basic 5.0 Programmers Guide to the Win32 API by Dan
              Appleman.

              Brad, I purchased the book several months ago, but I'm not very
              familiar with VB syntax. That's why I thought a constant was used
              for this call. s$ = String$(MAX_COMPUTERNAME_LENGTH+1, Ø)
              I'm not sure what's up with all this. I actually had read your
              article in NL101 also, and it was very informative, but it's a
              relatively short article for such a big subject.

              I'm not going to carry on here, because I did actually start this
              conversation elsewhere as Alyce mentioned, but I would like to know
              if you could give me the ID number of the old book you have for 16
              bit. Perhaps I could still order one if they're in print.

              Meanwhile, I will be hashing over some of what you explained to me
              in your reply. Thanks!

              Keith
            • Alyce Watson
              ... That sets up a buffer. MAX_COMPUTERNAME_LENGTH is a constant, representing a number. the String$ function sets up a string of the character specified.
              Message 6 of 6 , Mar 1, 2003
              • 0 Attachment
                At 08:15 PM 3/1/2003 +0000, you wrote:
                >Brad, I purchased the book several months ago, but I'm not very
                >familiar with VB syntax. That's why I thought a constant was used
                >for this call. s$ = String$(MAX_COMPUTERNAME_LENGTH+1, Ø)


                That sets up a buffer. MAX_COMPUTERNAME_LENGTH is a constant, representing
                a number. the String$ function sets up a string of the character
                specified. The one you see sets up a long string of null
                characters. There is nothing in the string because the function will fill it.

                When you are talking about VB, you need to know that it passes ByRef as
                default. That means that it passes the memory address of the variable so
                that the function can access it and change it. If nothing is specified,
                then an argument is passed ByRef by VB. To pass a copy of the variable --
                just its value, not its memory address, then you pass ByVal. If you see
                ByVal, the argement is passed by value. If you see nothing, or ByRef, the
                argument is passed by reference - in other words, passed as a memory
                address, not as the value contained in the function.

                In the case of the function you chose, you set up a string buffer and let
                the function fill it with the name of the computer. In LB, we pass ByVal
                as default. This is the opposite of VB. To pass ByRef for strings, we add
                a terminating null character. This tells LB to pass ByRef. LB adds a null
                terminator to all strings passed as ptr. We don't need to add the null
                terminator unless we want to pass ByRef, and then it is simply a signal to
                LB to pass the memory address of the string.

                To pass a numeric variable ByRef so that it can be changed by the function,
                we put it in a single item struct, since structs are always passed
                ByRef. You happened to choose a difficult function in that it needs both a
                string and numeric var passed ByRef. When it returns, the numeric var
                holds the length of the string returned, and the string var holds the
                computer name.

                HTH,
                Alyce
              Your message has been successfully submitted and would be delivered to recipients shortly.