Some of my older code is not working i think its because I updated the compiler.
I'm copying UDT values into allocated memory.
then i want one of the values from the memory i would just use:
Code: Select all
some_var = *cptr(UDT ptr, some_pointer).some_UDT_fieldname
My question is: Is there a way to get the UDT value from the allocated memory without dimming a udt but only casting as the UDT like in the example below. or maybe there is a new way to do what i'm doing in the function no_longer_works() ?
here is some example test code:
Code: Select all
type UDT
as ulongint a
as ulongint b
end type
'memory to hold data
dim as byte ptr p = CAllocate(1, SizeOf(UDT))
'UDT for inital data, add some values
dim as UDT test_udt
test_udt.a = 18446744073709551615
test_udt.b = 10101010101010101010
'copy the UTD into the allocated memory
*cptr(UDT ptr, p) = test_udt
'Clear the UDT values, because they are now in allowcated memory
test_udt = type<UDT>(0) 'Clear test_udt values to 0
print "test_udt.a = "; test_udt.a
print "test_udt.b = "; test_udt.b
'function to read some data from the memory
'function no_longer_works( p as byte ptr) as ulongint
' return *cptr(UDT ptr, p).b
'end function
function works( p as byte ptr) as ulongint
dim as UDT new_UDT
new_UDT = *cptr(UDT ptr, p)
return new_UDT.b
end function
'print "value from memory = "; no_longer_works(p)
print "value from memory = "; works(p)
Deallocate(p)
sleep