Click to See Complete Forum and Search --> : Get the address of a variable


cksiow
March 1st, 2001, 12:15 AM
does anyone know how to get the address of a variable in vb.

like in c, we use the operator &, &variable to get the address of the variable

any advise is appreciated

Clearcode
March 1st, 2001, 02:49 AM
There are three undocumented functions in VB5 and 6 that you can use - but bear in mind that they are probably removed by VB.NET:

Dim lAddress as Long
'\\ get address of a variable...
lAddress = VarPtr(variable)
'\\ get address of a string
lAddress = StrPrt(string)
'\\ get address of an object
lAddress = ObjPtr(object)




Bear in mind that these addresses are only valid within your app unless the variables are global.
You should use API functions suct as IsBadStringPointer(), IsBadReadPointer() etc. to validate the address before attemting to pass it to an external DLL or EXE - passing an invalid pointer will cause a GPF.

HTH,
Duncan

-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com