I want a local variable My_Variable to be a pointer to structure MY_STRUCT.
My_Function returns a pointer to MY_STRUCT and I want to store it in My_Variable.
How to do that?
MY_STRUCT STRUCT
My_StructMember DD 0
....
MY_STRUCT ENDS
LOCAL My_Variable:PTR MY_STRUCT ;???
invoke My_Function
mov My_Variable, eax
mov eax, My_Variable.My_StructMember
This code doesn't work.
:stupid:
My_Function returns a pointer to MY_STRUCT and I want to store it in My_Variable.
How to do that?
MY_STRUCT STRUCT
My_StructMember DD 0
....
MY_STRUCT ENDS
LOCAL My_Variable:PTR MY_STRUCT ;???
invoke My_Function
mov My_Variable, eax
mov eax, My_Variable.My_StructMember
This code doesn't work.
:stupid:
???
I would just go like this:
mov eax, offset My_Struct
mov ecx,.My_Struct.My_Variable
or if you want to save the Pointer:
LOCAL My_Struct_Pointer:DWORD
lea eax,My_Struct
mov My_Struct_Pointer,eax
or if you want to have a fixed My_Struct_Pointer at all times:
.data
My_Struct_Pointer dd OFFSET My_Struct
.code
I would just go like this:
mov eax, offset My_Struct
mov ecx,.My_Struct.My_Variable
or if you want to save the Pointer:
LOCAL My_Struct_Pointer:DWORD
lea eax,My_Struct
mov My_Struct_Pointer,eax
or if you want to have a fixed My_Struct_Pointer at all times:
.data
My_Struct_Pointer dd OFFSET My_Struct
.code
the way you are doing it is not correct.
structure members are referenced as an offset from the structure label(address).
you cannot do memory indirection from a memory location so...
invoke My_Function
mov My_variable,eax ;store the pointer to the structure
mov ecx,(MY_STRUCT ptr).My_StructMember
structure members are referenced as an offset from the structure label(address).
you cannot do memory indirection from a memory location so...
invoke My_Function
mov My_variable,eax ;store the pointer to the structure
mov ecx,(MY_STRUCT ptr).My_StructMember
Now I see...
Thanks, guys.
Thanks, guys.