Structure Handle

Everything else that doesn't fall into one of the other PB categories.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Structure Handle

Post by SFSxOI »

How do you get the handle of a structure in PureBasic?
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

"Handle" is an unsusual term in PB since it's not OO.
of course you can request handles of API objects,
but internal variables are accessed via pointers.
(like in C, not ++)

the pointer to a structure you'll get like every pointer to a variable:

Code: Select all

Structure Customer
 Num.l
 Name.s
 Debid.l
EndStructure

Define Test.Customer

*pointer = @Test

Test\Num = 42
Test\Name = "George"
Test\Debid = 4711

Debug Test\Num 
Debug *pointer
Debug PeekL(*pointer)

*pointer + 4
Debug PeekL(*pointer)
*stringpointer = PeekL(*pointer)
Debug PeekS(*stringpointer)

*pointer + 4
Debug PeekL(*pointer)
note that the Name field is declared a string, but is also a long that holds the pointer to the string.
infinite strings within structs are stored as pointers.

for structs you want to pass to API-functions it's just the same,
use @Structname within the Call.
oh... and have a nice day.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Kaeru Gaman;

Thanks for your reply. I see now what I was doing wrong. Besides overthinking the problem in the conversion from some C++ code to PB that i'm working on, I wasn't using a pointer to the structure. Your post cleared it up for me, Thank You :)
Post Reply