PDA

View Full Version : Pointer to Variant



mike lobanovsky
15-12-2013, 05:33
Hello gurus,

Is it possible to obtain a pointer to Long (and generally numeric) and String data contained in a Variant variable?

Any help would be much appreciated.

Petr Schreiber
15-12-2013, 16:17
Something to get you started, for Long:


Uses "Console"

PrintL "Assign long to variant:"

Variant v
v = 123 As Long

PrintL "v = " + Variant#(v)

PrintL
PrintL "Assign another number by doing memory overlay stunt:"
Long vptr = VarPtr(v)+8
Long l At vptr

l = 456
PrintL "v = " + Variant#(v)

PrintL
PrintL "Assign another number by doing poke :"
Poke(Long, vptr, 789)

PrintL "v = " + Variant#(v)

WaitKey


You can learn more about VARIANT internals for example here:
VBA Internals: Variant Variables and Pointers in Depth (http://bytecomb.com/vba-internals-variant-variables-and-pointers-in-depth/)


Petr

mike lobanovsky
15-12-2013, 16:50
Petr,

That clears up things for me a bit. I've just got to make sure a thinBasic Variant is an ordinary COM variant without any proprietary deviations.

Thanks much for your help.

Petr Schreiber
15-12-2013, 16:53
Yes,

thinBasic Variant is COM compatible :)


Petr

mike lobanovsky
15-12-2013, 17:09
Petr,


Is it :) or ;) ? Then what the other 48 bits following VARTYPE are used for in thinBasic?

Of course I'm just LOL-ing... :D


Kind regards,

Petr Schreiber
17-12-2013, 11:35
Hehe,

Eros added Variants specifically for use with COM, if I remember correctly - they worked well in my tests.
For more technical background it is better to wait for his reply, but I am afraid he is kind of flooded by real-world work recently.


Petr