Results 1 to 5 of 5

Thread: Memory Access in VB.Net

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    30

    Memory Access in VB.Net

    Hi Folks,

    Quick question - is it possible to access a memory address using vb.net?

    For example, if i want to access the memory address 0x00000002 I can type this in C#:

    private const int th32CS_SNAPPROCESS = 0x00000002;

    But when I try what I think the vb.net version should be:

    Private Const th32cs_SnapProcess As Int32 = 0x00000002

    However, VS doesnt seem to like this code.

    Any ideas why? Is it possible to access memory in vb.net?

    All suggestions gratefully recieved!

    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Memory Access in VB.Net

    The hexadecimal prefix in VB is "&H", not "0x". VB.NET doesn't support pointers though, so a memoery address won't do you much good.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2005
    Posts
    30

    Re: Memory Access in VB.Net

    Cheers for the advice!

  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: Memory Access in VB.Net

    I believe you can use the Marshal class to go in and out of managed memory if that helps any
    KrisSiegel.com - My Personal Website with my blog and portfolio
    Don't Forget to Rate Posts!

    Free Icons: FamFamFam, VBCorner, VBAccelerator
    Useful Links: System.Security.SecureString Managed DPAPI Overview Part 1 Managed DPAPI Overview Part 2 MSDN, MSDN2, Comparing the Timer Classes

  5. #5
    PowerPoster
    Join Date
    Jul 2002
    Location
    Dublin, Ireland
    Posts
    2,148

    Re: Memory Access in VB.Net

    Note that the memory model in the CLR does not guarantee that a variable will stay at the same address - the GC can move things around to make a bit of space. If you have to reference a variable by address (and I suggest that you don't really) then you have to "pin" it to prevent it being moved.

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