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?
Announcement
Collapse
No announcement yet.
ObjPtr
Collapse
X
-
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 ' ========================================================================================
-
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
Michael Mattias
Tal Systems (retired)
Port Washington WI USA
[email protected]
http://www.talsystems.com
Comment
-
-
Originally posted by Michael Mattias View PostHaven'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
Comment
-
>>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
-
Originally posted by Michael Mattias View PostHaven't tried but why not pass the OBJPTR "AS objecttype PTR"
Comment
-
Comment