Today I have been experimenting with DBP and the function stack, through use of C++ and inline assembly. I've managed to work out how to access the address of local variables of a function, as well as parameters. I'd imagine this will be very useful to some as it means you can now pass the address of variables into functions, essentially allowing you to return multiple values. Of course, this doesn't work in the global scope, but one thing at a time.
There are two functions:
get local variable ptr which gets the address of a specified local variable, and
get parameter variable ptr which gets the address of a specified function parameter. Variable numbers start at zero.
One of the uses of this is when you want to return multiple variables from a function. You simply pass the pointers, and in the function you write to these pointers using the * symbol.
Example:
MyFunction(100, 200)
wait key
end
function MyFunction(param1 as integer, param2 as integer)
local myVar as integer = 2
local myVar2 as integer = 3
ptr = get local variable ptr(0)
ptr2 = get local variable ptr(1)
pPtr = get parameter variable ptr(0)
pPtr2 = get parameter variable ptr(1)
print "Local pointer #1: " + str$(*ptr)
print "Local pointer #2: " + str$(*ptr2)
print "Parameter pointer #1: " + str$(*pPtr)
print "Parameter pointer #2: " + str$(*pPtr2)
ChangeIt(ptr, ptr2)
print "Values changed..."
print "Local pointer #1: " + str$(*ptr)
print "Local pointer #2: " + str$(*ptr2)
endfunction
function ChangeIt(ptr as dword, ptr2 as dword)
*ptr = 25
*ptr2 = 300
endfunction
The DLL is attached.
Quote: "Notes
When declaring variables, the following syntax will mess up pointers:
local myVar as integer : myVar = 1
local myVar2 as integer : myVar2 = 2
You must not put any instructions in between declarations as above. If you want to assign values to variables straight away, you can do it like this:
local myVar as integer = 1
local myVar2 as integer = 2
"