Announcement

Collapse
No announcement yet.

ObjPtr

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

  • ObjPtr

    I am looking for an easy way to access an object created in one sub from a call back function without making the object var global. I can use the ObjPtr to pass a pointer to the callback via the DIALOG SET/GET USER area, but once I am in the callback how to I reference the pointer that was returned by ObjPtr? What is the best (safest) way to manipulate the object within the callback?
    Scott Slater
    Summit Computer Networks, Inc.
    www.summitcn.com

  • #2
    Call this function:

    Code:
    ' ========================================================================================
    ' This function allows to make an object variable from a pointer.
    ' An alternative is to use POKE or MoveMemory, e.g.
    ' POKE DWORD, VARPTR(pUnk), pObj
    ' IF ISOBJECT pUnk THEN pUnk.AddRef
    ' ========================================================================================
    FUNCTION Ptr2Obj (BYVAL pObj AS DWORD) AS IUnknown
       LOCAL pUnk AS IUnknown
       LOCAL pv AS DWORD PTR
       IF pObj = %NULL THEN EXIT FUNCTION
       pv = VARPTR(pUnk)
       @pv = pObj
       IF ISOBJECT(pUnk) THEN
          pUnk.AddRef
          FUNCTION = pUnk
       END IF
    END FUNCTION
    ' ========================================================================================
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Haven't tried but why not pass the OBJPTR "AS objecttype PTR" or retrieve it in your callback (code not shown)

      Best guess..
      Code:
      FUNCTION myCallback (BYVAL hWnd AS LONG, other params ) 
        LOCAL pOBJ AS objectType PTR 
      
        DIALOG GET USER  hWnd, number to pOBJ 
        ...
      
      END FUNCTION
      Is that allowed?
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Is that allowed?
        No.
        Forum: http://www.jose.it-berater.org/smfforum/index.php

        Comment


        • #5
          Originally posted by Michael Mattias View Post
          Haven't tried but why not pass the OBJPTR "AS objecttype PTR" or retrieve it in your callback (code not shown)

          Best guess..
          Code:
          FUNCTION myCallback (BYVAL hWnd AS LONG, other params ) 
            LOCAL pOBJ AS objectType PTR 
          
            DIALOG GET USER  hWnd, number to pOBJ 
            ...
          
          END FUNCTION
          Is that allowed?

          PowerBASIC and related source code. Please do not post questions or discussions, just source code.
          hellobasic

          Comment


          • #6
            >>Is that allowed?
            > No

            Oh, well, it was a thought.

            I've always said if you don't ever have any bad ideas, you don't have enough ideas, period.
            Michael Mattias
            Tal Systems (retired)
            Port Washington WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Originally posted by Michael Mattias View Post
              Haven't tried but why not pass the OBJPTR "AS objecttype PTR"
              I already tried this and it wouldn't allow it. It would however be a great new feature. Maybe time for a feature request.
              Scott Slater
              Summit Computer Networks, Inc.
              www.summitcn.com

              Comment


              • #8
                Originally posted by José Roca View Post
                Call this function:
                Thanks José
                Scott Slater
                Summit Computer Networks, Inc.
                www.summitcn.com

                Comment

                Working...
                X