Hi guys,

inside a wndproc, i am processing the WM_MOUSEMOVE
message, and inside that message i want to create a
RECT and POINT structs, like this:

[size=12]

WndProc proc uses edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

.IF uMsg == WM_MOUSEMOVE
[color=red]
LOCAL pt :POINT
LOCAL rect :RECT
[/color]
...code...
...code...
...etc....[/size]


but, if i have it correct, MASM will reorganise that code and
compile it in such a way that it comes out the same as if i had
written it this way:

[size=12]

WndProc proc uses edi hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
[color=red]
LOCAL pt :POINT
LOCAL rect :RECT
[/color]
.IF uMsg == WM_MOUSEMOVE
...code...
...code...
...etc....
[/size]


Am i correct with this? If i am correct, what is the best way to
create those structs ONLY when processing the WM_MOUSEMOVE
message? (*without* branching to a subroutine). It just seems
wasteful to create them every time i enter the wndproc, when
they are only used for one message.
Posted on 2002-07-08 07:29:12 by sluggy
I just compiled a little test app and masm wouldn't accept any locals if they where after code. To do what you want I think you would have to manually adjust the stack yourself.
Posted on 2002-07-08 07:38:01 by Kudos
I tried that once. MASM only likes the LOCAL directive after a PROC directive.
Posted on 2002-07-08 07:52:35 by ThoughtCriminal
Sluggy Your are trying to allocate the locals at runtime. It can't be automatically done with compiled code.


Actually I just remembered a post by the svin he daid you could use the proc directive to make variables localised
Posted on 2002-07-08 09:41:43 by MArtial_Code
sluggy, there isn't any problem in allocating the locals "all the time",
the only difference will be the amount subtracted from esp at the
procedure entry. Well, ok, if you were doing a lot of *huge* locals
this way there could theoretically be a problem because of the way
the stack grows (guard pages), but for stuff this small, don't worry :).
Posted on 2002-07-08 09:52:05 by f0dder
First of all, MASM assembles, it does not compile. :D
As to many locals, I agree with f0dder. I once wrote a very sloppy recursive directory lister which used about half a kilobyte of stack for local variables, and it would cause a stack underflow. Very inefficient. The rewritten version ended up using only 4 bytes for a local variable. :P
Posted on 2002-07-08 12:04:24 by comrade
Why not just call a proc when the message is received?

For any message that does much work a write that into a proc, it also helps keeping WndProc from being so huge

gorshing
Posted on 2002-07-08 16:29:34 by gorshing
f0dder & comrade,
i guess i was just looking for an unnecessary optimisation. I was actually in the middle of transcribing some C code, and of course you can do that in C.


gorshing,
of course, that is an option, but i figured that a jump to a sub would negate any benefit i gained through not declaring the vars at the start. If i was declaring heaps of vars for a message that occurred often, i would definately put it in a sub. But like i said above, i was just trying to be needlessly tight with my code :)
Posted on 2002-07-08 16:52:12 by sluggy