Address of a variable: Difference between revisions

Line 231:
 
<lang Creative Basic>
To get the address of a variable without using the Windows API:
 
DEF X:INT
DEF pPointer:POINTER
pPointer=X
'To print in the console after opening it with the OPENCONSOLE command.
PRINT pPointer
'To print in an open window add the appropriate Window variable
'("Win" here) followed by a comma.
PRINT Win,pPOINTER
 
To get the address of a variable using the Windows API Lstrcpy called in Creative Basic:
(This may give users of another language without a native way to get the address of a variable to work around that problem.)
 
DEF Win:WINDOW
DEF Close:CHAR
DEF ScreenSizeX,ScreenSizeY,Col:INT
 
'*Map Function
DECLARE "Kernel32",Lstrcpy(P1:POINTER,P2:POINTER),INT
 
'Note: This is translated from VB5 or VB6 Code, and "Ptr" is *not* a Creative Basic pointer.
DEF Ptr:INT
DEF X1:INT
DEF X2:STRING
 
X1=123
 
'Call function
Ptr=Lstrcpy(X1,X1)
GETSCREENSIZE(ScreenSizeX,ScreenSizeY)
 
WINDOW Win,0,0,ScreenSizeX,ScreenSizeY,@MINBOX|@MAXBOX|@SIZE|@MAXIMIZED,0,"Skel Win",MainHandler
 
'Display address
PRINT Win, "The address of x1 is: " + Hex$(Ptr)
X2="X2"
 
WAITUNTIL Close=1
 
CLOSEWINDOW Win
 
END
 
SUB MainHandler
 
SELECT @CLASS
 
CASE @IDCLOSEWINDOW
 
Close=1
 
ENDSELECT
 
RETURN
 
Note: The Windows Dev Center (http://msdn.microsoft.com/en-us/library/windows/desktop/ms647490%28v=vs.85%29.aspx) says
improper use of the Lstrcpy function may compromise security. You are advised to see the Windows Dev site before using
the Lstrcopy function.
 
The address can also be printed in console window by issuing the OPENCONSOLE command followed by the PRINT command.
 
There does not appear to be a way to set the address of a variable in Creative Basic.