how do is cast a struct into another struct. for example, OSVERSIONINFOEX to OSVERSIONINFO? any help appreciated.
Posted on 2003-12-10 19:21:21 by evil__donkey

Is this what you need?
Posted on 2003-12-10 20:49:50 by roticv
A structure is just an array of contiguous bytes. The OSVERSIONINFOEX structure is essentially an OSVERSIONINFO structure that has a few extra dwords tacked on the end. You just pass the size of the OSVERSIONINFO structure then read only the relevant bytes. To cast it you do this:


mov osvix.dwOSVersionInfoSize,SIZEOF OSVERSIONINFO ; use only the bytes you want
invoke GetVersionEx,ADDR osvix ; Windows will only fill the bytes requested
.IF osvix.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS

Or you could do this

mov edi,OFFSET osvix
mov eax,[edi].OSVERSIONINFO.dwPlatformId ; cast the pointer as a structure

MASM doesn't care what you say the structure of the bytes is:

mov edi,OFFSET osvix
mov eax,[edi].RECT.left

best bet, only use OSVERSIONINFO, saves alot of compatibility problems.
Posted on 2003-12-10 21:22:47 by donkey
For structures within structures you can use the following :

teststruct struct

rct1 RECT <>
rct2 RECT <>
teststruct ends
ts teststruct <>

mov ts.rct2.left, eax
Posted on 2003-12-10 21:33:47 by donkey
Casting is a high level concept that doesnt directly exists in assembly. (Why love assembly ;) ).

Pointers are pointers, and they are all 32 bits long. Its up to you to use it as you so choose. I could use a RECT structure on you OSVERSIONINFOEX pointer. Masm wont care! In the end its just . So to answer your question, do as donkey has done, decided if you need to use a different structure and use it or not.

Typically the "EX" structure versions have more new fields at the end such that the offsets between the NON-EX an EX version are to the same fields up to the new ones in the EX version. So in this regard, as long as you dont use any new fields, you could use the OSVERSIONINFOEX structure on the pointer and it would be the same result as well. (Assembly gives you options, HLL languages give you headaches ;) )

Posted on 2003-12-13 01:28:51 by NaN