Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Pointers, Objects, Classes ...

Pointers, Objects, Classes ...

Scheduled Pinned Locked Moved C#
questioncsharp
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tambi Ashmoz
    wrote on last edited by
    #1

    How can I get the address of an object (as IntPtr) or any other variable type ? Though I could get a variable address in unsafe, (or maybe there is a better c# way ... I dont know) unsafe { int x=0; int *p=&x; } With objects it's not working, and still I have to convert it from int* to IntPtr ... Thanks

    L T S 3 Replies Last reply
    0
    • T Tambi Ashmoz

      How can I get the address of an object (as IntPtr) or any other variable type ? Though I could get a variable address in unsafe, (or maybe there is a better c# way ... I dont know) unsafe { int x=0; int *p=&x; } With objects it's not working, and still I have to convert it from int* to IntPtr ... Thanks

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      And if I may ask, what do you wanna do with it? top secret xacc-ide 0.0.1

      1 Reply Last reply
      0
      • T Tambi Ashmoz

        How can I get the address of an object (as IntPtr) or any other variable type ? Though I could get a variable address in unsafe, (or maybe there is a better c# way ... I dont know) unsafe { int x=0; int *p=&x; } With objects it's not working, and still I have to convert it from int* to IntPtr ... Thanks

        T Offline
        T Offline
        t3rmin4t0r
        wrote on last edited by
        #3

        GCHandle hnd = GCHandle.Alloc(object); InPtr ptr = hnd.AddrOfPinnedObject(); But seriously what are you going to do with it ? :)

        1 Reply Last reply
        0
        • T Tambi Ashmoz

          How can I get the address of an object (as IntPtr) or any other variable type ? Though I could get a variable address in unsafe, (or maybe there is a better c# way ... I dont know) unsafe { int x=0; int *p=&x; } With objects it's not working, and still I have to convert it from int* to IntPtr ... Thanks

          S Offline
          S Offline
          softp_vc
          wrote on last edited by
          #4

          If you are trying to read the contents of a specific address without knowing what type of data is held there, then one way of doing it is to call: Marshal.PtrToStringAnsi(ptr, length) where 'ptr' represents the address of the first byte and 'length' the number of bytes to be read. This returns the data in the form of a managed string (with each byte expanded to a 2-byte unicode character), which you can then examine Naveen

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups