Since I often see a thread where someone asks about using esp, removing the leave instruction, no stack-frames, no-locals etc. I present the no stack-frame, no locals, no proc MsgProc!!
Since the parameters where already on the stack, I just set esp to the right place before the call. Reused stack space.
I don't advocate programming this way. I did it just to see if I could.
Discuss amongst yourselves...
MsgProc:
mov eax, [esp+8] ;uMsg
.IF eax==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSE
mov edi, [esp] ;save esp top contents from being trashed.They will be trashed
add esp,4 ; mov esp, esi ;advance esp to address of hWnd
call DefWindowProc
sub esp,20 ;fix esp, 16 for parms, 4 for advance
mov [esp],edi ;restore trashed esp top contents
ret ;jumps somewhere, probably kernerl32, but hey, it works...
.ENDIF
xor eax,eax ;dont think we ever get here
ret
Since the parameters where already on the stack, I just set esp to the right place before the call. Reused stack space.
I don't advocate programming this way. I did it just to see if I could.
Discuss amongst yourselves...
ret ;jumps somewhere, probably kernerl32, but hey, it works...
I like this line :)
If you want a shorter one:
For Frame-Based Procedure:
pop ebp
jmp DefWindowProc
For Non-Frame-Based Procedure:
jmp DefWindowProc
:grin:
For Frame-Based Procedure:
pop ebp
jmp DefWindowProc
For Non-Frame-Based Procedure:
jmp DefWindowProc
:grin:
MsgProc:
cmp [esp+8], WM_DESTROY ; uMsg
je @F
jmp DefWindowProc
@@: invoke PostQuitMessage, NULL
ret 4*4 ; be nice :)
bAZiK,
The only lib I had included was kernel32. The ret whent to an address like 77de****, so I'd say kernel32.
I have been spending alot of time lately trying to figure out a coding style that fits how I think. I think it is PROCless.
No more prototypes, no more inc file of prototypes. Easy use of public and extern. Now I set up my proc like this:
I spent alot of effort to find a way that would give me informative diassembly when debugging.
My PLCALL will dissassemble to:
call [_procname(0000000)]
not call ($$$0001)
Declaring (procdata) pubilc, makes all data below public with just one extern. In an alternate file, I will still get real names.
mov eax, data1
will stay the same not
mov eax, procname+4
THe above was just a quick(first draft) test with something I didn't write.
The only lib I had included was kernel32. The ret whent to an address like 77de****, so I'd say kernel32.
I have been spending alot of time lately trying to figure out a coding style that fits how I think. I think it is PROCless.
No more prototypes, no more inc file of prototypes. Easy use of public and extern. Now I set up my proc like this:
...all the lib includes, .686 etc.
public (procname)
public (procdata)
.data
(procdata) label dword
data1 dword 0
data2 dword 0
.code
(procname) dd offset @(procname);pointer for indirect call to proc
@(procname):
pop esi
....do stuff here
jmp esi
end
Prototype to make calls work:
LCALL TYPEDEF proto;label call
PLCALL TYPEDEF PTR LCALL
extern (procname):proc
extern (procdata):dword ;public and extern are now easy!!
call PLCALL (procname)
I spent alot of effort to find a way that would give me informative diassembly when debugging.
My PLCALL will dissassemble to:
call [_procname(0000000)]
not call ($$$0001)
Declaring (procdata) pubilc, makes all data below public with just one extern. In an alternate file, I will still get real names.
mov eax, data1
will stay the same not
mov eax, procname+4
THe above was just a quick(first draft) test with something I didn't write.
You really thing your code is still readable for human beeing? :rolleyes:
:grin:
:grin:
Sorry, dont have time to type nicely right now:
Hope this is a little easier to read.
------------------------------------------------------------------------
...all the lib includes, .686 etc.
public fooproc
public foodata
.data
foodata label dword
data1 dword 0
data2 dword 0
.code
fooproc dd offset @fooproc ;pointer for indirect call to proc
@fooproc:
pop esi
....do stuff here
jmp esi
end
-----------------------------------------------------------------------------
In another file:
extern fooproc:proc
extern foodata:dword ;public and extern are now easy!!
.code
call PLCALL fooproc
-----------------------------------------------------------------------------
Prototype to make calls work:
LCALL TYPEDEF proto ;label call
PLCALL TYPEDEF PTR LCALL
Hope this is a little easier to read.