Did a search and read some articles, but they do not answer "My" question.

I gave GRiFLE for a test here and people with Win9x had a major lockup and I found it was because I didn't preserve a register in a proc. But, I didn't preserve a register in other procs and all is fine. Also, why does Win9x puke on things like this, but NT OS's don't?

When do I have to preserve registers in a proc? I know I am supposed to preserve ebx, esi, and edi (I don't use the other 2)
1. because that is the standard (so other programmers can use my proc, but they won't)
2. if I need those the same values I had before the proc.

Do I have to preserve with callbacks\subclasses? Like when I subclass a window and in the subclass proc I use edi, esi, ebx... do I *have to* preserve them? in a paint proc that gets called from WM_PAINT, do I *Have to* preserve them?

I don't have to preserve eax, ecx, edx unless I need those values unchanged when the proc returns, correct?

All the differant code I see, everyone does something differant!

Can someone shed a little more light on this?

TIA
Posted on 2003-01-19 09:27:22 by Gunner
You always have to preserve them. Windows uses them internally in-between calls to your code.
Posted on 2003-01-19 11:19:49 by comrade
XP doesn't seem to mind for a DlgProc and maybe for other callbacks but 98 totally goes down (for me) if i don't preserve. You need to preserve ebp, ebx, esi and edi (and esp if the function is stdcall, which callbacks are). The other main registers (ecx etc.) needn't be preserved.

-stormix
Posted on 2003-01-19 16:29:34 by stormix

XP doesn't seem to mind for a DlgProc and maybe for other callbacks but 98 totally goes down (for me) if i don't preserve. You need to preserve ebp, ebx, esi and edi (and esp if the function is stdcall, which callbacks are). The other main registers (ecx etc.) needn't be preserved.

-stormix


It was reverse for me.
Posted on 2003-01-19 18:43:30 by comrade
Yeah it's weird... I can get away with not preserving any callback procs in Win98 but if I forget to preserve in one of my procs, Win98 takes a bomb.... I will just preserve anything I use in any procs just to be safe....
Posted on 2003-01-19 22:00:18 by Gunner
gunner, you only have to preserve regs in callbacks. the list given before, ebx/esi/edi/ebp is correct. another thing... it's quite obvious that you must preserve esp, but a not-so-wellknown fact is that esp also has to be dword aligned.
Posted on 2003-01-20 02:45:02 by f0dder
It all depends on whether you are the caller or the the callee.

========

Caller save registers: These registers must be saved by the caller if the caller needs them unchanged.

EAX, ECX, EDX

========

Callee save registers: These registers must be saved by the callee if they are used.

EBX, ESI, EDI
EBP (if not used as standard stack frame pointer for function arguments and local variables)

In addition, the callee must leave DF (descending flag) cleared, so that string instructions always work in ascending order.
Posted on 2003-01-20 16:06:56 by tenkey
Thanks all. Do I have tp preserve esp and ebp even though I don't use them? Um, I do use them right? For the stack? So when I subclasses say an edit box, in the new WndProc I should put uses esp ebp right off the back right? and if I use the others add them? or just add them all (ebx, esi, edi, esp, ebp) to all the callbacks?
Posted on 2003-01-20 16:07:52 by Gunner
If you use PROC, then ESP and EBP will be properly preserved.
Posted on 2003-01-20 16:26:54 by tenkey
i usualy preserve all regs in my procs if im gunna reuse them for some thing else.other wize, i dont bother. and i usualy save the regs i am using before i call any api.
Posted on 2003-01-22 21:01:53 by Qages