Access class fields from asm

Carl Volhard CarlVolhard at web.de
Thu Jun 28 06:16:09 PDT 2007


Curiously this way works
    foo.b.offsetof

although the documentation says
    FooBar.b.offsetof
is the correct way. But this code generates the following compile errors:

> Error: 'this' is only allowed in non-static member functions, not main
> Error: this for b needs to be type FooBar not type int


BCS Wrote:

> Reply to Carl,
> 
> > How can i access non-static class fields?
> 
> try somthing like this (I haven't even tried to compile this)
> 
> public class FooBar {
>   public int b = 8;
> }
> FooBar foo = new FooBar(); // foo is a pointer
> asm{
>  mov EBX, foo;    // load by value
>  mov EAX, [EBX+FooBar.b.offsetof]; //offset from pointer
> }  
> 
> 



More information about the Digitalmars-d-learn mailing list