CODEPTR function

Purpose

Obtain a 32-bit address of a label, Sub or Function.

Syntax

address32 = CODEPTR({label | functionname | subname})

Remarks

CODEPTR is particularly useful when it is necessary to pass the address of a SUB or FUNCTION to Windows for callbacks.  address32 must be a Long-integer (LONG) or Double-word (DWORD) variable.

Restrictions

Pointers may not be obtained for labels that are outside the scope of the current Sub or Function.  Labels have local scope in current versions of PowerBASIC.

See also

STRPTR, VARPTR, CALL DWORD

Example

#COMPILE EXE
SUB MySub()

END SUB

 

FUNCTION PBMAIN

  LOCAL MySubPtr AS LONG, X AS STRING

  MySubPtr = CODEPTR(MySub) ' Address of MySub()

  X = "MySub() is located at address " + _

      FORMAT$(MySubPtr))

END FUNCTION