News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

typecast

Started by shashank_tulsyan, November 14, 2006, 02:36:28 PM

Previous topic - Next topic

shashank_tulsyan

I have a pointer to a masm structure.
How can I "typecast" it to it's original type and thus use it directly.
There may be no need of doing this :bg, but I want to know this just for knowlegde sake.

The struct:
xyz STRUCT
   version jint ?
   nOptions jint ?
   options DWORD ?
   ignoreUnrecognized jboolean ?   
xyz ENDS

LOCAL abc:DWORD ;say this is the pointer
LOCAL ste:xyz
   ;ste=(xyz)abc

u

local abc:ptr xyz

Utterly useless, save for readability....? A more readable line would be
local pSTE ; the address of "ste"
Please use a smaller graphic in your signature.

Tedd

There is no actual typecasting involved. And dwords can be considered untyped.
Anyway, what you do is 'type' the pointer when you have its value..


mov edi,ste
assume edi:PTR xyz    ;edi is now 'typed' to the xyz struct

mov eax,[edi].version
mov edx,[edi].options
...etc...

assume edi:nothing    ;turn the typing back off
No snowflake in an avalanche feels responsible.

shashank_tulsyan

Thanks I got it,
I had seen such an example a few days ago.
I don't write in masm generally, that's why I didn't recall it.