Yes, but I still wanted to do this by comparing objects. I want to know how to get a variable pointer as IntPtr and how to read from unknown type object from a specific place.
Tambi Ashmoz
Posts
-
Pointers,Classes,Objects... II -
Pointers,Classes,Objects... IIHow can I get a variable pointer (as IntPtr) ? I am trying to compare between two objects, the objects are not the same but they could be from some place ... Example - let say we have two classes one derived from another ... public class A { protected h=0; public virtual func() { h=0; } } public class B:A { public override func() { h=1; } } Now ... I'am creating the objects ... obj1=Activator.CreateInstance(t1); //Type t1; class A c.Invoke(obj1,null); //ConstructorInfo c; getting constructor from class A the same with the other class... obj1=Activator.CreateInstance(t2); //Type t2; class B c.Invoke(obj2,null); //ConstructorInfo c; getting constructor from class B From this point you can see in the debugger obj1,obj2 (with the variable h=0 in both) Now I'am invoking my function... //MethodInfo m1,m2; getting my virtual AND override functions each from it's class ... and after that running functions , with null as parametter... object []parametersForFunction=new object[m1.GetParameters().Length]; //m1 or m2 doesn't matter they have the same parameters... virtual,override m1.Invoke(obj1,parametersForFunction); m2.Invoke(obj2,parametersForFunction); I can't check "h" with the GetFields() couse its not public().. My problem is here... Now if wee go back to the debugger we can see that in obj1.h=0 and obj2.h=1 Somthing like this obj1.A.h=0 obj2.B.A.h=1 My idea was to try the Marshal.ReadIntPtr(IntPtr,offset) so I can read obj2 after some offset, So I needed my variable Address. (somehow even in unsafe we cant do object *p=obj1; on objetcs...) I tried Marshel.ReadByte and it's not working cause my object type could be anything... Anyone have some idea ??? Thanks
-
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