Message board for the users of flat assembler.
> Windows > "struc" and "struct"
i read on the forum about the use of struct.
but i dont understand why "struct" is needed, when struc works.
im new to assembly so this might just be one off that struc works.
format PE GUI 4.0
section '.text' code readable executable
.left dd ?
.top dd ?
.right dd ?
.bottom dd ?
push 0 ; MB_OK
push 0 ; HWND_DESKTOP
section '.data' data readable writeable
msg_buffer rb 32
msg_title db "Current cursor pos", 0
buffer_format db "left=%d top=%d", 0
section '.idata' import data readable writeable
library kernel32, 'KERNEL32.DLL', user32, 'USER32.DLL'
import kernel32, ExitProcess, 'ExitProcess'
import user32, MessageBox, 'MessageBoxA', GetCursorPos, 'GetCursorPos', wsprintf, 'wsprintfA'
the program gets the current cursor position and prints it in a message box.
i am unsure about why struc cant be used instead of "struct" macro, as i used it here to print it in the message box by using the MYRECT members.
also, win32 calls are stdcall and "wsprintf" is CDECL, is what i am doing here with the stack correct ?
or am i meant to pop some stuff after the wsprintf call ?
off to find some more info on them, and the documentation.
|30 Apr 2005, 16:53||
I think struc defines the structure but struct actually creates the structure at compile time, so I end up writing:
.X dd ?
.Y dd ?
otherwise I get a compile error
|01 May 2005, 00:32||
cod3b453: you're using the old "struct" macro, the newest packages support this kind of syntax:
struct POINT .X dd ? .Y dd ? ends
As for the wisepenguin's question:
The "struc" directive defines the structure in a way that it defines a kind of macro, which can be then used to declare different instances of that structure.
The "struct" (in its new version) is a macro which does the same, but defines also some additional values (like the absolute field offsets and structure size) for the convenience of programmer. It was made only to make it more like the structure definitions are in other assemblers, but it's only a macro (which uses internally the "struc" definition anyway), and it's not as flexible as the "struc" directive itself. If you understand how the "struc" works (and are not biased by other assemblers' approach), it's better for you to use the "struc" and take advantage of all capabilities it gives.
In fact I personally don't recommend using the "struct" macro, even though it is used in official includes - but I've done it to satisfy the expectations of people used to structure implementations in assemblers like TASM and NASM. In my vision (based on which I have designed the "struc" mechanism for flat assembler) defining absolute structure offsets is a wrong choice and structure should be declared independently for its each appearance and usage - even when you've got dynamically allocated structure, you can do it with "virtual" directive, like:
virtual at ebx mystruc@ebx MYSTRUC end virtual
Note that "struc" directive allows definitions of structures that have variable sizes and field offsets depending on instance, and perhaps depending on some additional parameters (you can define them with all the freedom you've got with macroinstructions in fasm) - this is where the idea of absolute offsets and size completely fails.
I plan to write something more about it in the fifth section of my Design Principles article, which is not yet finished (even though officially published on this website).
|01 May 2005, 08:21||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar.
Powered by rwasa.