Today I've got an idea of some maybe a little complex, but very interesting way to define Win32 structures. Here's an example of WNDCLASSEX structure macro:


macro struc_setting field,setting
{
field equ
if ~setting eq
if _#setting eq _#field setting
value equ setting
restore field
defined.#field = value
restore value
end if
end if
}

struc WNDCLASSEX [param]
{ common
if param eq ?
.cbSize dd ?
.style dd ?
.lpfnWndProc dd ?
.cbClsExtra dd ?
.cbWndExtra dd ?
.hInstance dd ?
.hIcon dd ?
.hCursor dd ?
.hbrBackground dd ?
.lpszMenuName dd ?
.lpszClassName dd ?
.hIconSm dd ?
else
defined.cbSize = .size
defined.style = 0
defined.lpfnWndProc = 0
defined.cbClsExtra = 0
defined.cbWndExtra = 0
defined.hInstance = 400000h
defined.hIcon = 0
defined.hCursor = 0
defined.hbrBackground = COLOR_WINDOW+1
defined.lpszMenuName = 0
defined.lpszClassName = 0
defined.hIconSm = 0
forward
struc_setting cbSize,param
struc_setting style,param
struc_setting lpfnWndProc,param
struc_setting cbClsExtra,param
struc_setting cbWndExtra,param
struc_setting hInstance,param
struc_setting hIcon,param
struc_setting hCursor,param
struc_setting hbrBackground,param
struc_setting lpszMenuName,param
struc_setting lpszClassName,param
struc_setting hIconSm,param
common
.cbSize dd defined.cbSize
.style dd defined.style
.lpfnWndProc dd defined.lpfnWndProc
.cbClsExtra dd defined.cbClsExtra
.cbWndExtra dd defined.cbWndExtra
.hInstance dd defined.hInstance
.hIcon dd defined.hIcon
.hCursor dd defined.hCursor
.hbrBackground dd defined.hbrBackground
.lpszMenuName dd defined.lpszMenuName
.lpszClassName dd defined.lpszClassName
.hIconSm dd defined.hIconSm
.size = $-.cbSize
end if }

This macro can be used in three ways. If you use it without any parameters:


wc WNDCLASSEX

it will define the structure with fields filled with default values. If you use "?" parameter:


wc WNDCLASSEX ?

the structure will have undefined fields (this is the one you can put in .udata section). And finally you can define any fields you want with your values like in this example:


wc WNDCLASSEX,\
lpfnWndProc WndProc,\
cbWndExtra 4

It fills wc.lpfnWncProc with address of WndProc and wc.cbWndExtra with dword 4.

If anyone finds this method useful, we can make a small program for converting standard structure macros (or MASM structure definitions) into this kind of stuff.
Posted on 2002-12-03 16:30:04 by Tomasz Grysztar
Another variant:


macro struc_setting field,setting
{
field equ
if ~ <setting> eq <>
if <_#setting> eq <_#field setting>
value equ setting
restore field
defined.#field value
restore value
end if
end if
}

struc WNDCLASSEX [param]
{ common
if <param> eq <?>
.cbSize dd ?
.style dd ?
.lpfnWndProc dd ?
.cbClsExtra dd ?
.cbWndExtra dd ?
.hInstance dd ?
.hIcon dd ?
.hCursor dd ?
.hbrBackground dd ?
.lpszMenuName dd ?
.lpszClassName dd ?
.hIconSm dd ?
else
defined.cbSize = .size
defined.style = 0
defined.lpfnWndProc = 0
defined.cbClsExtra = 0
defined.cbWndExtra = 0
defined.hInstance = 400000h
defined.hIcon = 0
defined.hCursor = 0
defined.hbrBackground = 0
defined.lpszMenuName = 0
defined.lpszClassName = 0
defined.hIconSm = 0
forward
struc_setting cbSize,param
struc_setting style,param
struc_setting lpfnWndProc,param
struc_setting cbClsExtra,param
struc_setting cbWndExtra,param
struc_setting hInstance,param
struc_setting hIcon,param
struc_setting hCursor,param
struc_setting hbrBackground,param
struc_setting lpszMenuName,param
struc_setting lpszClassName,param
struc_setting hIconSm,param
common
.cbSize dd defined.cbSize
.style dd defined.style
.lpfnWndProc dd defined.lpfnWndProc
.cbClsExtra dd defined.cbClsExtra
.cbWndExtra dd defined.cbWndExtra
.hInstance dd defined.hInstance
.hIcon dd defined.hIcon
.hCursor dd defined.hCursor
.hbrBackground dd defined.hbrBackground
.lpszMenuName dd defined.lpszMenuName
.lpszClassName dd defined.lpszClassName
.hIconSm dd defined.hIconSm
.size = $-.cbSize
end if }

And then:


wc WNDCLASSEX,\
lpfnWndProc = WndProc,\
cbWndExtra = 4


You won't believe how incredible playing with own program sometimes is. ;) :grin:
Posted on 2002-12-03 16:38:08 by Tomasz Grysztar
Everytime you play we get more toys! :alright:
Posted on 2002-12-03 16:51:38 by bitRAKE
woow this is nice. :alright: I wish I had the time to explore FASMs macro capabilities. :)
Posted on 2002-12-03 16:59:44 by stryker
The MASM32 by Hutch has a good file of API-definition (WINDOWS.INC). It was
rather well to convert automatically him for the use in FASM, taking into account
foregoing. :cool:
Certainly, from Hutch permission.
Thank You.
Posted on 2002-12-09 11:54:24 by tserk