Announcement

Collapse
No announcement yet.

When MSDN says "pointer to structure", what is proper PB translation?

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

  • When MSDN says "pointer to structure", what is proper PB translation?

    When the SDK Help for an API call says that a parameter should be a "pointer to a structure", is it asking for an address or a handle?

    Sorry to be dense on this topic, but the MSDN definition of "pointer to structure" is not clear to me, and when I read the PB Help for STRPTR, VARPTR, and ASCIIZ PTR, I get pretty lost.

    I'm trying to use this:

    BOOL TrackMouseEvent(

    LPTRACKMOUSEEVENT lpEventTrack // pointer to a TRACKMOUSEEVENT structure
    );

    So in PB code, I need:

    Code:
          Local tme As trackmouseeventapi
    and, (here's what I'm not sure of):

    Code:
          Local tme_ptr As String Ptr
    Then, to make the call (besides setting the other members), I need what?

    Code:
          TrackMouseEvent(@tme_ptr)

    Can anyone provide a clear explanation of what I need here and why?

    Thanks!

  • #2
    If you pass a variable BYREF it will pass the pointer to the memory.
    So:
    Local p as RECT
    TheFunction( p )
    would do if you have declared TheFunction() like:
    Delcare TheFunction lib "...." Alias .... ( BYREF R AS RECT )
    hellobasic

    Comment


    • #3
      TrackMouseEvent is already defined in win32api.inc:

      Code:
      DECLARE FUNCTION TrackMouseEvent LIB "USER32.DLL" ALIAS "TrackMouseEvent" (lpEventTrack AS TRACKMOUSEEVENTAPI) AS LONG
      So in PB code, you need:

      Code:
      Local tme As trackmouseeventapi
      Then, to make the call (besides setting the other members), you need:

      Code:
      TrackMouseEvent(tme)
      Why?

      Because if a parameter is declared BYREF, PB passes a pointer to the variable.
      Last edited by José Roca; 18 Feb 2009, 05:09 PM.
      Forum: http://www.jose.it-berater.org/smfforum/index.php

      Comment


      • #4
        I was incorrectly expecting that the pointer had to be defined explicitly, and now I have a process for how to analyze what's needed - after reading the MSDN, I should have checked the PB DECLARE...

        Thanks Edwin for the example, and Jose for the clarification!

        Comment


        • #5
          It is fundamental to understand calling conventions and parameters passing.

          You could also declare the function as:

          Code:
          DECLARE FUNCTION TrackMouseEvent LIB "USER32.DLL" ALIAS "TrackMouseEvent" (BYVAL lpEventTrack AS TRACKMOUSEEVENTAPI PTR) AS LONG
          and use it as:

          Code:
          LOCAL tme AS TRACKMOUSEEVENTAPI
          tme.cbSize = SIZEOF(TRACKMOUSEEVENTAPI)
          tme.dwFlags = %TME_LEAVE
          tme.hwndTrack = hwnd
          tme.dwHoverTime = 1
          TrackMouseEvent(VARPTR(tme))
          or, using the equivalent to C code:

          Code:
          LOCAL ptme AS TRACKMOUSEEVENTAPI PTR
          @ptme.cbSize = SIZEOF(TRACKMOUSEEVENTAPI)
          @ptme.dwFlags = %TME_LEAVE
          @ptme.hwndTrack = hwnd
          @ptme.dwHoverTime = 1
          TrackMouseEvent(ptme)
          In the three cases, the result is the same: A pointer to a TRACKMOUSEEVENTAPI structure is pushed into the stack.
          Forum: http://www.jose.it-berater.org/smfforum/index.php

          Comment


          • #6
            José, in your second example, to a newbie, it's not pointing out that you need to have the pointer variable pointing to a valid structure to succeed.
            Code:
            LOCAL tme AS TRACKMOUSEEVENTAPI
            LOCAL ptme AS TRACKMOUSEEVENTAPI PTR
            
            ptme = VARPTR(tme)
            ...
            Also, would not calling the function and enforcing BYREF generate the pointer for you?
            code TrackMouseEvent(BYREF tme)/code
            Last edited by colin glenn; 18 Feb 2009, 11:22 PM. Reason: oh, never mind, reread of your first post, ...
            Furcadia, an interesting online MMORPG in which you can create and program your own content.

            Comment


            • #7
              Yes. This is what happens when you post code without testing it first
              Forum: http://www.jose.it-berater.org/smfforum/index.php

              Comment


              • #8
                I tried pretty hard to explain that sort of thing throughout my Beginning Api Programming Example series over in Jose's Forum...



                Like Jose said, its not even barely possible to comprehend the Api documentation without understanding this, it is so fundamental. The thing is, if you have been programming in a BASIC dialect for ten years, you have been using pointers for ten years perhaps without even knowing it.
                Fred
                "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

                Comment


                • #9
                  Wow! What a goldmine! Thanks Fred (and Jose for hosting)!!!

                  there goes the rest of my weekend!

                  Comment

                  Working...
                  X