Pointers, Objects, Classes ...
-
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
-
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
And if I may ask, what do you wanna do with it? top secret xacc-ide 0.0.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
GCHandle hnd = GCHandle.Alloc(object); InPtr ptr = hnd.AddrOfPinnedObject(); But seriously what are you going to do with it ? :)
-
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
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