Results 1 to 6 of 6

Thread: Pointer to Variant

  1. #1

    Question Pointer to Variant

    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.
    Mike
    (3.6GHz i5 Core Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, x64 Windows 7 Ultimate Sp1)

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    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


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    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.
    Mike
    (3.6GHz i5 Core Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, x64 Windows 7 Ultimate Sp1)

  4. #4
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Yes,

    thinBasic Variant is COM compatible


    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  5. #5
    Petr,


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

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


    Kind regards,
    Mike
    (3.6GHz i5 Core Quad w/ 16GB RAM, nVidia GTX 1060Ti w/ 6GB VRAM, x64 Windows 7 Ultimate Sp1)

  6. #6
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    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
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

Similar Threads

  1. when it's time to use a pointer?
    By largo_winch in forum Sources, Templates, Code Snippets, Tips and Tricks, Do you know ...
    Replies: 3
    Last Post: 01-12-2011, 20:16
  2. Pointer methods
    By Richard in forum Real world situations and solutions using thinBasic
    Replies: 1
    Last Post: 05-02-2010, 00:48
  3. typo VARIANT # & $
    By Michael Clease in forum Fixed or cleared errors in help material
    Replies: 1
    Last Post: 06-11-2007, 16:17
  4. variant parameter
    By kryton9 in forum Power Basic
    Replies: 2
    Last Post: 24-09-2007, 18:52

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •