CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2000
    Posts
    737

    Get the address of a variable

    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


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Get the address of a variable

    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
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured